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