Pman.js
[Pman.Core] / Pman.js
1 //<script type="text/javascript">
2
3 /**
4  * 
5  * >>> Pman.layout.getRegion('center').tabs.stripWrap
6  * ==> tab.???
7  * var tbh = Pman.layout.getRegion('center').tabs.stripWrap.child('div').createChild(
8  * 
9  * {tag: 'div', style: 'display:block;position:absolute;top:2;left:300;width:100%;height:25px'});
10  * 
11  * 
12  *  CHANGES
13  *  - gtranslate moved to Pman.GoogleTranslate
14  * 
15  * 
16  */
17  
18 if (typeof(_T) == 'undefined') { _T={};}
19  
20
21
22 Roo.XComponent.on('register', function(e) { return Pman.xregister(e); });
23 Roo.XComponent.on('buildComplete',  
24      function() {
25                     
26         Pman.layout.getRegion('center').showPanel(0);
27         Pman.layout.endUpdate(); 
28         Pman.addTopToolbar();  
29         Pman.finalize();
30         Pman.fireEvent('load',this);
31         
32         if (!Pman.layout.getRegion('south').panels.length) {
33             Pman.layout.getRegion('south').hide();
34         }
35     
36     
37 } );
38
39 //Roo.debug = 1;
40   
41
42 Pman = new Roo.Document(
43 {
44    /// appVersion: '1.7', // fixme = needs to be removed - use Global AppVersion
45     subMenuItems : [],
46     topMenuItems : [],
47     rightNames: { }, /// register right names here - so they can be translated and rendered.
48     /**
49      * @property {Roo.menu.Menu} pulldownMenu - the 'add menu pulldown, you can use it to add items..
50      *
51      */
52     pulldownMenu : false, 
53     
54     
55     buildCompleted : false, // flag to say if we are building interface..
56     events : {
57         'beforeload' : true, // fired after page ready, before module building.
58         'load' : true, // fired after module building
59         'authrefreshed' : true // fire on auth updated?? - should be on Login?!?!?
60     },
61     
62     listeners : {
63         'ready' : function()
64         {
65             // kludge to fix firebug debugger
66             if (typeof(console) == 'undefined') {
67                 console = { log : function() {  } };
68             }
69             
70             // remove loader..
71             if (Roo.get('loading')) {
72                 Roo.get('loading').remove();
73             }
74             
75             Roo.state.Manager.setProvider(new Roo.state.CookieProvider());
76             
77             // link errors...
78             
79             if (AppLinkError.length) {
80                 Roo.MessageBox.alert("Error", AppLinkError, function() {
81                     Pman.Login.onLoad();
82                 });
83                 return;
84             }
85             
86             
87             // reset password!!!!
88             if (showNewPass.length) {
89                 Pman.PasswordChange.show(  { passwordReset : showNewPass },
90                     function(data) {
91                         // fail and success we do  a load...
92                         Pman.Login.onLoad();
93                     }
94                 );
95                 return;
96             }
97              
98             Pman.Login.onLoad();
99             
100         },
101         'load' : function()
102         {
103             if (Roo.get('loading-logo-tile')) {
104                 Roo.get('loading-logo-tile').remove();
105             }
106             if (Roo.get('loading-logo-tile-top')) {
107                 Roo.get('loading-logo-tile-top').remove();
108             }
109             if (Roo.get('loading-logo-bottom')) {
110                 Roo.get('loading-logo-bottom').remove();
111             }
112             if (Roo.get('loading-logo-center')) {
113                 Roo.get('loading-logo-center').remove();
114             }
115         }   
116         
117     },
118    
119     fakeRoot :  {
120         modKey : '000',
121         module : 'Pman',
122         region : 'center',
123         parent : false,
124         isTop : true,
125         name : "Pman Base",
126         disabled : false, 
127         permname: '' 
128     },
129     
130     layout: false,
131     
132     onload: function() {
133         //this.fireEvent('beforeload',this);
134         
135         
136         
137         if (this.layout) {
138             return; // already loaded
139         } 
140         if (Roo.get('loading')) {
141             Roo.get('loading').remove();
142         }
143         if (Roo.get('loading-mask')) {
144             Roo.get('loading-mask').show();
145         }
146         
147      
148         var _this = this;
149         this.stime = new Date();
150         this.layout = new Roo.BorderLayout(document.body, {
151             north: {
152                 split:false,
153                 initialSize: 25,
154                 titlebar: false
155             },
156          
157              
158             center: {
159                 titlebar: false,
160                 autoScroll:false,
161                 closeOnTab: true,
162                 tabPosition: 'top',
163                 //resizeTabs: true,
164                 alwaysShowTabs: true,
165                 minTabWidth: 140
166             } ,
167             south: {
168                 collapsible : true,
169                 collapsed : true,
170                 split:false,
171                 height: 120,
172                 titlebar: false 
173             }
174             
175         });
176         
177         
178         Pman.register( Roo.apply(this.fakeRoot, {
179             layout : this.layout      
180                 
181                                  
182         } ) );
183         
184         // creates all the modules ready to load..
185         
186         this.fireEvent('beforeload',this);
187         
188         
189         
190         this.layout.beginUpdate();
191         this.layout.add('north', new Roo.ContentPanel('title', 'North'));
192         var au = Pman.Login.authUser;
193         if (au.id > 0 && au.company_id_background_color && au.company_id_background_color.length) {
194             Roo.get('title').dom.style.backgroundColor = '#' + au.company_id_background_color;
195             Roo.get('headerInformation').dom.style.color = this.invertColor('#' + au.company_id_background_color);
196         }
197         if (au.id > 0 && au.company_id_logo_id * 1 > 0) {
198             Roo.get('headerInformation-company-logo').dom.src =  baseURL + 
199                 '/Images/' + au.company_id_logo_id + '/' + au.company_id_logo_id_filename;
200         } else {
201             Roo.get('headerInformation-company-logo').dom.src = Roo.BLANK_IMAGE_URL;
202         }
203         
204         Roo.get('headerInformation').dom.innerHTML = String.format(
205                 "You are Logged in as <b>{0} ({1})</b>", // to {4} v{3}", // for <b>{2}</b>",
206                 au.name, au.email, au.company_id_name, 
207                 AppVersion , appNameShort
208         );
209         
210         
211         document.title = appName + ' v' + AppVersion + ' - ' + au.company_id_name;
212         Roo.QuickTips.init(); 
213         if (Roo.isGecko) {
214            Roo.useShims = true;
215         }
216        
217         //this.mainLayout.beginUpdate();
218         //var maskDom = Roo.get(document.body)._maskMsg.dom
219         this.layout.beginUpdate();
220         
221         Pman.building = true;
222         
223         this.buildModules(this, 
224            
225         );
226         
227         
228      
229     },
230     
231     addTopToolbar : function()
232     {
233           //console.log( "t6:" + ((new Date())-stime));
234         //this.mainLayout.endUpdate();
235         // make a new tab to hold administration stuff...
236         
237        
238         //console.log( "t7:" + ((new Date())-stime));
239         var se = Pman.layout.getRegion('center').tabs.stripEl;
240         var tbh = se.createChild( 
241                 { tag: 'td', style: 'width:100%;'  });
242         
243         var lotb = new Roo.Toolbar(tbh);
244         
245         if (Roo.isSafari) {
246             var tbl = se.child('table', true);
247             tbl.setAttribute('width', '100%');
248         }
249         lotb.add(
250             new Roo.Toolbar.Fill(), 
251      
252             {
253                 text: "Change Password",
254                 cls: 'x-btn-text-icon',
255                 icon: rootURL + '/Pman/templates/images/change-password.gif',
256                 handler : function(){
257                     Pman.PasswordChange.show({});
258                 }
259             }, '-'
260         );
261          
262         
263         if (this.topMenuItems.length) {
264             
265             Roo.each(this.topMenuItems, function (mi) {
266                 lotb.add(mi);
267             });
268             lotb.add('-');
269         }
270         
271         
272         
273         if (this.subMenuItems.length) {
274             
275             this.subMenuItems.sort(function (a,b) {
276                 return a.seqid > b.seqid ? 1 : -1;
277             });
278             // chop off last seperator.
279             // since we always add it.. just chop of last item
280             this.subMenuItems.pop(); 
281             
282             var btn = new Roo.Toolbar.Button( 
283                 {
284                     text: "Add New Item",
285                     cls: 'x-btn-text-icon',
286                     icon: Roo.rootURL + 'images/default/dd/drop-add.gif',
287                     menu : {
288                         items : this.subMenuItems
289                     }     
290                 }
291             );
292             this.pulldownMenu = btn.menu;
293             lotb.add(btn, '-');
294             
295         }
296        
297         lotb.add(
298             {
299                 text: "Logout",
300                 cls: 'x-btn-text-icon',
301                 icon: rootURL + '/Pman/templates/images/logout.gif',
302                 handler: function() {
303                     Pman.Login.logout();
304                 }
305                  
306             }
307         );
308       
309        // this.layout.endUpdate();
310     },
311     
312     
313     finalize : function() {
314         
315       
316        
317         window.onbeforeunload = function(e) { 
318             e = e || window.event;
319             var r = "Closing this window will loose changes, are you sure you want to do that?";
320
321             // For IE and Firefox
322             if (e) {
323                 e.returnValue = r;
324             }
325
326             // For Safari
327             return r;
328             
329         };
330         
331         Roo.MessageBox.hide();
332         if (Roo.get('loading-mask')) {
333            Roo.get('loading-mask').remove();
334         }
335         
336         
337         this.buildCompleted = true; // now we can force refreshes on everything..
338         
339         
340         // does the URL indicate we want to see a system..
341         if (AppTrackOnLoad * 1 > 0) {
342             this.onLoadTrack(AppTrackOnLoad,false);
343         }
344         
345         // Open system..
346         
347         var forceAdmin = function(data)
348         {
349             if (!data || !data.id) {
350                 //Roo.log("Force Admin");
351                 Pman.Dialog.PersonStaff.show( 
352                     { 
353                         id : 0, 
354                         company_id : Pman.Login.authUser.company_id_id * 1, 
355                         company_id_name : Pman.Login.authUser.company_id_name
356                     }, function(data) {
357                         forceAdmin(data);
358                     }
359                 );
360                 return;
361             }
362             Roo.state.Manager.set('Pman.Login.username', data.email),
363             window.onbeforeunload = false;
364             document.location = baseURL + '?ts=' + Math.random();
365         }
366         
367         var forceCompany = function(data) {
368             if (Pman.Login.authUser.company_id * 1 > 0) {
369                 forceAdmin();
370                 return;
371             }
372             if (!data || !data.id) {
373                 Pman.Dialog.Companies.show( { id : 0, isOwner : 1, comptype: 'OWNER' }, function(data) {
374                     forceCompany(data);
375                 });
376                 return;
377             }
378             Pman.Login.authUser.company_id_id  = data.id;
379             Pman.Login.authUser.company_id  = data.id;
380             Pman.Login.authUser.company_id_name  = data.name;
381             forceAdmin();
382         }
383         
384         if (Pman.Login.authUser.id < 0) {
385             // admin company has been created - create the user..
386             if (Pman.Login.authUser.company_id_id* 1 > 0) {
387                 forceAdmin();
388                 return;
389             }
390             
391             forceCompany();
392             /// create account..
393             
394             
395         }
396         
397
398     },
399     
400     
401     // REMOVE THESE 
402     
403      
404     onLoadTrack : function(id,cb) {
405         this.onLoadTrackCall(id, cb, 'DocumentsCirc_');
406     },
407     onLoadTrackEdit : function(id,cb) {
408         this.onLoadTrackCall(id, cb, 'Documents_');
409     },
410     
411     
412     /// ----------- FIXME -----
413     
414     
415     onLoadTrackCall : function(id,cb, cls) {
416         Roo.get(document.body).mask("Loading Document details");
417
418         Pman.request({
419             url: baseURL + '/Roo/Documents.html',  
420             params: {
421                 _id: id
422             },  
423             method: 'GET',  
424             success : function(data) {
425                 Roo.get(document.body).unmask();
426              
427                 
428                 switch(data.in_out) {
429                     case 'IN' : cls+='In';break;
430                     case 'OUT' : cls+='Out';break;
431                     case 'WIP' : cls+='Wip';break;
432                     default: 
433                         Roo.MessageBox.alert("Error", "invalid in_out");
434                         return;
435                 }
436                 Pman.Dialog[cls].show(data, cb ? cb : Pman.refreshActivePanel);
437             }, 
438             
439             failure: function() {
440                 Roo.get(document.body).unmask();
441                 //if (cb) {
442                 //    cb.call(false);
443                 //}
444                  
445            }
446         });
447           
448     },
449     
450     refreshActivePanel : function() {
451         var actpan = this.layout.getRegion('center').getActivePanel();
452         if (actpan.controller && actpan.controller.paging) {
453             actpan.controller.paging.onClick('refresh');
454             return;
455         }
456         
457         var agid = Pman.layout.getRegion('center').getActivePanel().id;
458         if (!agid) {
459             return;
460         }
461         Pman.Tab[agid].paging.onClick('refresh');
462     },
463     toCidV : function(data) {
464         return 'C' + data.in_out.substring(0,1) + data.cid;
465     },
466     
467     
468     /**
469      * hasPerm:
470      * Does the authenticated user have permission to see this.
471      * 
472      * @param {String} name the [Module].[permission] to check for
473      * @param {Char} lvl  - which type of permission to use (eg. S=show...)
474      * @returns {Boolean} tue indicates permission allowed
475      */
476     hasPerm: function(name, lvl) {
477         if (
478             (typeof(Pman.Login.authUser) != 'object')
479             ||
480             (typeof(Pman.Login.authUser.perms) != 'object')
481             ||
482             (typeof(Pman.Login.authUser.perms[name]) != 'string')
483             ) {
484                 return false;
485         }
486         
487         return Pman.Login.authUser.perms[name].indexOf(lvl) > -1;
488         
489     },
490     /**
491      * hasPermExists:
492      * Is there a permission defined for this (used by module registration.)
493      * 
494      * @param {String} name the [Module].[permission] to check for
495      * @returns {Boolean} tue indicates permission exists.
496      */
497     hasPermExists: function(name) {
498         if (
499             (typeof(Pman.Login.authUser) != 'object')
500             ||
501             (typeof(Pman.Login.authUser.perms) != 'object')
502             ||
503             (typeof(Pman.Login.authUser.perms[name]) != 'string')
504             ) {
505                 return false;
506         }
507         return true;
508     },
509     
510     
511     
512     
513     
514     
515     Readers : {},
516     ColModels : {},
517     Forms : {},
518     Tab : {},
519     Dialog : {},
520     
521     processResponse : function (response)
522     {
523         var res = '';
524         try {
525             res = Roo.decode(response.responseText);
526             // oops...
527             if (typeof(res) != 'object') {
528                 res = { success : false, errorMsg : res, errors : true };
529             }
530             if (typeof(res.success) == 'undefined') {
531                 res.success = false;
532             }
533             
534         } catch(e) {
535             res = { success : false,  errorMsg : response.responseText, errors : true };
536         }
537         return res;
538     },
539     genericDelete : function(tab,tbl) {
540         
541         var r = [];
542         
543             
544         var s = tab.grid.getSelectionModel().getSelections();
545         if (!s.length)  {
546             Roo.MessageBox.alert("Error", "Select at least one Row to delete" );
547             return '';
548         }
549         
550         for(var i = 0; i < s.length; i++) {
551             r.push(s[i].data.id);
552         }
553     
554         Roo.MessageBox.confirm("Confirm", "Are you sure you want to delete that?",
555             function(btn) {
556                 if (btn != 'yes') {
557                     return;
558                 }
559                 // what about the toolbar??
560                 tab.grid.getView().mainWrap.mask("Deleting");
561                 Pman.request({
562                     url: baseURL + '/Roo/'+tbl+'.php',
563                     method: 'GET',
564                     params: {
565                         _delete : r.join(',')
566                     },
567                     success: function(response) {
568                         tab.grid.getView().mainWrap.unmask();
569                         if ( tab.paging ) {
570                             tab.paging.onClick('refresh');   
571                         } else if (tab.refresh) {
572                             tab.refresh();
573                         } else if (tab.grid.footer && tab.grid.footer.onClick) {
574                             // new xtype built grids
575                             tab.grid.footer.onClick('refresh');   
576                         } else {
577                             tab.grid.getDataSource().load();
578                         }
579                         
580                         
581                         
582                     },
583                     failure: function(act) {
584                         tab.grid.getView().mainWrap.unmask();
585                         Roo.MessageBox.alert("Error", "Error Deleting");
586                     }
587                     
588                 });
589             }
590             
591         );
592         return '';
593     },
594     
595     
596     standardActionFailed :  function(f, act, cb) {
597     
598         if (act.failureType == 'client') {
599             Roo.MessageBox.alert("Error", "Please Correct all the errors in red", cb);
600             return;
601         }
602         if (act.failureType == 'connect') {
603             Roo.MessageBox.alert("Error", "Problem Connecting to Server - please try again.", cb);
604             return;
605         }
606         
607         if (act.type == 'submit') {
608             
609             Roo.MessageBox.alert("Error", typeof(act.result.errorMsg) == 'string' ?
610                 String.format('{0}', act.result.errorMsg) : 
611                 "Saving failed = fix errors and try again", cb);
612             return;
613         }
614         
615         // what about load failing..
616         Roo.MessageBox.alert("Error", "Error loading details",cb); 
617     },
618     /**
619      * Depreciated - USE new Pman.Request
620     * 
621      * 
622      */
623     request : function(c) {
624         var r= new Roo.data.Connection({
625             timeout : typeof(c.timeout) == 'undefined' ?  30000 : c.timeout
626         });
627         r.request({
628             url: c.url,
629             method : c.method,
630             params: c.params,
631             xmlData : c.xmlData,
632             success:  function(response, opts)  {  // check successfull...
633                
634                 var res = Pman.processResponse(response);
635                 
636                 if (!res.success) { // error!
637                     if (c.failure) {
638                         if (true === c.failure.call(this,response, opts)) {
639                             return;
640                         }
641                     }
642                     Roo.MessageBox.hide();
643                     Roo.MessageBox.alert("Error", res.errorMsg ? res.errorMsg : "Error Sending");
644                     return;
645                 }
646                 
647                 c.success.call(this, res.data);
648                 
649                 return; 
650             },
651             failure :  function(response, opts)  {  // check successfull...
652                 
653                 if (c.failure) {
654                     if (true === c.failure.call(this,response, opts)) {
655                         return;
656                     }
657                 }
658                 Roo.MessageBox.hide();
659                 Roo.MessageBox.alert("Error", "Connection timed out sending");
660                 Roo.log(response);
661                 
662             },
663             scope: this
664             
665         });
666     },
667     
668     
669     // depreciated - use Pman.Download()
670     
671     download : function(c) {
672         
673         return new Pman.Download(c);
674     },
675     
676     // fixme - move to document manager...
677     downloadRevision : function(doc, rev)
678     {
679         this.download({
680             url: baseURL + '/Documents/Doc/DownloadRev/'+ doc.id + '/' + rev + '/' +
681                 doc.project_id_code + '-' + doc.cidV + '-' + rev  + '-' +  doc.filename
682         }); 
683                     
684     },
685     
686     
687     exportCSV : function(c) {
688         
689         for(var i=0;i < c.csvFormat.length;i++) {
690             c.params['csvCols['+i+']'] = c.csvFormat[i][0];
691             c.params['csvTitles['+i+']'] = c.csvFormat[i][1];
692         }
693         c.url +=  '?' + Roo.urlEncode(c.params);
694         this.download(c);
695
696     },
697     
698     
699     prettyDate : function (value) 
700     {
701         if (typeof(value) == 'string') {
702             var ds = Date.parseDate(value, 'Y-m-d H:i:s');
703             if (ds) {
704                 return this.prettyDate(ds);
705             }
706             ds = Date.parseDate(value, 'Y-m-d');
707             if (ds) {
708                 return this.prettyDate(ds);
709             }
710             return '';
711         }
712 // last 7 days...
713         if (!value) {
714             return '';
715         }
716         var td = new Date();
717         var daysSince = Math.floor(td.getElapsed(value) / (1000 * 60*60*24));
718         if (daysSince < 7) {
719             return value.dateFormat('D H:i');
720         }
721         
722         // same month
723         if (td.dateFormat('m') == value.dateFormat('m')) {
724             return value.dateFormat('dS D');
725         }
726         // same year?
727         if (td.dateFormat('Y') == value.dateFormat('Y')) {
728             return value.dateFormat('dS M');
729         }
730         return value.dateFormat('d M Y');
731     },
732     loadException : function(a,b,c,d)
733     {
734         if (d && d.authFailure) {
735             Pman.Login.show();
736             return;
737         }
738         Roo.MessageBox.alert("Problem Loading Data", a.message || c.statusText);
739     },
740     
741     
742     /**
743      * 
744      * Routine to flash alerts in the title bar..
745      * 
746      * 
747      */
748     
749     notifyActive : false,
750     
751     notifyTitle: function(msg)
752     {
753         if (this.notifyActive ) {
754             return;
755         }
756         var stop = false;
757         
758         var stopper = function() {
759             stop = true;
760              document.title = oldtitle;
761         };
762         
763         Roo.get(document.body).on('mousemove', stopper, this);
764         var oldtitle = document.title;
765         var s = 1;
766         var _this = this;
767         var ivl = window.setInterval(function() {
768             
769             if (stop) {
770                 Roo.get(document.body).un('mousemove', stopper, this);
771                 _this.notifyActive = false;
772                 document.title = oldtitle;
773                 window.clearInterval(ivl);
774                 return true;
775             }
776             s = !s;
777             document.title = s ? msg : oldtitle;
778             return false;     
779         }, 1000); // every 120 secs = 2mins..
780          document.title =   msg;
781         
782         
783         
784     },
785     /**
786      * @property {Array} appModules  - array based on AppModules global
787      */
788     appModules : false,
789     
790     modules : false,
791     
792     
793     xregister : function(obj)
794     {
795         
796         // work out owner..
797         if (!this.appModules === false) {
798             this.appModules = typeof(AppModules ) == 'undefined'? [] :
799                 AppModules.split(',');
800         }
801         
802         
803         
804         // ignore registration of objects which are disabled.
805         // global supplied by master.html
806         appDisabled = typeof(appDisabled) == 'undefined' ? [] : appDisabled;
807         
808         
809         /// design flaw
810         // previously we did not a good naming policy for module and parts
811         // most things that are called module here, really are 'parts'
812         // new versions should have 'part' as [ module : part ]
813         
814         
815         if (typeof(obj.part) != 'undefined')  {
816             
817             var permname = obj.part.join('.');
818                 // we now have permission...
819                 // obj.moduleOwner '.' lname
820                 
821             if (this.hasPermExists(permname) && !this.hasPerm(permname,'S')) {
822                 // it's a turned off permission...
823                 Roo.log(permname + " is Disabled for this user");
824                 obj.disabled = true;
825                 return;
826             }
827             if (appDisabled.indexOf(permname) > -1)  {
828                 Roo.log(permname + " is Disabled for this site");
829                 obj.disabled = true;
830                 return;
831             }
832             
833             
834         }
835         
836         if ( obj.isTop) {
837             // false parent... use it..
838             return;
839         }
840         
841         
842         if (obj.parent === Pman) {
843             obj.parent = Pman.fakeRoot;
844         }
845         
846         if (typeof(obj.parent) == 'undefined') {
847             console.log("Parent is undefined");
848             console.log(obj);
849             obj.disabled = true;
850             return;
851         }
852             
853             
854         if (obj.parent === false) {
855             obj.disabled = true;
856             console.log('ignoring top level object (as parent===false found)');
857             console.log(obj);
858             return;
859         }
860         // this is an error condition - the parent does not exist..
861             // technically it should not happen..
862           
863         // hack for Pman parent == Pman..
864         if (obj.parent == obj.module) {
865             obj.parent = false;
866             
867         }
868        
869         
870     },
871     /**
872      * DEPRICATED : use Roo.XComponents now..
873      * 
874      * Pman.register({
875           modKey : '00-admin-xxxx',
876           module : Pman.Tab.projectMgr, << really a components..
877           part : [ 'Admin', 'ProjectManager' ]
878           moduleOwner : 
879           region : 'center',
880           parent : Pman.layout
881         })
882      * 
883      */
884     register : function(obj)
885     {
886         
887         //this.xregister(obj);
888         
889         
890         // old style calls go in here..
891         // we need to convert the object so that it looks a bit like an XCompoenent..
892          
893         obj.render = function()
894         {
895             if (!this.parent) {
896                 Roo.log("Skip module, as parent does not exist");
897                 Roo.log(this);
898                 return;
899             }
900             //if (typeof(mod) == 'function') {
901             //    mod();
902                 
903             if (typeof(this.region) == 'undefined') {
904                 Roo.log("Module does not have region defined, skipping");
905                 Roo.log(this);
906                 return;
907             }
908             if (this.module.disabled) {
909                 Roo.log("Module disabled, should not rendering")
910                 Roo.log(this);
911                 return;
912             }
913             
914             if (!this.parent.layout) {
915                 Roo.log("Module parent does not have property layout.")
916                 Roo.log(this);
917                 return;
918             }
919         
920            // honour DEPRICATED permname setings..
921            // new code should use PART name, and matching permissions.
922             if (this.permname && this.permname.length) {
923                 if (Pman.hasPerm(this.permname, 'S')) {
924                    this.add(this.parent.layout, this.region);    
925                 }
926                 return;
927             }
928             this.add(this.parent.layout, this.region);    
929               
930         };
931         // map some of the standard properties..
932         obj.order = obj.modKey;
933         
934         // a bit risky...
935         
936         
937         
938         // the other issue we have is that
939          
940         
941         // Roo.log("CALLING XComponent register with : " + obj.name);
942         
943         // this will call xregister as it's the on.register handler..
944         Roo.XComponent.register(obj.isTop ? obj : Roo.apply(obj.module, obj));
945         /*
946         
947         
948         if (obj.disabled) {
949             return;
950         }
951          
952         if (!obj.parent.modules) {
953             obj.parent.modules = new Roo.util.MixedCollection(false, function(o) { return o.modKey });
954         }
955         
956         obj.parent.modules.add(obj);
957         */
958     },
959     
960     
961     buildModules : function(parent, onComplete) 
962     {
963         Roo.XComponent.build();
964         /*
965         var _this = this;
966         var cmp = function(a,b) {   
967             return String(a).toUpperCase() > String(b).toUpperCase() ? 1 : -1;
968             
969         };
970         if (!parent.modules) {
971             return;
972         }
973         parent.modules.keySort('ASC',  cmp );
974         var mods = [];
975         
976         
977         // add modules to their parents..
978         var addMod = function(m) {
979            // console.log(m.modKey);
980             
981             mods.push(m);
982             if (m.module.modules) {
983                 m.module.modules.keySort('ASC',  cmp );
984                 m.module.modules.each(addMod);
985             }
986             if (m.finalize) {
987                 m.finalize.name = m.name + " (clean up) ";
988                 mods.push(m.finalize);
989             }
990             
991         }
992  
993         parent.modules.each(addMod);
994         //this.allmods = mods;
995         //console.log(mods);
996         //return;
997         if (!mods.length) {
998             if (onComplete) onComplete();
999             return;
1000         }
1001         // flash it up as modal - so we store the mask!?
1002         Roo.MessageBox.show({ title: 'loading' });
1003         Roo.MessageBox.show({
1004            title: "Please wait...",
1005            msg: "Building Interface...",
1006            width:450,
1007            progress:true,
1008            closable:false,
1009            modal: false
1010           
1011         });
1012         var n = 0;
1013         var progressRun = function() {
1014             
1015             var mod = mods[n];
1016             
1017             
1018             Roo.MessageBox.updateProgress(
1019                 (n+1)/mods.length,  "Building Interface " + (n+1) + 
1020                     " of " + mods.length + 
1021                     (mod.name ? (' - ' + mod.name) : '')
1022                     );
1023             
1024             
1025             
1026             if (typeof(mod) == 'function') {
1027                 mod();
1028                 
1029             } else  if (typeof(mod.region) == 'undefined') {
1030                 Roo.log("Module does not have region defined, skipping");
1031                 Roo.log(mod);
1032                 
1033             } else  if (mod.parent.layout && !mod.module.disabled) {
1034                 // honour permname setings..
1035                 if (mod.permname && mod.permname.length) {
1036                     if (Pman.hasPerm(mod.permname, 'S')) {
1037                         mod.module.add(mod.parent.layout, mod.region);    
1038                     }
1039                 } else {
1040                     mod.module.add(mod.parent.layout, mod.region);    
1041                 } 
1042             }
1043             
1044             
1045             n++;
1046             if (n >= mods.length) {
1047                 onComplete();  
1048                 return;
1049             }
1050                 
1051             
1052             progressRun.defer(10, Pman);    
1053         }
1054         progressRun.defer(1, Pman);
1055         */
1056         
1057         
1058     },
1059     
1060     invertColor : function(c)
1061     {
1062         // read..
1063         var ca = [];
1064         for(var i = 0; i < 3; i++){
1065             ca[i] = parseInt(c.charAt((i*2)+1) + c.charAt((i*2)+2), 16);
1066         }
1067             
1068         // invert..
1069         var col = '';
1070         Roo.each(ca, function(hi) {
1071             var h = parseInt(255-hi).toString(16);
1072             if(h < 16){
1073                 h = '0' + h;
1074             }
1075             col += h;
1076         });
1077         return '#' + col;
1078         
1079     }
1080     
1081     
1082     
1083     
1084     
1085     
1086     
1087 });
1088