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