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