Commits

Sebastian Sdorra committed 5657dbf

improve Sonia.navigation package

Comments (0)

Files changed (2)

scm-webapp/src/main/webapp/resources/js/layout.js

       height: 75
     }), {
       region: 'west',
-      id: 'west-panel', // see Ext.getCmp() below
+      id: 'west', // see Ext.getCmp() below
       title: 'West',
+      xtype: 'navPanel',
       split: true,
       width: 200,
       minSize: 175,
   }
 
   function createMainMenu(){
-    var panel = Ext.getCmp('west-panel');
-    panel.add({
-      xtype: 'navPanel',
+    var panel = Ext.getCmp('west');
+    panel.addSections([{
       title: 'Main',
-      data: [{
+      items: [{
         label: 'Groups',
         fn: addGroupPanel
       },{
         label: 'Repositories',
         fn: addRepositoryPanel
       }]
-    });
-    panel.doLayout();
+    },{
+      title: 'Config',
+      items: [{
+        label: 'Repositories',
+        fn: null
+      },{
+        label: 'Server',
+        fn: null
+      }]
+    }]);
   }
 
   // create menu after login

scm-webapp/src/main/webapp/resources/js/sonia.navigation.js

 
 Ext.ns('Sonia.navigation');
 
-Sonia.navigation.NavPanel = Ext.extend(Ext.Panel, {
+Sonia.navigation.NavSection = Ext.extend(Ext.Panel, {
 
   data: null,
 
     }
 
     Ext.apply(this, Ext.apply(this.initialConfig, config));
-    Sonia.navigation.NavPanel.superclass.initComponent.apply(this, arguments);
+    Sonia.navigation.NavSection.superclass.initComponent.apply(this, arguments);
 
   },
 
     var prefix = this.id + '-nav-item-';
     if ( id != null && id.indexOf(prefix) == 0 ){
       var i = parseInt( id.substring( prefix.length ) );
-      this.data[i].fn();
+      var fn = this.data[i].fn;
+      if ( Ext.isFunction( fn ) ){
+        fn();
+      } else if ( debug ){
+        console.debug('fn at "' +  this.data[i].label + '" is not a function');
+      }
     }
   },
 
 
 });
 
+Ext.reg('navSection', Sonia.navigation.NavSection);
+
+Sonia.navigation.NavPanel = Ext.extend(Ext.Panel, {
+
+  sections: null,
+
+  initComponent: function(){
+
+    var config = {
+      listeners: {
+        afterrender: {
+          fn: this.renderSections,
+          scope: this
+        }
+      }
+    };
+
+    Ext.apply(this, Ext.apply(this.initialConfig, config));
+    Sonia.navigation.NavSection.superclass.initComponent.apply(this, arguments);
+  },
+
+  renderSections: function(){
+    if ( this.sections != null ){
+      this.addSections( this.sections );
+    }
+  },
+
+  addSections: function(sections){
+    if ( Ext.isArray( sections ) && sections.length > 0 ){
+      for ( var i=0; i<sections.length; i++ ){
+        this.addSection( sections[i] );
+      }
+    } else {
+      this.addSection( sections );
+    }
+    this.doLayout();
+  },
+
+  addSection: function(section){
+    this.add({
+      xtype: 'navSection',
+      title: section.title,
+      data: section.items
+    });
+  }
+
+});
+
 Ext.reg('navPanel', Sonia.navigation.NavPanel);