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