DataObjects/Core_domain.php
[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_id * 1, 
362                         company_id_name : Pman.Login.authUser.company_id_name
363                     }, function(data) {
364                         forceAdmin(data);
365                     }
366                 );
367                 return;
368             }
369             Roo.state.Manager.set('Pman.Login.username', data.email),
370             window.onbeforeunload = false;
371             document.location = baseURL + '?ts=' + Math.random();
372         }
373         
374         var forceCompany = function(data) {
375             if (Pman.Login.authUser.company_id * 1 > 0) {
376                 forceAdmin();
377                 return;
378             }
379             if (!data || !data.id) {
380                 Pman.Dialog.CoreCompanies.show( { id : 0, comptype: 'OWNER' }, function(data) {
381                     Roo.log("company dialog returned");
382                     Roo.log(data);
383                     forceCompany(data);
384                 });
385                 return;
386             }
387             Pman.Login.authUser.company_id_id  = data.id;
388             Pman.Login.authUser.company_id  = data.id;
389             Pman.Login.authUser.company_id_name  = data.name;
390             Roo.log("forcing admin");
391             forceAdmin();
392         }
393         
394         if (Pman.Login.authUser.id < 0) {
395             // admin company has been created - create the user..
396             if (Pman.Login.authUser.company_id_id* 1 > 0) {
397                 forceAdmin();
398                 return;
399             }
400             
401             forceCompany();
402             /// create account..
403             
404             
405         }
406         
407
408     },
409     
410     
411     // REMOVE THESE 
412     
413      
414     onLoadTrack : function(id,cb) {
415         this.onLoadTrackCall(id, cb, 'DocumentsCirc_');
416     },
417     onLoadTrackEdit : function(id,cb) {
418         this.onLoadTrackCall(id, cb, 'Documents_');
419     },
420     
421     
422     /// ----------- FIXME -----
423     
424     
425     onLoadTrackCall : function(id,cb, cls) {
426         Roo.get(document.body).mask("Loading Document details");
427
428         new Pman.Request({
429             url: baseURL + '/Roo/Documents.html',  
430             params: {
431                 _id: id
432             },  
433             method: 'GET',  
434             success : function(res) {
435                 var data = res.data;
436                 Roo.get(document.body).unmask();
437              
438                 
439                 switch(data.in_out) {
440                     case 'IN' : cls+='In';break;
441                     case 'OUT' : cls+='Out';break;
442                     case 'WIP' : cls+='Wip';break;
443                     default: 
444                         Roo.MessageBox.alert("Error", "invalid in_out");
445                         return;
446                 }
447                 Pman.Dialog[cls].show(data, cb ? cb : Pman.refreshActivePanel);
448             }, 
449             
450             failure: function() {
451                 Roo.get(document.body).unmask();
452                 //if (cb) {
453                 //    cb.call(false);
454                 //}
455                  
456            }
457         });
458           
459     },
460     
461     refreshActivePanel : function() {
462         var actpan = this.layout.getRegion('center').getActivePanel();
463         if (actpan.controller && actpan.controller.paging) {
464             actpan.controller.paging.onClick('refresh');
465             return;
466         }
467         
468         var agid = Pman.layout.getRegion('center').getActivePanel().id;
469         if (!agid) {
470             return;
471         }
472         Pman.Tab[agid].paging.onClick('refresh');
473     },
474     toCidV : function(data) {
475         return 'C' + data.in_out.substring(0,1) + data.cid;
476     },
477     
478     
479     /**
480      * hasPerm:
481      * Does the authenticated user have permission to see this.
482      * 
483      * @param {String} name the [Module].[permission] to check for
484      * @param {Char} lvl  - which type of permission to use (eg. S=show...)
485      * @returns {Boolean} tue indicates permission allowed
486      */
487     hasPerm: function(name, lvl) {
488         if (
489             (typeof(Pman.Login.authUser) != 'object')
490             ||
491             (typeof(Pman.Login.authUser.perms) != 'object')
492             ||
493             (typeof(Pman.Login.authUser.perms[name]) != 'string')
494             ) {
495                 return false;
496         }
497         
498         return Pman.Login.authUser.perms[name].indexOf(lvl) > -1;
499         
500     },
501     /**
502      * hasPermExists:
503      * Is there a permission defined for this (used by module registration.)
504      * 
505      * @param {String} name the [Module].[permission] to check for
506      * @returns {Boolean} tue indicates permission exists.
507      */
508     hasPermExists: function(name) {
509         if (
510             (typeof(Pman.Login.authUser) != 'object')
511             ||
512             (typeof(Pman.Login.authUser.perms) != 'object')
513             ||
514             (typeof(Pman.Login.authUser.perms[name]) != 'string')
515             ) {
516                 return false;
517         }
518         return true;
519     },
520     
521     
522     
523     
524     
525     
526     Readers : {},
527     ColModels : {},
528     Forms : {},
529     Tab : {},
530     Dialog : {},
531     
532     processResponse : function (response)
533     {
534         var res = '';
535         try {
536             res = Roo.decode(response.responseText);
537             // oops...
538             if (typeof(res) != 'object') {
539                 res = { success : false, errorMsg : res, errors : true };
540             }
541             if (typeof(res.success) == 'undefined') {
542                 res.success = false;
543             }
544             
545         } catch(e) {
546             res = { success : false,  errorMsg : response.responseText, errors : true };
547         }
548         return res;
549     },
550     genericDelete : function(tab,tbl) {
551         
552         var r = [];
553         
554             
555         var s = tab.grid.getSelectionModel().getSelections();
556         if (!s.length)  {
557             Roo.MessageBox.alert("Error", "Select at least one Row to delete" );
558             return '';
559         }
560         var reader = tab.grid.reader || tab.grid.ds.reader;
561         for(var i = 0; i < s.length; i++) {
562             r.push(reader.getId(s[i].json));
563         }
564     
565         Roo.MessageBox.confirm("Confirm", "Are you sure you want to delete that?",
566             function(btn) {
567                 if (btn != 'yes') {
568                     return;
569                 }
570                 // what about the toolbar??
571                 tab.grid.getView().mainWrap.mask("Deleting");
572                 new Pman.Request({
573                     url: baseURL + '/Roo/'+tbl+'.php',
574                     method: 'POST',
575                     params: {
576                         _delete : r.join(',')
577                     },
578                     success: function(response) {
579                         tab.grid.getView().mainWrap.unmask();
580                         if ( tab.paging ) {
581                             tab.paging.onClick('refresh');   
582                         } else if (tab.grid.footer && tab.grid.footer.onClick) {
583                             // new xtype built grids
584                             tab.grid.footer.onClick('refresh');   
585                         } else if (tab.refresh) {
586                             tab.refresh(); // this might cause problems as panels have a refresh method?
587                         } else {
588                             tab.grid.getDataSource().load();
589                         }
590                         
591                         
592                         
593                     },
594                     failure: function(act) {
595                         Roo.log(act);
596                         var msg = '';
597                         try {
598                             msg = act.errorMsg;
599                         } catch(e) {
600                             msg = "Error deleting";
601                         }
602                         tab.grid.getView().mainWrap.unmask();
603                         Roo.MessageBox.alert("Error",  msg);
604                     }
605                     
606                 });
607             }
608             
609         );
610         return '';
611     },
612     
613     
614     standardActionFailed :  function(f, act, cb) {
615     
616         if (act.failureType == 'client') {
617             Roo.MessageBox.alert("Error", "Please Correct all the errors in red", cb);
618             return;
619         }
620         if (act.failureType == 'connect') {
621             Roo.MessageBox.alert("Error", "Problem Connecting to Server - please try again.", cb);
622             return;
623         }
624         
625         if (act.type == 'submit') {
626             
627             Roo.MessageBox.alert("Error", typeof(act.result.errorMsg) == 'string' ?
628                 String.format('{0}', act.result.errorMsg) : 
629                 "Saving failed = fix errors and try again", cb);
630             return;
631         }
632         
633         // what about load failing..
634         Roo.MessageBox.alert("Error", "Error loading details",cb); 
635     },
636     /**
637      * Depreciated - USE new Pman.Request
638     *  We need to replace all the uses with this, however the api is slightly different,
639     *  the success argument is res.data, not res..
640      * 
641      */
642     request : function(c) {
643         return new Pman.Request(c);
644           
645     },
646     
647     
648     // depreciated - use Pman.Download()
649     
650     download : function(c) {
651         
652         return new Pman.Download(c);
653     },
654     
655     // fixme - move to document manager...
656     downloadRevision : function(doc, rev)
657     {
658         this.download({
659             url: baseURL + '/Documents/Doc/DownloadRev/'+ doc.id + '/' + rev + '/' +
660                 doc.project_id_code + '-' + doc.cidV + '-' + rev  + '-' +  doc.filename
661         }); 
662                     
663     },
664     
665     
666     exportCSV : function(c) {
667         
668         for(var i=0;i < c.csvFormat.length;i++) {
669             c.params['csvCols['+i+']'] = c.csvFormat[i][0];
670             c.params['csvTitles['+i+']'] = c.csvFormat[i][1];
671         }
672         c.url +=  '?' + Roo.urlEncode(c.params);
673         this.download(c);
674
675     },
676     
677     
678     prettyDate : function (value) 
679     {
680         if (typeof(value) == 'string') {
681             var ds = Date.parseDate(value, 'Y-m-d H:i:s');
682             if (ds) {
683                 return this.prettyDate(ds);
684             }
685             ds = Date.parseDate(value, 'Y-m-d');
686             if (ds) {
687                 return this.prettyDate(ds);
688             }
689             return '';
690         }
691 // last 7 days...
692         if (!value) {
693             return '';
694         }
695         var td = new Date();
696         var daysSince = Math.floor(td.getElapsed(value) / (1000 * 60*60*24));
697         if (daysSince < 7) {
698             return value.dateFormat('D H:i');
699         }
700         
701         // same month
702         if (td.dateFormat('m') == value.dateFormat('m')) {
703             return value.dateFormat('dS D');
704         }
705         // same year?
706         if (td.dateFormat('Y') == value.dateFormat('Y')) {
707             return value.dateFormat('dS M');
708         }
709         return value.dateFormat('d M Y');
710     },
711     loadException : function(a,b,c,d)
712     {
713         if (d && d.authFailure) {
714             Pman.Login.show();
715             return;
716         }
717         Roo.MessageBox.alert("Problem Loading Data", a.message || c.statusText);
718     },
719     
720     
721     /**
722      * 
723      * Routine to flash alerts in the title bar..
724      * 
725      * 
726      */
727     
728     notifyActive : false,
729     
730     notifyTitle: function(msg)
731     {
732         if (this.notifyActive ) {
733             return;
734         }
735         var stop = false;
736         
737         var stopper = function() {
738             stop = true;
739              document.title = oldtitle;
740         };
741         
742         Roo.get(document.body).on('mousemove', stopper, this);
743         var oldtitle = document.title;
744         var s = 1;
745         var _this = this;
746         var ivl = window.setInterval(function() {
747             
748             if (stop) {
749                 Roo.get(document.body).un('mousemove', stopper, this);
750                 _this.notifyActive = false;
751                 document.title = oldtitle;
752                 window.clearInterval(ivl);
753                 return true;
754             }
755             s = !s;
756             document.title = s ? msg : oldtitle;
757             return false;     
758         }, 1000); // every 120 secs = 2mins..
759          document.title =   msg;
760         
761         
762         
763     },
764     /**
765      * @property {Array} appModules  - array based on AppModules global
766      */
767     appModules : false,
768     
769     modules : false,
770     
771     
772     xregister : function(obj)
773     {
774         
775         // work out owner..
776         if (!Pman.appModules === false) {
777             Pman.appModules = typeof(AppModules ) == 'undefined'? [] :
778                 AppModules.split(',');
779         }
780         
781         
782         
783         // ignore registration of objects which are disabled.
784         // global supplied by master.html
785         appDisabled = typeof(appDisabled) == 'undefined' ? [] : appDisabled;
786         
787         
788         /// design flaw
789         // previously we did not a good naming policy for module and parts
790         // most things that are called module here, really are 'parts'
791         // new versions should have 'part' as [ module : part ]
792          if (typeof(obj.part) != 'undefined')  {
793            
794             var permname = obj.part.join('.');
795                 // we now have permission...
796                 // obj.moduleOwner '.' lname
797            
798            
799             if (appDisabled.indexOf(permname) > -1)  {
800                 Roo.log(permname + " is Disabled for this site");
801                 obj.disabled = true;
802                 return;
803             }
804             
805             
806         }
807         
808        
809         
810         if ( obj.isTop) {
811             // false parent... use it..
812             return;
813         }
814         
815         
816         if (obj.parent === Pman || obj.parent  == 'Pman') {
817             // Roo.log("PARENT OF : " + obj.name + " replacing with fake");
818             obj.parent = Pman.fakeRoot;
819         }
820         
821         if (typeof(obj.parent) == 'undefined') {
822             Roo.log("Parent is undefined");
823             Roo.log(obj);
824             obj.disabled = true;
825             return;
826         }
827             
828             
829         if (obj.parent === false) {
830             obj.disabled = true;
831             Roo.log('ignoring top level object (as parent===false found)');
832             Roo.log(obj);
833             return;
834         }
835         // this is an error condition - the parent does not exist..
836             // technically it should not happen..
837           
838         // hack for Pman parent == Pman..
839         if (obj.parent == obj.module) {
840             obj.parent = false;
841             
842         }
843        
844         
845     },
846     /**
847      * fired before building on each compoenent
848      * used to apply permissions.
849      */
850     
851     xbeforebuild : function(obj)
852     {
853         if (typeof(obj.part) != 'undefined')  {
854            
855             if (!obj.part[1].length) {
856                 obj.part[1] = obj.part[0];
857             }
858             var permname = obj.part.join('.');
859             
860             Roo.log("CHECKING: "+ permname);
861             
862                 // we now have permission...
863                 // obj.moduleOwner '.' lname
864             
865             if (Pman.hasPermExists(permname) && !Pman.hasPerm(permname,'S')) {
866                 // it's a turned off permission...
867                 Roo.log(permname + " is Disabled for this user");
868                 obj.disabled = true;
869                 return;
870             }
871             
872             if (obj.permname && obj.permname.length && Pman.hasPermExists(obj.permname) && !Pman.hasPerm(obj.permname,'S')) {
873                 // it's a turned off permission...
874                 Roo.log(obj.permname + " is Disabled for this user");
875                 obj.disabled = true;
876                 return;
877             }
878             
879         }
880         
881         
882     },
883     
884     /**
885      * DEPRICATED : use Roo.XComponents now..
886      * 
887      * Pman.register({
888           modKey : '00-admin-xxxx',
889           module : Pman.Tab.projectMgr, << really a components..
890           part : [ 'Admin', 'ProjectManager' ]
891           moduleOwner : 
892           region : 'center',
893           parent : Pman.layout
894         })
895      * 
896      */
897     register : function(obj)
898     {
899         
900         //this.xregister(obj);
901         
902         
903         // old style calls go in here..
904         // we need to convert the object so that it looks a bit like an XCompoenent..
905          
906         obj.render = function()
907         {
908             if (!this.parent) {
909                 Roo.log("Skip module, as parent does not exist");
910                 Roo.log(this);
911                 return;
912             }
913             //if (typeof(mod) == 'function') {
914             //    mod();
915                 
916             if (typeof(this.region) == 'undefined') {
917                 Roo.log("Module does not have region defined, skipping");
918                 Roo.log(this);
919                 return;
920             }
921             if (this.module.disabled) {
922                 Roo.log("Module disabled, should not rendering");
923                 Roo.log(this);
924                 return;
925             }
926              
927             if (!this.parent.layout) {
928                 Roo.log("Module parent does not have property layout.");
929                 Roo.log(this);
930                 return;
931             }
932         
933            // honour DEPRICATED permname setings..
934            // new code should use PART name, and matching permissions.
935             if (this.permname && this.permname.length) {
936                 if (!Pman.hasPerm(this.permname, 'S')) {
937                     return;
938                 }
939                 
940             }
941             this.add(this.parent.layout, this.region);
942             this.el = this.layout;
943             
944             
945               
946         };
947         // map some of the standard properties..
948         obj.order = obj.modKey;
949         
950         // a bit risky...
951         
952         
953         
954         // the other issue we have is that
955          
956         
957         // Roo.log("CALLING XComponent register with : " + obj.name);
958         
959         // this will call xregister as it's the on.register handler..
960         Roo.XComponent.register(obj.isTop ? obj : Roo.apply(obj.module, obj));
961          
962     } ,
963     invertColor : function(c)
964     {
965         // read..
966         var ca = [];
967         for(var i = 0; i < 3; i++){
968             ca[i] = parseInt(c.charAt((i*2)+1) + c.charAt((i*2)+2), 16);
969         }
970             
971         // invert..
972         var col = '';
973         Roo.each(ca, function(hi) {
974             var h = parseInt(255-hi).toString(16);
975             if(h < 16){
976                 h = '0' + h;
977             }
978             col += h;
979         });
980         return '#' + col;
981         
982     }
983     
984     
985     
986     
987     
988     
989     
990 });
991