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