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