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