check what is being written to our log files.
[Pman.Core] / Pman.js
1  
2 /**
3  * 
4  *  
5  *  This is the main Pman class
6  *  - it's a bit too heavy at present - needs to go on a diet....
7  */
8  
9 // translation..
10 if (typeof(_T) == 'undefined') { _T={};}
11
12
13
14 Roo.XComponent.on('register', function(e) {
15     if (typeof(Pman) != 'undefined') { return Pman.xregister(e); } return true;
16 });
17 Roo.XComponent.on('beforebuild', function(e) {
18     if (typeof(Pman) != 'undefined') { return Pman.xbeforebuild(e); } return true;
19 });
20
21 Roo.XComponent.on('buildcomplete',  
22     function() {
23         Pman.building = false;   
24         Pman.layout.getRegion('center').showPanel(0);
25         Pman.layout.endUpdate(); 
26         Pman.addTopToolbar();  
27         Pman.finalize();
28         Pman.fireEvent('load',this);
29         
30         if (!Pman.layout.getRegion('south').panels.length) {
31             Pman.layout.getRegion('south').hide();
32         }
33     
34     
35     }
36 );
37
38 //Roo.debug = 1;
39   
40
41 Pman = new Roo.Document(
42 {
43    /// appVersion: '1.7', // fixme = needs to be removed - use Global AppVersion
44     subMenuItems : [],
45     topMenuItems : [],
46     rightNames: { }, /// register right names here - so they can be translated and rendered.
47     /**
48      * @property {Roo.menu.Menu} pulldownMenu - the 'add menu pulldown, you can use it to add items..
49      *
50      */
51     pulldownMenu : false, 
52     
53     
54     buildCompleted : false, // flag to say if we are building interface..
55     events : {
56         'beforeload' : true, // fired after page ready, before module building.
57         'load' : true, // fired after module building
58         'authrefreshed' : true // fire on auth updated?? - should be on Login?!?!?
59     },
60     
61     listeners : {
62         'ready' : function()
63         {
64             // kludge to fix firebug debugger
65             if (typeof(console) == 'undefined') {
66                 console = { log : function() {  } };
67             }
68             
69             // remove loader..
70             if (Roo.get('loading')) {
71                 Roo.get('loading').remove();
72             }
73             
74             Roo.state.Manager.setProvider(new Roo.state.CookieProvider());
75             
76             // link errors...
77             
78             if (AppLinkError.length) {
79                 Roo.MessageBox.alert("Error", AppLinkError, function() {
80                     Pman.Login.onLoad();
81                 });
82                 return;
83             }
84             
85             
86             // reset password!!!!
87             if (showNewPass.length) {
88                 Pman.PasswordChange.show(  { passwordReset : showNewPass },
89                     function(data) {
90                         // fail and success we do  a load...
91                         Pman.Login.onLoad();
92                     }
93                 );
94                 return;
95             }
96              
97             Pman.Login.onLoad();
98             
99         },
100         'load' : function()
101         {
102             if (Roo.get('loading-logo-tile')) {
103                 Roo.get('loading-logo-tile').remove();
104             }
105             if (Roo.get('loading-logo-tile-top')) {
106                 Roo.get('loading-logo-tile-top').remove();
107             }
108             if (Roo.get('loading-logo-bottom')) {
109                 Roo.get('loading-logo-bottom').remove();
110             }
111             if (Roo.get('loading-logo-center')) {
112                 Roo.get('loading-logo-center').remove();
113             }
114         }   
115         
116     },
117    
118     fakeRoot :  new Roo.XComponent( {
119         modKey : '000',
120         module : 'Pman',
121         region : 'center',
122         parent : false,
123         isTop : true,
124         name : "Pman Base",
125         disabled : false, 
126         permname: '' ,
127         render : function (el) { this.el = this.layout; }
128     }),
129     
130     layout: false,
131     
132     onload: function() {
133         //this.fireEvent('beforeload',this);
134         
135         
136         
137         if (this.layout) {
138             return; // already loaded
139         } 
140         if (Roo.get('loading')) {
141             Roo.get('loading').remove();
142         }
143         if (Roo.get('loading-mask')) {
144             Roo.get('loading-mask').show();
145         }
146         
147      
148         var _this = this;
149         this.stime = new Date();
150         this.layout = new Roo.BorderLayout(document.body, {
151             north: {
152                 split:false,
153                 initialSize: 25,
154                 titlebar: false
155             },
156          
157              
158             center: {
159                 titlebar: false,
160                 autoScroll:false,
161                 closeOnTab: true,
162                 tabPosition: 'top',
163                 //resizeTabs: true,
164                 alwaysShowTabs: true,
165                 minTabWidth: 140
166             } ,
167             south: {
168                 collapsible : true,
169                 collapsed : true,
170                 split:false,
171                 height: 120,
172                 titlebar: false 
173             }
174             
175         });
176         this.fakeRoot.layout = this.layout;
177         /*
178         Pman.register( Roo.apply(this.fakeRoot, {
179             layout : this.layout      
180                 
181                                  
182         } ) );
183         */
184         
185         // creates all the modules ready to load..
186         
187         this.fireEvent('beforeload',this);
188         
189         
190         
191         this.layout.beginUpdate();
192         this.layout.add('north', new Roo.ContentPanel('title', 'North'));
193         var au = Pman.Login.authUser;
194         if (au.id > 0 && au.company_id_background_color && au.company_id_background_color.length) {
195             Roo.get('title').dom.style.backgroundColor = '#' + au.company_id_background_color;
196             Roo.get('headerInformation').dom.style.color = this.invertColor('#' + au.company_id_background_color);
197         }
198         if (au.id > 0 && au.company_id_logo_id * 1 > 0) {
199             Roo.get('headerInformation-company-logo').dom.src =  baseURL + 
200                 '/Images/' + au.company_id_logo_id + '/' + au.company_id_logo_id_filename;
201         } else {
202             Roo.get('headerInformation-company-logo').dom.src = Roo.BLANK_IMAGE_URL;
203         }
204         
205         Roo.get('headerInformation').dom.innerHTML = String.format(
206                 "You are Logged in as <b>{0} ({1})</b>", // to {4} v{3}", // for <b>{2}</b>",
207                 au.name, au.email, au.company_id_name, 
208                 AppVersion , appNameShort
209         );
210         
211         
212         document.title = appName + ' v' + AppVersion + ' - ' + au.company_id_name;
213         Roo.QuickTips.init(); 
214         if (Roo.isGecko) {
215            Roo.useShims = true;
216         }
217        
218         //this.mainLayout.beginUpdate();
219         //var maskDom = Roo.get(document.body)._maskMsg.dom
220         this.layout.beginUpdate();
221         
222         Pman.building = true;
223         Roo.XComponent.build();
224          
225         
226         
227      
228     },
229     
230     addTopToolbar : function()
231     {
232           //console.log( "t6:" + ((new Date())-stime));
233         //this.mainLayout.endUpdate();
234         // make a new tab to hold administration stuff...
235         
236        
237         //console.log( "t7:" + ((new Date())-stime));
238         if (!Pman.layout.getRegion('center').tabs) {
239                 Roo.log("Error could not find tabs? - not adding toolbar?");
240                 return;
241         }
242         
243         var se = Pman.layout.getRegion('center').tabs.stripEl;
244         var tbh = se.createChild( 
245                 { tag: 'td', style: 'width:100%;'  });
246         
247         var lotb = new Roo.Toolbar(tbh);
248         
249         if (Roo.isSafari) {
250             var tbl = se.child('table', true);
251             tbl.setAttribute('width', '100%');
252         }
253         
254         if (Pman.hasPerm('Core.ChangePassword','S')) {
255             
256             lotb.add(
257                 new Roo.Toolbar.Fill(), 
258          
259                 {
260                     text: "Change Password",
261                     cls: 'x-btn-text-icon',
262                     icon: rootURL + '/Pman/templates/images/change-password.gif',
263                     handler : function(){
264                         Pman.PasswordChange.show({});
265                     }
266                 }, '-'
267             );
268         }     
269             
270         if (this.topMenuItems.length) {
271             
272             Roo.each(this.topMenuItems, function (mi) {
273                 lotb.add(mi);
274             });
275             lotb.add('-');
276         }
277         
278         
279         
280         if (this.subMenuItems.length) {
281             
282             this.subMenuItems.sort(function (a,b) {
283                 return a.seqid > b.seqid ? 1 : -1;
284             });
285             // chop off last seperator.
286             // since we always add it.. just chop of last item
287             this.subMenuItems.pop(); 
288             
289             var btn = new Roo.Toolbar.Button( 
290                 {
291                     text: "Add New Item",
292                     cls: 'x-btn-text-icon',
293                     icon: Roo.rootURL + 'images/default/dd/drop-add.gif',
294                     menu : {
295                         items : this.subMenuItems
296                     }     
297                 }
298             );
299             this.pulldownMenu = btn.menu;
300             lotb.add(btn, '-');
301             
302         }
303        
304         lotb.add(
305             {
306                 text: "Logout",
307                 cls: 'x-btn-text-icon',
308                 icon: rootURL + '/Pman/templates/images/logout.gif',
309                 handler: function() {
310                     Pman.Login.logout();
311                 }
312                  
313             }
314         );
315       
316        // this.layout.endUpdate();
317     },
318     
319     
320     finalize : function() {
321         
322       
323        
324         window.onbeforeunload = function(e) { 
325             e = e || window.event;
326             var r = "Closing this window will loose changes, are you sure you want to do that?";
327
328             // For IE and Firefox
329             if (e) {
330                 e.returnValue = r;
331             }
332
333             // For Safari
334             return r;
335             
336         };
337         
338         Roo.MessageBox.hide();
339         if (Roo.get('loading-mask')) {
340            Roo.get('loading-mask').remove();
341         }
342         
343         
344         this.buildCompleted = true; // now we can force refreshes on everything..
345         
346         
347         // does the URL indicate we want to see a system..
348         if (AppTrackOnLoad * 1 > 0) {
349             this.onLoadTrack(AppTrackOnLoad,false);
350         }
351         
352         // Open system..
353         
354         var forceAdmin = function(data)
355         {
356             if (!data || !data.id) {
357                 //Roo.log("Force Admin");
358                 Pman.Dialog.PersonStaff.show( 
359                     { 
360                         id : 0, 
361                         company_id : Pman.Login.authUser.company_id * 1, 
362                         company_id_name : Pman.Login.authUser.company_id_name
363                     }, function(data) {
364                         forceAdmin(data);
365                     }
366                 );
367                 return;
368             }
369             
370             Roo.state.Manager.set('Pman.Login.username', data.email),
371             window.onbeforeunload = false;
372             document.location = baseURL + '?ts=' + Math.random();
373         }
374         
375         var forceCompany = function(data) {
376             if (Pman.Login.authUser.company_id * 1 > 0) {
377                 forceAdmin();
378                 return;
379             }
380             if (!data || !data.id) {
381                 Pman.Dialog.CoreCompanies.show( { id : 0, comptype: 'OWNER' }, function(data) {
382                     Roo.log("company dialog returned");
383                     Roo.log(data);
384                     forceCompany(data);
385                 });
386                 return;
387             }
388             Pman.Login.authUser.company_id_id  = data.id;
389             Pman.Login.authUser.company_id  = data.id;
390             Pman.Login.authUser.company_id_name  = data.name;
391             Roo.log("forcing admin");
392             forceAdmin();
393         }
394         
395         if (Pman.Login.authUser.id < 0) {
396             // admin company has been created - create the user..
397             if (Pman.Login.authUser.company_id* 1 > 0) {
398                 forceAdmin();
399                 return;
400             }
401             
402             forceCompany();
403             /// create account..
404             
405             
406         }
407         
408
409     },
410     
411     
412     // REMOVE THESE 
413     
414      
415     onLoadTrack : function(id,cb) {
416         this.onLoadTrackCall(id, cb, 'DocumentsCirc_');
417     },
418     onLoadTrackEdit : function(id,cb) {
419         this.onLoadTrackCall(id, cb, 'Documents_');
420     },
421     
422     
423     /// ----------- FIXME -----
424     
425     
426     onLoadTrackCall : function(id,cb, cls) {
427         Roo.get(document.body).mask("Loading Document details");
428
429         new Pman.Request({
430             url: baseURL + '/Roo/Documents.html',  
431             params: {
432                 _id: id
433             },  
434             method: 'GET',  
435             success : function(res) {
436                 var data = res.data;
437                 Roo.get(document.body).unmask();
438              
439                 
440                 switch(data.in_out) {
441                     case 'IN' : cls+='In';break;
442                     case 'OUT' : cls+='Out';break;
443                     case 'WIP' : cls+='Wip';break;
444                     default: 
445                         Roo.MessageBox.alert("Error", "invalid in_out");
446                         return;
447                 }
448                 Pman.Dialog[cls].show(data, cb ? cb : Pman.refreshActivePanel);
449             }, 
450             
451             failure: function() {
452                 Roo.get(document.body).unmask();
453                 //if (cb) {
454                 //    cb.call(false);
455                 //}
456                  
457            }
458         });
459           
460     },
461     
462     refreshActivePanel : function() {
463         var actpan = this.layout.getRegion('center').getActivePanel();
464         if (actpan.controller && actpan.controller.paging) {
465             actpan.controller.paging.onClick('refresh');
466             return;
467         }
468         
469         var agid = Pman.layout.getRegion('center').getActivePanel().id;
470         if (!agid) {
471             return;
472         }
473         Pman.Tab[agid].paging.onClick('refresh');
474     },
475     toCidV : function(data) {
476         return 'C' + data.in_out.substring(0,1) + data.cid;
477     },
478     
479     
480     /**
481      * hasPerm:
482      * Does the authenticated user have permission to see this.
483      * 
484      * @param {String} name the [Module].[permission] to check for
485      * @param {Char} lvl  - which type of permission to use (eg. S=show...)
486      * @returns {Boolean} tue indicates permission allowed
487      */
488     hasPerm: function(name, lvl) {
489         if (
490             (typeof(Pman.Login.authUser) != 'object')
491             ||
492             (typeof(Pman.Login.authUser.perms) != 'object')
493             ||
494             (typeof(Pman.Login.authUser.perms[name]) != 'string')
495             ) {
496                 return false;
497         }
498         
499         return Pman.Login.authUser.perms[name].indexOf(lvl) > -1;
500         
501     },
502     /**
503      * hasPermExists:
504      * Is there a permission defined for this (used by module registration.)
505      * 
506      * @param {String} name the [Module].[permission] to check for
507      * @returns {Boolean} tue indicates permission exists.
508      */
509     hasPermExists: function(name) {
510         if (
511             (typeof(Pman.Login.authUser) != 'object')
512             ||
513             (typeof(Pman.Login.authUser.perms) != 'object')
514             ||
515             (typeof(Pman.Login.authUser.perms[name]) != 'string')
516             ) {
517                 return false;
518         }
519         return true;
520     },
521     
522     
523     
524     
525     
526     
527     Readers : {},
528     ColModels : {},
529     Forms : {},
530     Tab : {},
531     Dialog : {},
532     
533     processResponse : function (response)
534     {
535         var res = '';
536         try {
537             res = Roo.decode(response.responseText);
538             // oops...
539             if (typeof(res) != 'object') {
540                 res = { success : false, errorMsg : res, errors : true };
541             }
542             if (typeof(res.success) == 'undefined') {
543                 res.success = false;
544             }
545             
546         } catch(e) {
547             res = { success : false,  errorMsg : response.responseText, errors : true };
548         }
549         return res;
550     },
551     genericDelete : function(tab,tbl) {
552         
553         var r = [];
554  
555             
556         var s = tab.grid.getSelectionModel().getSelections();
557         if (!s.length)  {
558             Roo.MessageBox.alert("Error", "Select at least one Row to delete" );
559             return '';
560         }
561         var reader = tab.grid.reader || tab.grid.ds.reader;
562         for(var i = 0; i < s.length; i++) {
563             r.push(reader.getId(s[i].json));
564         }
565     
566         Roo.MessageBox.confirm("Confirm", "Are you sure you want to delete that?",
567             function(btn) {
568                 if (btn != 'yes') {
569                     return;
570                 }
571                 // what about the toolbar??
572                 tab.grid.getView().mainWrap.mask("Deleting");
573                 new Pman.Request({
574                     url: baseURL + '/Roo/'+tbl+'.php',
575                     method: 'POST',
576                     params: {
577                         _delete : r.join(',')
578                     },
579                     success: function(response) {
580                         tab.grid.getView().mainWrap.unmask();
581                         if ( tab.paging ) {
582                             tab.paging.onClick('refresh');   
583                         } else if (tab.grid.footer && tab.grid.footer.onClick) {
584                             // new xtype built grids
585                             tab.grid.footer.onClick('refresh');   
586                         } else if (tab.refresh) {
587                             tab.refresh(); // this might cause problems as panels have a refresh method?
588                         } else {
589                             tab.grid.getDataSource().load();
590                         }
591                         
592                         
593                         
594                     },
595                     failure: function(act) {
596                         
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             if (obj.permname && obj.permname.length && Pman.hasPermExists(obj.permname) && !Pman.hasPerm(obj.permname,'S')) {
875                 // it's a turned off permission...
876                 Roo.log(obj.permname + " is Disabled for this user");
877                 obj.disabled = true;
878                 return;
879             }
880             
881         }
882         
883         
884     },
885     
886     /**
887      * DEPRICATED : use Roo.XComponents now..
888      * 
889      * Pman.register({
890           modKey : '00-admin-xxxx',
891           module : Pman.Tab.projectMgr, << really a components..
892           part : [ 'Admin', 'ProjectManager' ]
893           moduleOwner : 
894           region : 'center',
895           parent : Pman.layout
896         })
897      * 
898      */
899     register : function(obj)
900     {
901         
902         //this.xregister(obj);
903         
904         
905         // old style calls go in here..
906         // we need to convert the object so that it looks a bit like an XCompoenent..
907          
908         obj.render = function()
909         {
910             if (!this.parent) {
911                 Roo.log("Skip module, as parent does not exist");
912                 Roo.log(this);
913                 return;
914             }
915             //if (typeof(mod) == 'function') {
916             //    mod();
917                 
918             if (typeof(this.region) == 'undefined') {
919                 Roo.log("Module does not have region defined, skipping");
920                 Roo.log(this);
921                 return;
922             }
923             if (this.module.disabled) {
924                 Roo.log("Module disabled, should not rendering");
925                 Roo.log(this);
926                 return;
927             }
928              
929             if (!this.parent.layout) {
930                 Roo.log("Module parent does not have property layout.");
931                 Roo.log(this);
932                 return;
933             }
934         
935            // honour DEPRICATED permname setings..
936            // new code should use PART name, and matching permissions.
937             if (this.permname && this.permname.length) {
938                 if (!Pman.hasPerm(this.permname, 'S')) {
939                     return;
940                 }
941                 
942             }
943             this.add(this.parent.layout, this.region);
944             this.el = this.layout;
945             
946             
947               
948         };
949         // map some of the standard properties..
950         obj.order = obj.modKey;
951         
952         // a bit risky...
953         
954         
955         
956         // the other issue we have is that
957          
958         
959         // Roo.log("CALLING XComponent register with : " + obj.name);
960         Roo.log(obj);
961         // this will call xregister as it's the on.register handler..
962         Roo.XComponent.register(obj.isTop ? obj : Roo.apply(obj.module, obj));
963          
964     } ,
965     invertColor : function(c)
966     {
967         // read..
968         var ca = [];
969         for(var i = 0; i < 3; i++){
970             ca[i] = parseInt(c.charAt((i*2)+1) + c.charAt((i*2)+2), 16);
971         }
972             
973         // invert..
974         var col = '';
975         Roo.each(ca, function(hi) {
976             var h = parseInt(255-hi).toString(16);
977             if(h < 16){
978                 h = '0' + h;
979             }
980             col += h;
981         });
982         return '#' + col;
983         
984     }
985     
986     
987     
988     
989     
990     
991     
992 });
993