Merge branch 'master' of http://git.roojs.com:8081/Pman.Core
[Pman.Core] / Pman.js
diff --git a/Pman.js b/Pman.js
index 039d761..41bad06 100644 (file)
--- a/Pman.js
+++ b/Pman.js
@@ -8,11 +8,37 @@
  * 
  * {tag: 'div', style: 'display:block;position:absolute;top:2;left:300;width:100%;height:25px'});
  * 
+ * 
+ *  CHANGES
+ *  - gtranslate moved to Pman.GoogleTranslate
+ * 
+ * 
  */
  
 if (typeof(_T) == 'undefined') { _T={};}
  
 
+
+Roo.XComponent.on('register', function(e) { if (typeof(Pman) != 'undefined') { return Pman.xregister(e); } return true;  });
+Roo.XComponent.on('beforebuild', function(e) { if (typeof(Pman) != 'undefined') { return Pman.xbeforebuild(e); } return true; });
+
+Roo.XComponent.on('buildComplete',  
+     function() {
+                    
+        Pman.layout.getRegion('center').showPanel(0);
+        Pman.layout.endUpdate(); 
+        Pman.addTopToolbar();  
+        Pman.finalize();
+        Pman.fireEvent('load',this);
+        
+        if (!Pman.layout.getRegion('south').panels.length) {
+            Pman.layout.getRegion('south').hide();
+        }
+    
+    
+} );
+
+//Roo.debug = 1;
   
 
 Pman = new Roo.Document(
@@ -21,6 +47,13 @@ Pman = new Roo.Document(
     subMenuItems : [],
     topMenuItems : [],
     rightNames: { }, /// register right names here - so they can be translated and rendered.
+    /**
+     * @property {Roo.menu.Menu} pulldownMenu - the 'add menu pulldown, you can use it to add items..
+     *
+     */
+    pulldownMenu : false, 
+    
+    
     buildCompleted : false, // flag to say if we are building interface..
     events : {
         'beforeload' : true, // fired after page ready, before module building.
@@ -37,16 +70,16 @@ Pman = new Roo.Document(
             }
             
             // remove loader..
-            if (Ext.get('loading')) {
-                Ext.get('loading').remove();
+            if (Roo.get('loading')) {
+                Roo.get('loading').remove();
             }
             
-            Ext.state.Manager.setProvider(new Ext.state.CookieProvider());
+            Roo.state.Manager.setProvider(new Roo.state.CookieProvider());
             
             // link errors...
             
             if (AppLinkError.length) {
-                Ext.MessageBox.alert("Error", AppLinkError, function() {
+                Roo.MessageBox.alert("Error", AppLinkError, function() {
                     Pman.Login.onLoad();
                 });
                 return;
@@ -85,7 +118,17 @@ Pman = new Roo.Document(
         
     },
    
-
+    fakeRoot :  new Roo.XComponent( {
+        modKey : '000',
+        module : 'Pman',
+        region : 'center',
+        parent : false,
+        isTop : true,
+        name : "Pman Base",
+        disabled : false, 
+        permname: '' ,
+        render : function (el) { this.el = this.layout; }
+    }),
     
     layout: false,
     
@@ -97,37 +140,17 @@ Pman = new Roo.Document(
         if (this.layout) {
             return; // already loaded
         } 
-        if (Ext.get('loading')) {
-            Ext.get('loading').remove();
+        if (Roo.get('loading')) {
+            Roo.get('loading').remove();
         }
-        if (Ext.get('loading-mask')) {
-            Ext.get('loading-mask').show();
+        if (Roo.get('loading-mask')) {
+            Roo.get('loading-mask').show();
         }
         
-        
-       
-        
-        /*
-        Ext.MessageBox.show({
-           title: "Please wait...",
-           msg: "Building Interface...",
-           width:340,
-           progress:true,
-           closable:false
-          
-        });
-        */
-        //Pman.onLoadBuild();
-        //Ext.get(document.body).mask("Building Interface");
-        //Pman.onLoadBuild.defer(100, Pman);
-       //Pman.onLoadBuild();
-                    
-   // },
-    //onLoadBuild : function() {
-        
+     
         var _this = this;
         this.stime = new Date();
-        this.layout = new Ext.BorderLayout(document.body, {
+        this.layout = new Roo.BorderLayout(document.body, {
             north: {
                 split:false,
                 initialSize: 25,
@@ -143,34 +166,46 @@ Pman = new Roo.Document(
                 //resizeTabs: true,
                 alwaysShowTabs: true,
                 minTabWidth: 140
-            } /*,
+            } ,
             south: {
+                collapsible : true,
+                collapsed : true,
                 split:false,
-                initialSize: 25,
-                titlebar: false
+                height: 120,
+                titlebar: false 
             }
-            */
+            
         });
+        this.fakeRoot.layout = this.layout;
+        /*
+        Pman.register( Roo.apply(this.fakeRoot, {
+            layout : this.layout      
+                
+                                 
+        } ) );
+        */
+        
+        // creates all the modules ready to load..
         
         this.fireEvent('beforeload',this);
         
         
         
         this.layout.beginUpdate();
-        this.layout.add('north', new Ext.ContentPanel('title', 'North'));
+        this.layout.add('north', new Roo.ContentPanel('title', 'North'));
         var au = Pman.Login.authUser;
-        if (au.id > 0 && au.company_id_background_color.length) {
-            Ext.get('title').dom.style.backgroundColor = '#' + au.company_id_background_color;
-            Ext.get('headerInformation').dom.style.color = this.invertColor('#' + au.company_id_background_color);
+        if (au.id > 0 && au.company_id_background_color && au.company_id_background_color.length) {
+            Roo.get('title').dom.style.backgroundColor = '#' + au.company_id_background_color;
+            Roo.get('headerInformation').dom.style.color = this.invertColor('#' + au.company_id_background_color);
         }
         if (au.id > 0 && au.company_id_logo_id * 1 > 0) {
-            Ext.get('headerInformation-company-logo').dom.src =  baseURL + 
+            Roo.get('headerInformation-company-logo').dom.src =  baseURL + 
                 '/Images/' + au.company_id_logo_id + '/' + au.company_id_logo_id_filename;
         } else {
-            Ext.get('headerInformation-company-logo').dom.src = Roo.BLANK_IMAGE_URL;
+            Roo.get('headerInformation-company-logo').dom.src = Roo.BLANK_IMAGE_URL;
         }
         
-        Ext.get('headerInformation').dom.innerHTML = String.format(
+        Roo.get('headerInformation').dom.innerHTML = String.format(
                 "You are Logged in as <b>{0} ({1})</b>", // to {4} v{3}", // for <b>{2}</b>",
                 au.name, au.email, au.company_id_name, 
                 AppVersion , appNameShort
@@ -178,27 +213,18 @@ Pman = new Roo.Document(
         
         
         document.title = appName + ' v' + AppVersion + ' - ' + au.company_id_name;
-        Ext.QuickTips.init(); 
-        if (Ext.isGecko) {
-           Ext.useShims = true;
+        Roo.QuickTips.init(); 
+        if (Roo.isGecko) {
+           Roo.useShims = true;
         }
        
         //this.mainLayout.beginUpdate();
-        //var maskDom = Ext.get(document.body)._maskMsg.dom
+        //var maskDom = Roo.get(document.body)._maskMsg.dom
         this.layout.beginUpdate();
         
         Pman.building = true;
-        
-        this.buildModules(this, 
-            function() {
-                
-                _this.layout.getRegion('center').showPanel(0);
-                _this.layout.endUpdate(); 
-                _this.addTopToolbar();  
-                _this.finalize();
-                _this.fireEvent('load',this);
-            }
-        );
+        Roo.XComponent.build();
+         
         
         
      
@@ -216,14 +242,14 @@ Pman = new Roo.Document(
         var tbh = se.createChild( 
                 { tag: 'td', style: 'width:100%;'  });
         
-        var lotb = new Ext.Toolbar(tbh);
+        var lotb = new Roo.Toolbar(tbh);
         
         if (Roo.isSafari) {
             var tbl = se.child('table', true);
             tbl.setAttribute('width', '100%');
         }
         lotb.add(
-            new Ext.Toolbar.Fill(), 
+            new Roo.Toolbar.Fill(), 
      
             {
                 text: "Change Password",
@@ -255,17 +281,19 @@ Pman = new Roo.Document(
             // since we always add it.. just chop of last item
             this.subMenuItems.pop(); 
             
-            lotb.add(
+            var btn = new Roo.Toolbar.Button( 
                 {
-                     
                     text: "Add New Item",
                     cls: 'x-btn-text-icon',
-                    icon: Ext.rootURL + 'images/default/dd/drop-add.gif',
+                    icon: Roo.rootURL + 'images/default/dd/drop-add.gif',
                     menu : {
                         items : this.subMenuItems
                     }     
-                } ,'-'
+                }
             );
+            this.pulldownMenu = btn.menu;
+            lotb.add(btn, '-');
+            
         }
        
         lotb.add(
@@ -289,7 +317,7 @@ Pman = new Roo.Document(
       
        
         window.onbeforeunload = function(e) { 
-            var e = e || window.event;
+            e = e || window.event;
             var r = "Closing this window will loose changes, are you sure you want to do that?";
 
             // For IE and Firefox
@@ -302,9 +330,9 @@ Pman = new Roo.Document(
             
         };
         
-        Ext.MessageBox.hide();
-        if (Ext.get('loading-mask')) {
-           Ext.get('loading-mask').remove();
+        Roo.MessageBox.hide();
+        if (Roo.get('loading-mask')) {
+           Roo.get('loading-mask').remove();
         }
         
         
@@ -321,10 +349,11 @@ Pman = new Roo.Document(
         var forceAdmin = function(data)
         {
             if (!data || !data.id) {
+                //Roo.log("Force Admin");
                 Pman.Dialog.PersonStaff.show( 
                     { 
                         id : 0, 
-                        company_id : Pman.Login.authUser.company_id * 1, 
+                        company_id : Pman.Login.authUser.company_id_id * 1, 
                         company_id_name : Pman.Login.authUser.company_id_name
                     }, function(data) {
                         forceAdmin(data);
@@ -332,7 +361,7 @@ Pman = new Roo.Document(
                 );
                 return;
             }
-            Ext.state.Manager.set('Pman.Login.username', data.email),
+            Roo.state.Manager.set('Pman.Login.username', data.email),
             window.onbeforeunload = false;
             document.location = baseURL + '?ts=' + Math.random();
         }
@@ -348,12 +377,19 @@ Pman = new Roo.Document(
                 });
                 return;
             }
+            Pman.Login.authUser.company_id_id  = data.id;
             Pman.Login.authUser.company_id  = data.id;
             Pman.Login.authUser.company_id_name  = data.name;
             forceAdmin();
         }
         
         if (Pman.Login.authUser.id < 0) {
+            // admin company has been created - create the user..
+            if (Pman.Login.authUser.company_id_id* 1 > 0) {
+                forceAdmin();
+                return;
+            }
+            
             forceCompany();
             /// create account..
             
@@ -364,7 +400,7 @@ Pman = new Roo.Document(
     },
     
     
-    
+    // REMOVE THESE 
     
      
     onLoadTrack : function(id,cb) {
@@ -379,16 +415,17 @@ Pman = new Roo.Document(
     
     
     onLoadTrackCall : function(id,cb, cls) {
-        Ext.get(document.body).mask("Loading Document details");
+        Roo.get(document.body).mask("Loading Document details");
 
-        Pman.request({
+        new Pman.Request({
             url: baseURL + '/Roo/Documents.html',  
             params: {
                 _id: id
             },  
             method: 'GET',  
-            success : function(data) {
-                Ext.get(document.body).unmask();
+            success : function(res) {
+                var data = res.data;
+                Roo.get(document.body).unmask();
              
                 
                 switch(data.in_out) {
@@ -396,14 +433,14 @@ Pman = new Roo.Document(
                     case 'OUT' : cls+='Out';break;
                     case 'WIP' : cls+='Wip';break;
                     default: 
-                        Ext.MessageBox.alert("Error", "invalid in_out");
+                        Roo.MessageBox.alert("Error", "invalid in_out");
                         return;
                 }
                 Pman.Dialog[cls].show(data, cb ? cb : Pman.refreshActivePanel);
             }, 
             
             failure: function() {
-                Ext.get(document.body).unmask();
+                Roo.get(document.body).unmask();
                 //if (cb) {
                 //    cb.call(false);
                 //}
@@ -413,22 +450,65 @@ Pman = new Roo.Document(
           
     },
     
+    refreshActivePanel : function() {
+        var actpan = this.layout.getRegion('center').getActivePanel();
+        if (actpan.controller && actpan.controller.paging) {
+            actpan.controller.paging.onClick('refresh');
+            return;
+        }
+        
+        var agid = Pman.layout.getRegion('center').getActivePanel().id;
+        if (!agid) {
+            return;
+        }
+        Pman.Tab[agid].paging.onClick('refresh');
+    },
+    toCidV : function(data) {
+        return 'C' + data.in_out.substring(0,1) + data.cid;
+    },
+    
+    
     /**
-     * eg. has Pman.hasPerm('Admin.Admin_Tab', 'S') == showlist..
+     * hasPerm:
+     * Does the authenticated user have permission to see this.
      * 
+     * @param {String} name the [Module].[permission] to check for
+     * @param {Char} lvl  - which type of permission to use (eg. S=show...)
+     * @returns {Boolean} tue indicates permission allowed
      */
     hasPerm: function(name, lvl) {
-        if (typeof(Pman.Login.authUser) != 'object') {
-            return false;
-        }
-        if (typeof(Pman.Login.authUser.perms[name]) != 'string') {
-            return false;
+        if (
+            (typeof(Pman.Login.authUser) != 'object')
+            ||
+            (typeof(Pman.Login.authUser.perms) != 'object')
+            ||
+            (typeof(Pman.Login.authUser.perms[name]) != 'string')
+            ) {
+                return false;
         }
+        
         return Pman.Login.authUser.perms[name].indexOf(lvl) > -1;
         
     },
-    
-    
+    /**
+     * hasPermExists:
+     * Is there a permission defined for this (used by module registration.)
+     * 
+     * @param {String} name the [Module].[permission] to check for
+     * @returns {Boolean} tue indicates permission exists.
+     */
+    hasPermExists: function(name) {
+        if (
+            (typeof(Pman.Login.authUser) != 'object')
+            ||
+            (typeof(Pman.Login.authUser.perms) != 'object')
+            ||
+            (typeof(Pman.Login.authUser.perms[name]) != 'string')
+            ) {
+                return false;
+        }
+        return true;
+    },
     
     
     
@@ -445,7 +525,7 @@ Pman = new Roo.Document(
     {
         var res = '';
         try {
-            res = Ext.decode(response.responseText);
+            res = Roo.decode(response.responseText);
             // oops...
             if (typeof(res) != 'object') {
                 res = { success : false, errorMsg : res, errors : true };
@@ -466,7 +546,7 @@ Pman = new Roo.Document(
             
         var s = tab.grid.getSelectionModel().getSelections();
         if (!s.length)  {
-            Ext.MessageBox.alert("Error", "Select at least one Row to delete" );
+            Roo.MessageBox.alert("Error", "Select at least one Row to delete" );
             return '';
         }
         
@@ -474,16 +554,16 @@ Pman = new Roo.Document(
             r.push(s[i].data.id);
         }
     
-        Ext.MessageBox.confirm("Confirm", "Are you sure you want to delete that?",
+        Roo.MessageBox.confirm("Confirm", "Are you sure you want to delete that?",
             function(btn) {
                 if (btn != 'yes') {
                     return;
                 }
                 // what about the toolbar??
                 tab.grid.getView().mainWrap.mask("Deleting");
-                Pman.request({
+                new Pman.Request({
                     url: baseURL + '/Roo/'+tbl+'.php',
-                    method: 'GET',
+                    method: 'POST',
                     params: {
                         _delete : r.join(',')
                     },
@@ -505,67 +585,52 @@ Pman = new Roo.Document(
                     },
                     failure: function(act) {
                         tab.grid.getView().mainWrap.unmask();
-                        Ext.MessageBox.alert("Error", "Error Deleting");
+                        Roo.MessageBox.alert("Error", "Error Deleting");
                     }
                     
                 });
             }
+            
         );
-    },
-    refreshActivePanel : function() {
-        var actpan = this.layout.getRegion('center').getActivePanel();
-        if (actpan.controller && actpan.controller.paging) {
-            actpan.controller.paging.onClick('refresh');
-            return;
-        }
-        
-        var agid = Pman.layout.getRegion('center').getActivePanel().id;
-        if (!agid) {
-            return;
-        }
-        Pman.Tab[agid].paging.onClick('refresh');
-    },
-    toCidV : function(data) {
-        return 'C' + data.in_out.substring(0,1) + data.cid;
+        return '';
     },
     
+    
     standardActionFailed :  function(f, act, cb) {
     
         if (act.failureType == 'client') {
-            Ext.MessageBox.alert("Error", "Please Correct all the errors in red", cb);
+            Roo.MessageBox.alert("Error", "Please Correct all the errors in red", cb);
             return;
         }
         if (act.failureType == 'connect') {
-            Ext.MessageBox.alert("Error", "Problem Connecting to Server - please try again.", cb);
+            Roo.MessageBox.alert("Error", "Problem Connecting to Server - please try again.", cb);
             return;
         }
         
         if (act.type == 'submit') {
             
-            Ext.MessageBox.alert("Error", typeof(act.result.errorMsg) == 'string' ?
+            Roo.MessageBox.alert("Error", typeof(act.result.errorMsg) == 'string' ?
                 String.format('{0}', act.result.errorMsg) : 
                 "Saving failed = fix errors and try again", cb);
             return;
         }
         
         // what about load failing..
-        Ext.MessageBox.alert("Error", "Error loading details",cb); 
+        Roo.MessageBox.alert("Error", "Error loading details",cb); 
     },
     /**
-     * 
-     * similar to Ext.Ajax, but handles our responses better...
-     * c.url
-     * c.method
-     * c.params
-     * c.failure() == failure function..
-     * c.success(data) == success function..
-     * 
+     * Depreciated - USE new Pman.Request
+    *  We need to replace all the uses with this, however the api is slightly different,
+    *  the success argument is res.data, not res..
      * 
      */
     request : function(c) {
-        
-        Ext.Ajax.request({
-            timeout : c.timeout || 30000,
+        //return new Pman.Request(c);
+         
+        var r= new Roo.data.Connection({
+            timeout : typeof(c.timeout) == 'undefined' ?  30000 : c.timeout
+        });
+        r.request({
             url: c.url,
             method : c.method,
             params: c.params,
@@ -581,7 +646,7 @@ Pman = new Roo.Document(
                         }
                     }
                     Roo.MessageBox.hide();
-                    Ext.MessageBox.alert("Error", res.errorMsg ? res.errorMsg : "Error Sending");
+                    Roo.MessageBox.alert("Error", res.errorMsg ? res.errorMsg : "Error Sending");
                     return;
                 }
                 
@@ -598,81 +663,24 @@ Pman = new Roo.Document(
                 }
                 Roo.MessageBox.hide();
                 Roo.MessageBox.alert("Error", "Connection timed out sending");
-                console.log(response);
+                Roo.log(response);
                 
             },
             scope: this
             
         });
+         
     },
-    csvFrame : false,
     
-    createCsvFrame: function()
-    {
-        
-        if (this.csvFrame) {
-            document.body.removeChild(this.csvFrame);
-        }
-            
-        var id = Ext.id();
-        this.csvFrame = document.createElement('iframe');
-        this.csvFrame.id = id;
-        this.csvFrame.name = id;
-        this.csvFrame.className = 'x-hidden';
-        if(Ext.isIE){
-            this.csvFrame.src = Ext.SSL_SECURE_URL;
-        }
-        document.body.appendChild(this.csvFrame);
-
-        if(Ext.isIE){
-            document.frames[id].name = id;
-        }
-        
-    },
-    /**
-     * download({
-          url: 
-         })
-     * 
-     * 
-     */
     
+    // depreciated - use Pman.Download()
     
     download : function(c) {
         
-        if (c.newWindow) {
-            // as ie seems buggy...
-            window.open( c.url + '?' + Roo.urlEncode(c.params || {}), '_blank');
-            return;
-            
-        }
-        
-        this.createCsvFrame();
-        function cb(){
-            var r = { responseText : "", responseXML : null };
-
-            var frame = this.csvFrame;
-
-            try { 
-                var doc = Ext.isIE ? 
-                    frame.contentWindow.document : 
-                    (frame.contentDocument || window.frames[this.csvFrame.id].document);
-                
-                if(doc && doc.body && doc.body.innerHTML.length){
-                  //  alert(doc.body.innerHTML);
-                    Ext.MessageBox.alert("Error download",doc.body.innerHTML);
-                }
-                 
-            }
-            catch(e) {
-            }
-
-            Ext.EventManager.removeListener(frame, 'load', cb, this);
-        }
-        Ext.EventManager.on( this.csvFrame, 'load', cb, this);
-        this.csvFrame.src = c.url;
+        return new Pman.Download(c);
     },
+    
+    // fixme - move to document manager...
     downloadRevision : function(doc, rev)
     {
         this.download({
@@ -681,18 +689,20 @@ Pman = new Roo.Document(
         }); 
                     
     },
+    
+    
     exportCSV : function(c) {
-        //this.createCsvFrame(); 
+        
         for(var i=0;i < c.csvFormat.length;i++) {
             c.params['csvCols['+i+']'] = c.csvFormat[i][0];
             c.params['csvTitles['+i+']'] = c.csvFormat[i][1];
         }
-        
-        
-        c.url +=  '?' + Ext.urlEncode(c.params);
+        c.url +=  '?' + Roo.urlEncode(c.params);
         this.download(c);
 
     },
+    
+    
     prettyDate : function (value) 
     {
         if (typeof(value) == 'string') {
@@ -772,163 +782,206 @@ Pman = new Roo.Document(
             }
             s = !s;
             document.title = s ? msg : oldtitle;
-                  
+            return false;     
         }, 1000); // every 120 secs = 2mins..
          document.title =   msg;
         
         
         
     },
-    
-    modules : false,
     /**
-     * example:
-     * 
-     * Pman.register({
-          modKey : '00-admin-xxxx',
-          module : Pman.Tab.projectMgr,
-          region : 'center',
-          parent : Pman.layout
-        })
-     * 
+     * @property {Array} appModules  - array based on AppModules global
      */
-    register : function(obj) {
-        if (!obj.parent) {
-            if (obj.parent === false) {
-                //console.log(obj);
+    appModules : false,
+    
+    modules : false,
+    
+    
+    xregister : function(obj)
+    {
+        
+        // work out owner..
+        if (!Pman.appModules === false) {
+            Pman.appModules = typeof(AppModules ) == 'undefined'? [] :
+                AppModules.split(',');
+        }
+        
+        
+        
+        // ignore registration of objects which are disabled.
+        // global supplied by master.html
+        appDisabled = typeof(appDisabled) == 'undefined' ? [] : appDisabled;
+        
+        
+        /// design flaw
+        // previously we did not a good naming policy for module and parts
+        // most things that are called module here, really are 'parts'
+        // new versions should have 'part' as [ module : part ]
+         if (typeof(obj.part) != 'undefined')  {
+           
+            var permname = obj.part.join('.');
+                // we now have permission...
+                // obj.moduleOwner '.' lname
+           
+           
+            if (appDisabled.indexOf(permname) > -1)  {
+                Roo.log(permname + " is Disabled for this site");
+                obj.disabled = true;
                 return;
             }
             
-            console.log(obj);
-        }
-        if (!obj.parent.modules) {
-            obj.parent.modules = new Roo.util.MixedCollection(false, function(o) { return o.modKey });
+            
         }
-        obj.parent.modules.add(obj);
         
-    },
-    
-    buildModules : function(parent, onComplete) 
-    {
+       
         
-        var _this = this;
-        var cmp = function(a,b) {   
-            return String(a).toUpperCase() > String(b).toUpperCase() ? 1 : -1;
-            
-        };
-        if (!parent.modules) {
+        if ( obj.isTop) {
+            // false parent... use it..
             return;
         }
-        parent.modules.keySort('ASC',  cmp );
-        var mods = [];
         
         
-        // add modules to their parents..
-        var addMod = function(m) {
-           // console.log(m.modKey);
+        if (obj.parent === Pman || obj.parent  == 'Pman') {
+            Roo.log("PARENT OF : " + obj.name + " replacing with fake");
+            obj.parent = Pman.fakeRoot;
+        }
+        
+        if (typeof(obj.parent) == 'undefined') {
+            console.log("Parent is undefined");
+            console.log(obj);
+            obj.disabled = true;
+            return;
+        }
             
-            mods.push(m);
-            if (m.module.modules) {
-                m.module.modules.keySort('ASC',  cmp );
-                m.module.modules.each(addMod);
-            }
-            if (m.finalize) {
-                m.finalize.name = m.name + " (clean up) ";
-                mods.push(m.finalize);
-            }
             
-        }
-        parent.modules.each(addMod);
-        //this.allmods = mods;
-        //console.log(mods);
-        //return;
-        if (!mods.length) {
-            if (onComplete) onComplete();
+        if (obj.parent === false) {
+            obj.disabled = true;
+            console.log('ignoring top level object (as parent===false found)');
+            console.log(obj);
             return;
         }
-        // flash it up as modal - so we store the mask!?
-        Ext.MessageBox.show({ title: 'loading' });
-        Ext.MessageBox.show({
-           title: "Please wait...",
-           msg: "Building Interface...",
-           width:450,
-           progress:true,
-           closable:false,
-           modal: false
+        // this is an error condition - the parent does not exist..
+            // technically it should not happen..
           
-        });
-        var n = 0;
-        var progressRun = function() {
-            
-            var m = mods[n];
+        // hack for Pman parent == Pman..
+        if (obj.parent == obj.module) {
+            obj.parent = false;
             
+        }
+       
+        
+    },
+    /**
+     * fired before building on each compoenent
+     * used to apply permissions.
+     */
+    
+    xbeforebuild : function(obj)
+    {
+        if (typeof(obj.part) != 'undefined')  {
+           
+            if (!obj.part[1].length) {
+                obj.part[1] = obj.part[0];
+            }
+            var permname = obj.part.join('.');
             
-            Ext.MessageBox.updateProgress(
-                (n+1)/mods.length,  "Building Interface " + (n+1) + 
-                    " of " + mods.length + 
-                    (m.name ? (' - ' + m.name) : '')
-                    );
+            Roo.log("CHECKING: "+ permname);
             
+                // we now have permission...
+                // obj.moduleOwner '.' lname
+           
+            if (Pman.hasPermExists(permname) && !Pman.hasPerm(permname,'S')) {
+                // it's a turned off permission...
+                Roo.log(permname + " is Disabled for this user");
+                obj.disabled = true;
+                return;
+            }
+        
             
             
-            if (typeof(m) == 'function') {
-                m();
-                
-            } else {
-                if (m.parent.layout && !m.module.disabled) {
-                    m.module.add(m.parent.layout, m.region);    
-                }
+        }
+        
+        
+    },
+    
+    /**
+     * DEPRICATED : use Roo.XComponents now..
+     * 
+     * Pman.register({
+          modKey : '00-admin-xxxx',
+          module : Pman.Tab.projectMgr, << really a components..
+          part : [ 'Admin', 'ProjectManager' ]
+          moduleOwner : 
+          region : 'center',
+          parent : Pman.layout
+        })
+     * 
+     */
+    register : function(obj)
+    {
+        
+        //this.xregister(obj);
+        
+        
+        // old style calls go in here..
+        // we need to convert the object so that it looks a bit like an XCompoenent..
+         
+        obj.render = function()
+        {
+            if (!this.parent) {
+                Roo.log("Skip module, as parent does not exist");
+                Roo.log(this);
+                return;
+            }
+            //if (typeof(mod) == 'function') {
+            //    mod();
                 
+            if (typeof(this.region) == 'undefined') {
+                Roo.log("Module does not have region defined, skipping");
+                Roo.log(this);
+                return;
+            }
+            if (this.module.disabled) {
+                Roo.log("Module disabled, should not rendering")
+                Roo.log(this);
+                return;
             }
             
-            
-            n++;
-            if (n >= mods.length) {
-                onComplete();  
+            if (!this.parent.layout) {
+                Roo.log("Module parent does not have property layout.")
+                Roo.log(this);
                 return;
             }
+        
+           // honour DEPRICATED permname setings..
+           // new code should use PART name, and matching permissions.
+            if (this.permname && this.permname.length) {
+                if (!Pman.hasPerm(this.permname, 'S')) {
+                    return;
+                }
                 
+            }
+            this.add(this.parent.layout, this.region);
+            this.el = this.layout;
             
-            progressRun.defer(10, Pman);    
-        }
-        progressRun.defer(1, Pman);
-     
+            
+              
+        };
+        // map some of the standard properties..
+        obj.order = obj.modKey;
         
+        // a bit risky...
         
-    },
-    
-    gtranslate : function(str, src, dest, cb) {
-        // load script: 
         
         
-        var x = new Roo.data.ScriptTagProxy({ 
-            url:  'http://ajax.googleapis.com/ajax/services/language/translate', 
-            callbackParam : 'callback' 
-        });
-        x.load(
-            {
-                v: '1.0',
-                q : str,
-                langpair : src + '|' +dest
-            }, // end params.
-            { // reader
-                readRecords : function (o) {
-                    if (!o.responseData) {
-                        return o;
-                    }
-                    return o.responseData.translatedText;
-                }
-            }, 
-            function (result) {
-                cb(result);
-            },
-            this,
-            []
-        );
+        // the other issue we have is that
+         
         
-            
+        // Roo.log("CALLING XComponent register with : " + obj.name);
         
+        // this will call xregister as it's the on.register handler..
+        Roo.XComponent.register(obj.isTop ? obj : Roo.apply(obj.module, obj));
+         
     } ,
     invertColor : function(c)
     {