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