5 * This is the main Pman class
6 * - it's a bit too heavy at present - needs to go on a diet....
10 if (typeof(_T) == 'undefined') { _T={};}
14 Roo.XComponent.on('register', function(e) {
15 if (typeof(Pman) != 'undefined') { return Pman.xregister(e); } return true;
17 Roo.XComponent.on('beforebuild', function(e) {
18 if (typeof(Pman) != 'undefined') { return Pman.xbeforebuild(e); } return true;
21 Roo.XComponent.on('buildcomplete',
23 Pman.building = false;
24 Pman.layout.getRegion('center').showPanel(0);
25 Pman.layout.endUpdate();
28 Pman.fireEvent('load',this);
30 if (!Pman.layout.getRegion('south').panels.length) {
31 Pman.layout.getRegion('south').hide();
41 Pman = new Roo.Document(
43 /// appVersion: '1.7', // fixme = needs to be removed - use Global AppVersion
46 rightNames: { }, /// register right names here - so they can be translated and rendered.
48 * @property {Roo.menu.Menu} pulldownMenu - the 'add menu pulldown, you can use it to add items..
54 buildCompleted : false, // flag to say if we are building interface..
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?!?!?
64 // kludge to fix firebug debugger
65 if (typeof(console) == 'undefined') {
66 console = { log : function() { } };
70 if (Roo.get('loading')) {
71 Roo.get('loading').remove();
74 Roo.state.Manager.setProvider(new Roo.state.CookieProvider());
78 if (AppLinkError.length) {
79 Roo.MessageBox.alert("Error", AppLinkError, function() {
87 if (showNewPass.length) {
88 Pman.PasswordChange.show( { passwordReset : showNewPass },
90 // fail and success we do a load...
102 if (Roo.get('loading-logo-tile')) {
103 Roo.get('loading-logo-tile').remove();
105 if (Roo.get('loading-logo-tile-top')) {
106 Roo.get('loading-logo-tile-top').remove();
108 if (Roo.get('loading-logo-bottom')) {
109 Roo.get('loading-logo-bottom').remove();
111 if (Roo.get('loading-logo-center')) {
112 Roo.get('loading-logo-center').remove();
118 fakeRoot : new Roo.XComponent( {
127 render : function (el) { this.el = this.layout; }
133 //this.fireEvent('beforeload',this);
138 return; // already loaded
140 if (Roo.get('loading')) {
141 Roo.get('loading').remove();
143 if (Roo.get('loading-mask')) {
144 Roo.get('loading-mask').show();
149 this.stime = new Date();
150 this.layout = new Roo.BorderLayout(document.body, {
164 alwaysShowTabs: true,
176 this.fakeRoot.layout = this.layout;
178 Pman.register( Roo.apply(this.fakeRoot, {
185 // creates all the modules ready to load..
187 this.fireEvent('beforeload',this);
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);
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;
202 Roo.get('headerInformation-company-logo').dom.src = Roo.BLANK_IMAGE_URL;
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
212 document.title = appName + ' v' + AppVersion + ' - ' + au.company_id_name;
213 Roo.QuickTips.init();
218 //this.mainLayout.beginUpdate();
219 //var maskDom = Roo.get(document.body)._maskMsg.dom
220 this.layout.beginUpdate();
222 Pman.building = true;
223 Roo.XComponent.build();
230 addTopToolbar : function()
232 //console.log( "t6:" + ((new Date())-stime));
233 //this.mainLayout.endUpdate();
234 // make a new tab to hold administration stuff...
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?");
243 var se = Pman.layout.getRegion('center').tabs.stripEl;
244 var tbh = se.createChild(
245 { tag: 'td', style: 'width:100%;' });
247 var lotb = new Roo.Toolbar(tbh);
250 var tbl = se.child('table', true);
251 tbl.setAttribute('width', '100%');
254 if (Pman.hasPerm('Core.ChangePassword','S')) {
257 new Roo.Toolbar.Fill(),
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({});
270 if (this.topMenuItems.length) {
272 Roo.each(this.topMenuItems, function (mi) {
280 if (this.subMenuItems.length) {
282 this.subMenuItems.sort(function (a,b) {
283 return a.seqid > b.seqid ? 1 : -1;
285 // chop off last seperator.
286 // since we always add it.. just chop of last item
287 this.subMenuItems.pop();
289 var btn = new Roo.Toolbar.Button(
291 text: "Add New Item",
292 cls: 'x-btn-text-icon',
293 icon: Roo.rootURL + 'images/default/dd/drop-add.gif',
295 items : this.subMenuItems
299 this.pulldownMenu = btn.menu;
307 cls: 'x-btn-text-icon',
308 icon: rootURL + '/Pman/templates/images/logout.gif',
309 handler: function() {
316 // this.layout.endUpdate();
320 finalize : function() {
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?";
328 // For IE and Firefox
338 Roo.MessageBox.hide();
339 if (Roo.get('loading-mask')) {
340 Roo.get('loading-mask').remove();
344 this.buildCompleted = true; // now we can force refreshes on everything..
347 // does the URL indicate we want to see a system..
348 if (AppTrackOnLoad * 1 > 0) {
349 this.onLoadTrack(AppTrackOnLoad,false);
354 var forceAdmin = function(data)
356 if (!data || !data.id) {
357 //Roo.log("Force Admin");
358 Pman.Dialog.PersonStaff.show(
361 company_id : Pman.Login.authUser.company_id * 1,
362 company_id_name : Pman.Login.authUser.company_id_name
370 Roo.state.Manager.set('Pman.Login.username', data.email),
371 window.onbeforeunload = false;
372 document.location = baseURL + '?ts=' + Math.random();
375 var forceCompany = function(data) {
376 if (Pman.Login.authUser.company_id * 1 > 0) {
380 if (!data || !data.id) {
381 Pman.Dialog.CoreCompanies.show( { id : 0, comptype: 'OWNER' }, function(data) {
382 Roo.log("company dialog returned");
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");
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) {
415 onLoadTrack : function(id,cb) {
416 this.onLoadTrackCall(id, cb, 'DocumentsCirc_');
418 onLoadTrackEdit : function(id,cb) {
419 this.onLoadTrackCall(id, cb, 'Documents_');
423 /// ----------- FIXME -----
426 onLoadTrackCall : function(id,cb, cls) {
427 Roo.get(document.body).mask("Loading Document details");
430 url: baseURL + '/Roo/Documents.html',
435 success : function(res) {
437 Roo.get(document.body).unmask();
440 switch(data.in_out) {
441 case 'IN' : cls+='In';break;
442 case 'OUT' : cls+='Out';break;
443 case 'WIP' : cls+='Wip';break;
445 Roo.MessageBox.alert("Error", "invalid in_out");
448 Pman.Dialog[cls].show(data, cb ? cb : Pman.refreshActivePanel);
451 failure: function() {
452 Roo.get(document.body).unmask();
462 refreshActivePanel : function() {
463 var actpan = this.layout.getRegion('center').getActivePanel();
464 if (actpan.controller && actpan.controller.paging) {
465 actpan.controller.paging.onClick('refresh');
469 var agid = Pman.layout.getRegion('center').getActivePanel().id;
473 Pman.Tab[agid].paging.onClick('refresh');
475 toCidV : function(data) {
476 return 'C' + data.in_out.substring(0,1) + data.cid;
482 * Does the authenticated user have permission to see this.
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
488 hasPerm: function(name, lvl) {
490 (typeof(Pman.Login.authUser) != 'object')
492 (typeof(Pman.Login.authUser.perms) != 'object')
494 (typeof(Pman.Login.authUser.perms[name]) != 'string')
499 return Pman.Login.authUser.perms[name].indexOf(lvl) > -1;
504 * Is there a permission defined for this (used by module registration.)
506 * @param {String} name the [Module].[permission] to check for
507 * @returns {Boolean} tue indicates permission exists.
509 hasPermExists: function(name) {
511 (typeof(Pman.Login.authUser) != 'object')
513 (typeof(Pman.Login.authUser.perms) != 'object')
515 (typeof(Pman.Login.authUser.perms[name]) != 'string')
533 processResponse : function (response)
537 res = Roo.decode(response.responseText);
539 if (typeof(res) != 'object') {
540 res = { success : false, errorMsg : res, errors : true };
542 if (typeof(res.success) == 'undefined') {
547 res = { success : false, errorMsg : response.responseText, errors : true };
551 genericDelete : function(tab,tbl) {
556 var s = tab.grid.getSelectionModel().getSelections();
558 Roo.MessageBox.alert("Error", "Select at least one Row to delete" );
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));
566 Roo.MessageBox.confirm("Confirm", "Are you sure you want to delete that?",
571 // what about the toolbar??
572 tab.grid.getView().mainWrap.mask("Deleting");
574 url: baseURL + '/Roo/'+tbl+'.php',
577 _delete : r.join(',')
579 success: function(response) {
580 tab.grid.getView().mainWrap.unmask();
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?
589 tab.grid.getDataSource().load();
595 failure: function(act) {
601 msg = "Error deleting";
603 tab.grid.getView().mainWrap.unmask();
604 Roo.MessageBox.alert("Error", msg);
615 standardActionFailed : function(f, act, cb) {
617 if (act.failureType == 'client') {
618 Roo.MessageBox.alert("Error", "Please Correct all the errors in red", cb);
621 if (act.failureType == 'connect') {
622 Roo.MessageBox.alert("Error", "Problem Connecting to Server - please try again.", cb);
626 if (act.type == 'submit') {
628 Roo.MessageBox.alert("Error", typeof(act.result.errorMsg) == 'string' ?
629 String.format('{0}', act.result.errorMsg) :
630 "Saving failed = fix errors and try again", cb);
634 // what about load failing..
635 Roo.MessageBox.alert("Error", "Error loading details",cb);
638 * Depreciated - USE new Pman.Request
639 * We need to replace all the uses with this, however the api is slightly different,
640 * the success argument is res.data, not res..
643 request : function(c) {
644 return new Pman.Request(c);
649 // depreciated - use Pman.Download()
651 download : function(c) {
653 return new Pman.Download(c);
656 // fixme - move to document manager...
657 downloadRevision : function(doc, rev)
660 url: baseURL + '/Documents/Doc/DownloadRev/'+ doc.id + '/' + rev + '/' +
661 doc.project_id_code + '-' + doc.cidV + '-' + rev + '-' + doc.filename
667 exportCSV : function(c) {
669 for(var i=0;i < c.csvFormat.length;i++) {
670 c.params['csvCols['+i+']'] = c.csvFormat[i][0];
671 c.params['csvTitles['+i+']'] = c.csvFormat[i][1];
673 c.url += '?' + Roo.urlEncode(c.params);
679 prettyDate : function (value)
681 if (typeof(value) == 'string') {
682 var ds = Date.parseDate(value, 'Y-m-d H:i:s');
684 return this.prettyDate(ds);
686 ds = Date.parseDate(value, 'Y-m-d');
688 return this.prettyDate(ds);
697 var daysSince = Math.floor(td.getElapsed(value) / (1000 * 60*60*24));
699 return value.dateFormat('D H:i');
703 if (td.dateFormat('m') == value.dateFormat('m')) {
704 return value.dateFormat('dS D');
707 if (td.dateFormat('Y') == value.dateFormat('Y')) {
708 return value.dateFormat('dS M');
710 return value.dateFormat('d M Y');
712 loadException : function(a,b,c,d)
714 if (d && d.authFailure) {
718 Roo.MessageBox.alert("Problem Loading Data", a.message || c.statusText);
724 * Routine to flash alerts in the title bar..
729 notifyActive : false,
731 notifyTitle: function(msg)
733 if (this.notifyActive ) {
738 var stopper = function() {
740 document.title = oldtitle;
743 Roo.get(document.body).on('mousemove', stopper, this);
744 var oldtitle = document.title;
747 var ivl = window.setInterval(function() {
750 Roo.get(document.body).un('mousemove', stopper, this);
751 _this.notifyActive = false;
752 document.title = oldtitle;
753 window.clearInterval(ivl);
757 document.title = s ? msg : oldtitle;
759 }, 1000); // every 120 secs = 2mins..
760 document.title = msg;
766 * @property {Array} appModules - array based on AppModules global
773 xregister : function(obj)
777 if (!Pman.appModules === false) {
778 Pman.appModules = typeof(AppModules ) == 'undefined'? [] :
779 AppModules.split(',');
784 // ignore registration of objects which are disabled.
785 // global supplied by master.html
786 appDisabled = typeof(appDisabled) == 'undefined' ? [] : appDisabled;
790 // previously we did not a good naming policy for module and parts
791 // most things that are called module here, really are 'parts'
792 // new versions should have 'part' as [ module : part ]
793 if (typeof(obj.part) != 'undefined') {
795 var permname = obj.part.join('.');
796 // we now have permission...
797 // obj.moduleOwner '.' lname
800 if (appDisabled.indexOf(permname) > -1) {
801 Roo.log(permname + " is Disabled for this site");
812 // false parent... use it..
817 if (obj.parent === Pman || obj.parent == 'Pman') {
818 // Roo.log("PARENT OF : " + obj.name + " replacing with fake");
819 obj.parent = Pman.fakeRoot;
822 if (typeof(obj.parent) == 'undefined') {
823 Roo.log("Parent is undefined");
830 if (obj.parent === false) {
832 Roo.log('ignoring top level object (as parent===false found)');
836 // this is an error condition - the parent does not exist..
837 // technically it should not happen..
839 // hack for Pman parent == Pman..
840 if (obj.parent == obj.module) {
848 * fired before building on each compoenent
849 * used to apply permissions.
852 xbeforebuild : function(obj)
854 Roo.log('object : ');
857 if (typeof(obj.part) != 'undefined') {
859 if (!obj.part[1].length) {
860 obj.part[1] = obj.part[0];
862 var permname = obj.part.join('.');
864 Roo.log("CHECKING: "+ permname);
866 // we now have permission...
867 // obj.moduleOwner '.' lname
869 if (Pman.hasPermExists(permname) && !Pman.hasPerm(permname,'S')) {
870 // it's a turned off permission...
871 Roo.log(permname + " is Disabled for this user");
876 if (obj.permname && obj.permname.length && Pman.hasPermExists(obj.permname) && !Pman.hasPerm(obj.permname,'S')) {
877 // it's a turned off permission...
878 Roo.log(obj.permname + " is Disabled for this user");
889 * DEPRICATED : use Roo.XComponents now..
892 modKey : '00-admin-xxxx',
893 module : Pman.Tab.projectMgr, << really a components..
894 part : [ 'Admin', 'ProjectManager' ]
901 register : function(obj)
904 //this.xregister(obj);
907 // old style calls go in here..
908 // we need to convert the object so that it looks a bit like an XCompoenent..
910 obj.render = function()
913 Roo.log("Skip module, as parent does not exist");
917 //if (typeof(mod) == 'function') {
920 if (typeof(this.region) == 'undefined') {
921 Roo.log("Module does not have region defined, skipping");
925 if (this.module.disabled) {
926 Roo.log("Module disabled, should not rendering");
931 if (!this.parent.layout) {
932 Roo.log("Module parent does not have property layout.");
937 // honour DEPRICATED permname setings..
938 // new code should use PART name, and matching permissions.
939 if (this.permname && this.permname.length) {
940 if (!Pman.hasPerm(this.permname, 'S')) {
945 this.add(this.parent.layout, this.region);
946 this.el = this.layout;
951 // map some of the standard properties..
952 obj.order = obj.modKey;
958 // the other issue we have is that
961 // Roo.log("CALLING XComponent register with : " + obj.name);
963 // this will call xregister as it's the on.register handler..
964 Roo.XComponent.register(obj.isTop ? obj : Roo.apply(obj.module, obj));
967 invertColor : function(c)
971 for(var i = 0; i < 3; i++){
972 ca[i] = parseInt(c.charAt((i*2)+1) + c.charAt((i*2)+2), 16);
977 Roo.each(ca, function(hi) {
978 var h = parseInt(255-hi).toString(16);