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