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