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