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