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_id * 1,
362 company_id_name : Pman.Login.authUser.company_id_name
369 Roo.state.Manager.set('Pman.Login.username', data.email),
370 window.onbeforeunload = false;
371 document.location = baseURL + '?ts=' + Math.random();
374 var forceCompany = function(data) {
375 if (Pman.Login.authUser.company_id * 1 > 0) {
379 if (!data || !data.id) {
380 Pman.Dialog.CoreCompanies.show( { id : 0, comptype: 'OWNER' }, function(data) {
381 Roo.log("company dialog returned");
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");
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) {
414 onLoadTrack : function(id,cb) {
415 this.onLoadTrackCall(id, cb, 'DocumentsCirc_');
417 onLoadTrackEdit : function(id,cb) {
418 this.onLoadTrackCall(id, cb, 'Documents_');
422 /// ----------- FIXME -----
425 onLoadTrackCall : function(id,cb, cls) {
426 Roo.get(document.body).mask("Loading Document details");
429 url: baseURL + '/Roo/Documents.html',
434 success : function(res) {
436 Roo.get(document.body).unmask();
439 switch(data.in_out) {
440 case 'IN' : cls+='In';break;
441 case 'OUT' : cls+='Out';break;
442 case 'WIP' : cls+='Wip';break;
444 Roo.MessageBox.alert("Error", "invalid in_out");
447 Pman.Dialog[cls].show(data, cb ? cb : Pman.refreshActivePanel);
450 failure: function() {
451 Roo.get(document.body).unmask();
461 refreshActivePanel : function() {
462 var actpan = this.layout.getRegion('center').getActivePanel();
463 if (actpan.controller && actpan.controller.paging) {
464 actpan.controller.paging.onClick('refresh');
468 var agid = Pman.layout.getRegion('center').getActivePanel().id;
472 Pman.Tab[agid].paging.onClick('refresh');
474 toCidV : function(data) {
475 return 'C' + data.in_out.substring(0,1) + data.cid;
481 * Does the authenticated user have permission to see this.
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
487 hasPerm: function(name, lvl) {
489 (typeof(Pman.Login.authUser) != 'object')
491 (typeof(Pman.Login.authUser.perms) != 'object')
493 (typeof(Pman.Login.authUser.perms[name]) != 'string')
498 return Pman.Login.authUser.perms[name].indexOf(lvl) > -1;
503 * Is there a permission defined for this (used by module registration.)
505 * @param {String} name the [Module].[permission] to check for
506 * @returns {Boolean} tue indicates permission exists.
508 hasPermExists: function(name) {
510 (typeof(Pman.Login.authUser) != 'object')
512 (typeof(Pman.Login.authUser.perms) != 'object')
514 (typeof(Pman.Login.authUser.perms[name]) != 'string')
532 processResponse : function (response)
536 res = Roo.decode(response.responseText);
538 if (typeof(res) != 'object') {
539 res = { success : false, errorMsg : res, errors : true };
541 if (typeof(res.success) == 'undefined') {
546 res = { success : false, errorMsg : response.responseText, errors : true };
550 genericDelete : function(tab,tbl) {
555 var s = tab.grid.getSelectionModel().getSelections();
557 Roo.MessageBox.alert("Error", "Select at least one Row to delete" );
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));
565 Roo.MessageBox.confirm("Confirm", "Are you sure you want to delete that?",
570 // what about the toolbar??
571 tab.grid.getView().mainWrap.mask("Deleting");
573 url: baseURL + '/Roo/'+tbl+'.php',
576 _delete : r.join(',')
578 success: function(response) {
579 tab.grid.getView().mainWrap.unmask();
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?
588 tab.grid.getDataSource().load();
594 failure: function(act) {
600 msg = "Error deleting";
602 tab.grid.getView().mainWrap.unmask();
603 Roo.MessageBox.alert("Error", msg);
614 standardActionFailed : function(f, act, cb) {
616 if (act.failureType == 'client') {
617 Roo.MessageBox.alert("Error", "Please Correct all the errors in red", cb);
620 if (act.failureType == 'connect') {
621 Roo.MessageBox.alert("Error", "Problem Connecting to Server - please try again.", cb);
625 if (act.type == 'submit') {
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);
633 // what about load failing..
634 Roo.MessageBox.alert("Error", "Error loading details",cb);
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..
642 request : function(c) {
643 return new Pman.Request(c);
648 // depreciated - use Pman.Download()
650 download : function(c) {
652 return new Pman.Download(c);
655 // fixme - move to document manager...
656 downloadRevision : function(doc, rev)
659 url: baseURL + '/Documents/Doc/DownloadRev/'+ doc.id + '/' + rev + '/' +
660 doc.project_id_code + '-' + doc.cidV + '-' + rev + '-' + doc.filename
666 exportCSV : function(c) {
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];
672 c.url += '?' + Roo.urlEncode(c.params);
678 prettyDate : function (value)
680 if (typeof(value) == 'string') {
681 var ds = Date.parseDate(value, 'Y-m-d H:i:s');
683 return this.prettyDate(ds);
685 ds = Date.parseDate(value, 'Y-m-d');
687 return this.prettyDate(ds);
696 var daysSince = Math.floor(td.getElapsed(value) / (1000 * 60*60*24));
698 return value.dateFormat('D H:i');
702 if (td.dateFormat('m') == value.dateFormat('m')) {
703 return value.dateFormat('dS D');
706 if (td.dateFormat('Y') == value.dateFormat('Y')) {
707 return value.dateFormat('dS M');
709 return value.dateFormat('d M Y');
711 loadException : function(a,b,c,d)
713 if (d && d.authFailure) {
717 Roo.MessageBox.alert("Problem Loading Data", a.message || c.statusText);
723 * Routine to flash alerts in the title bar..
728 notifyActive : false,
730 notifyTitle: function(msg)
732 if (this.notifyActive ) {
737 var stopper = function() {
739 document.title = oldtitle;
742 Roo.get(document.body).on('mousemove', stopper, this);
743 var oldtitle = document.title;
746 var ivl = window.setInterval(function() {
749 Roo.get(document.body).un('mousemove', stopper, this);
750 _this.notifyActive = false;
751 document.title = oldtitle;
752 window.clearInterval(ivl);
756 document.title = s ? msg : oldtitle;
758 }, 1000); // every 120 secs = 2mins..
759 document.title = msg;
765 * @property {Array} appModules - array based on AppModules global
772 xregister : function(obj)
776 if (!Pman.appModules === false) {
777 Pman.appModules = typeof(AppModules ) == 'undefined'? [] :
778 AppModules.split(',');
783 // ignore registration of objects which are disabled.
784 // global supplied by master.html
785 appDisabled = typeof(appDisabled) == 'undefined' ? [] : appDisabled;
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') {
794 var permname = obj.part.join('.');
795 // we now have permission...
796 // obj.moduleOwner '.' lname
799 if (appDisabled.indexOf(permname) > -1) {
800 Roo.log(permname + " is Disabled for this site");
811 // false parent... use it..
816 if (obj.parent === Pman || obj.parent == 'Pman') {
817 // Roo.log("PARENT OF : " + obj.name + " replacing with fake");
818 obj.parent = Pman.fakeRoot;
821 if (typeof(obj.parent) == 'undefined') {
822 Roo.log("Parent is undefined");
829 if (obj.parent === false) {
831 Roo.log('ignoring top level object (as parent===false found)');
835 // this is an error condition - the parent does not exist..
836 // technically it should not happen..
838 // hack for Pman parent == Pman..
839 if (obj.parent == obj.module) {
847 * fired before building on each compoenent
848 * used to apply permissions.
851 xbeforebuild : function(obj)
853 if (typeof(obj.part) != 'undefined') {
855 if (!obj.part[1].length) {
856 obj.part[1] = obj.part[0];
858 var permname = obj.part.join('.');
860 Roo.log("CHECKING: "+ permname);
862 // we now have permission...
863 // obj.moduleOwner '.' lname
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");
880 * DEPRICATED : use Roo.XComponents now..
883 modKey : '00-admin-xxxx',
884 module : Pman.Tab.projectMgr, << really a components..
885 part : [ 'Admin', 'ProjectManager' ]
892 register : function(obj)
895 //this.xregister(obj);
898 // old style calls go in here..
899 // we need to convert the object so that it looks a bit like an XCompoenent..
901 obj.render = function()
904 Roo.log("Skip module, as parent does not exist");
908 //if (typeof(mod) == 'function') {
911 if (typeof(this.region) == 'undefined') {
912 Roo.log("Module does not have region defined, skipping");
916 if (this.module.disabled) {
917 Roo.log("Module disabled, should not rendering");
922 if (!this.parent.layout) {
923 Roo.log("Module parent does not have property layout.");
928 // honour DEPRICATED permname setings..
929 // new code should use PART name, and matching permissions.
930 if (this.permname && this.permname.length) {
931 if (!Pman.hasPerm(this.permname, 'S')) {
936 this.add(this.parent.layout, this.region);
937 this.el = this.layout;
942 // map some of the standard properties..
943 obj.order = obj.modKey;
949 // the other issue we have is that
952 // Roo.log("CALLING XComponent register with : " + obj.name);
954 // this will call xregister as it's the on.register handler..
955 Roo.XComponent.register(obj.isTop ? obj : Roo.apply(obj.module, obj));
958 invertColor : function(c)
962 for(var i = 0; i < 3; i++){
963 ca[i] = parseInt(c.charAt((i*2)+1) + c.charAt((i*2)+2), 16);
968 Roo.each(ca, function(hi) {
969 var h = parseInt(255-hi).toString(16);