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