Commits

Sebastian Sdorra  committed 53a8799

improve plugin config api

  • Participants
  • Parent commits 226817c

Comments (0)

Files changed (5)

File plugins/scm-hg-plugin/src/main/java/sonia/scm/api/rest/resources/HgConfigResource.java

   @GET
   public HgConfig getConfig()
   {
-    return handler.getConfig();
+    HgConfig config = handler.getConfig();
+
+    if (config == null)
+    {
+      config = new HgConfig();
+    }
+
+    return config;
   }
 
   //~--- set methods ----------------------------------------------------------

File plugins/scm-hg-plugin/src/main/java/sonia/scm/repository/HgConfig.java

    *
    * @return
    */
-  public File getConfigDirectory()
+  public String getBaseUrl()
   {
-    return configDirectory;
+    return baseUrl;
   }
 
   /**
    * Method description
    *
    *
-   * @param configDirectory
+   * @param baseUrl
    */
-  public void setConfigDirectory(File configDirectory)
+  public void setBaseUrl(String baseUrl)
   {
-    this.configDirectory = configDirectory;
+    this.baseUrl = baseUrl;
   }
 
   /**
   //~--- fields ---------------------------------------------------------------
 
   /** Field description */
-  private File configDirectory;
+  private String baseUrl;
 
   /** Field description */
   private String hgBinary = "hg";

File plugins/scm-hg-plugin/src/main/resources/sonia/scm/hg.config.js

  * To change this template, choose Tools | Templates
  * and open the template in the editor.
  */
-repositoryConfigPanels.push({
-  style: 'margin: 10px',
-  trackResetOnLoad : true,
-  autoScroll : true,
-  border : false,
-  frame : false,
-  collapsible : false,
-  collapsed : false,
-  layoutConfig : {
-    labelSeparator : ''
-  },
+registerConfigPanel({
+  xtype : 'configForm',
+  title : 'Mercurial Settings',
   items : [{
-    xtype : 'fieldset',
-    checkboxToggle : false,
-    title : 'Mercurial Settings',
-    collapsible : true,
-    autoHeight : true,
-    labelWidth : 140,
-    buttonAlign: 'left',
-    layoutConfig : {
-      labelSeparator : ''
-    },
-    items : [{
-      xtype : 'textfield',
-      fieldLabel : 'HG Binary',
-      name : 'hgBinary',
-      allowBlank : false
-    },{
-      xtype: 'textfield',
-      name: 'hgRepoDirectroy',
-      fieldLabel: 'Repository directory',
-      allowBlank : false
-    },{
-      xtype: 'textfield',
-      name: 'hgBaseUrl',
-      fieldLabel: 'Base URL',
-      allowBlank : false
-    }],
-    buttons: [{
-      text: 'Save'
-    },{
-      text: 'Cancel'
-    }]
+    xtype : 'textfield',
+    fieldLabel : 'HG Binary',
+    name : 'hgBinary',
+    allowBlank : false
+  },{
+    xtype: 'textfield',
+    name: 'repositoryDirectory',
+    fieldLabel: 'Repository directory',
+    allowBlank : false
+  },{
+    xtype: 'textfield',
+    name: 'baseUrl',
+    fieldLabel: 'Base URL',
+    allowBlank : false
   }]
-
 });

File scm-webapp/src/main/webapp/resources/js/global.js

 // config form panels
 var repositoryConfigPanels = [];
 
+function registerConfigPanel(panel){
+  repositoryConfigPanels.push( panel );
+}
+
 var repositoryTypeStore = new Ext.data.JsonStore({
   id: 1,
   fields: [ 'displayName', 'name' ]

File scm-webapp/src/main/webapp/resources/js/sonia.config.js

 
 });
 
-Ext.reg("configPanel", Sonia.config.ConfigPanel);
+Ext.reg("configPanel", Sonia.config.ConfigPanel);
+
+Sonia.config.ConfigForm = Ext.extend(Ext.form.FormPanel, {
+
+  title: 'Config Form',
+  items: null,
+
+  initComponent: function(){
+
+    var config = {
+      title: null,
+      style: 'margin: 10px',
+      trackResetOnLoad : true,
+      autoScroll : true,
+      border : false,
+      frame : false,
+      collapsible : false,
+      collapsed : false,
+      layoutConfig : {
+        labelSeparator : ''
+      },
+      items : [{
+        xtype : 'fieldset',
+        checkboxToggle : false,
+        title : this.title,
+        collapsible : true,
+        autoHeight : true,
+        labelWidth : 140,
+        buttonAlign: 'left',
+        layoutConfig : {
+          labelSeparator : ''
+        },
+        items: this.items,
+        buttons: [{
+          text: 'Save'
+        },{
+          text: 'Cancel'
+        }]
+      }]
+    };
+
+    Ext.apply(this, Ext.apply(this.initialConfig, config));
+    Sonia.config.ConfigForm.superclass.initComponent.apply(this, arguments);
+  }
+
+});
+
+Ext.reg("configForm", Sonia.config.ConfigForm);