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