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={};}
12 Roo.XComponent.on('register', function(e) {
13 if (typeof(Pman) != 'undefined') { return Pman.xregister(e); } return true;
15 Roo.XComponent.on('beforebuild', function(e) {
16 if (typeof(Pman) != 'undefined') { return Pman.xbeforebuild(e); } return true;
19 Roo.XComponent.on('buildcomplete',
21 Pman.building = false;
22 Pman.layout.getRegion('center').showPanel(0);
23 Pman.layout.endUpdate();
26 Pman.fireEvent('load',this);
28 if (!Pman.layout.getRegion('south').panels.length) {
29 Pman.layout.getRegion('south').hide();
39 Pman = new Roo.Document(
41 /// appVersion: '1.7', // fixme = needs to be removed - use Global AppVersion
44 rightNames: { }, /// register right names here - so they can be translated and rendered.
46 * @property {Roo.menu.Menu} pulldownMenu - the 'add menu pulldown, you can use it to add items..
52 buildCompleted : false, // flag to say if we are building interface..
54 'beforeload' : true, // fired after page ready, before module building.
55 'load' : true, // fired after module building
56 'authrefreshed' : true // fire on auth updated?? - should be on Login?!?!?
62 // kludge to fix firebug debugger
63 if (typeof(console) == 'undefined') {
64 console = { log : function() { } };
68 if (Roo.get('loading')) {
69 Roo.get('loading').remove();
72 Roo.state.Manager.setProvider(new Roo.state.CookieProvider());
76 if (AppLinkError.length) {
77 Roo.MessageBox.alert("Error", AppLinkError, function() {
85 if (showNewPass.length) {
86 Pman.PasswordChange.show( { passwordReset : showNewPass },
88 // fail and success we do a load...
100 if (Roo.get('loading-logo-tile')) {
101 Roo.get('loading-logo-tile').remove();
103 if (Roo.get('loading-logo-tile-top')) {
104 Roo.get('loading-logo-tile-top').remove();
106 if (Roo.get('loading-logo-bottom')) {
107 Roo.get('loading-logo-bottom').remove();
109 if (Roo.get('loading-logo-center')) {
110 Roo.get('loading-logo-center').remove();
116 fakeRoot : new Roo.XComponent( {
125 render : function (el) { this.el = this.layout; }
131 //this.fireEvent('beforeload',this);
136 return; // already loaded
138 if (Roo.get('loading')) {
139 Roo.get('loading').remove();
141 if (Roo.get('loading-mask')) {
142 Roo.get('loading-mask').show();
147 this.stime = new Date();
148 this.layout = new Roo.BorderLayout(document.body, {
162 alwaysShowTabs: true,
174 this.fakeRoot.layout = this.layout;
176 Pman.register( Roo.apply(this.fakeRoot, {
183 // creates all the modules ready to load..
185 this.fireEvent('beforeload',this);
189 this.layout.beginUpdate();
190 this.layout.add('north', new Roo.ContentPanel('title', 'North'));
191 var au = Pman.Login.authUser;
192 if (au.id > 0 && au.company_id_background_color && au.company_id_background_color.length) {
193 Roo.get('title').dom.style.backgroundColor = '#' + au.company_id_background_color;
194 Roo.get('headerInformation').dom.style.color = this.invertColor('#' + au.company_id_background_color);
196 if (au.id > 0 && au.company_id_logo_id * 1 > 0) {
197 Roo.get('headerInformation-company-logo').dom.src = baseURL +
198 '/Images/' + au.company_id_logo_id + '/' + au.company_id_logo_id_filename;
200 Roo.get('headerInformation-company-logo').dom.src = Roo.BLANK_IMAGE_URL;
203 Roo.get('headerInformation').dom.innerHTML = String.format(
204 "You are Logged in as <b>{0} ({1})</b>", // to {4} v{3}", // for <b>{2}</b>",
205 au.name, au.email, au.company_id_name,
206 AppVersion , appNameShort
210 document.title = appName + ' v' + AppVersion + ' - ' + au.company_id_name;
211 Roo.QuickTips.init();
216 //this.mainLayout.beginUpdate();
217 //var maskDom = Roo.get(document.body)._maskMsg.dom
218 this.layout.beginUpdate();
220 Pman.building = true;
221 Roo.XComponent.build();
228 addTopToolbar : function()
230 //console.log( "t6:" + ((new Date())-stime));
231 //this.mainLayout.endUpdate();
232 // make a new tab to hold administration stuff...
235 //console.log( "t7:" + ((new Date())-stime));
236 if (!Pman.layout.getRegion('center').tabs) {
237 Roo.log("Error could not find tabs? - not adding toolbar?");
241 var se = Pman.layout.getRegion('center').tabs.stripEl;
242 var tbh = se.createChild(
243 { tag: 'td', style: 'width:100%;' });
245 var lotb = new Roo.Toolbar(tbh);
248 var tbl = se.child('table', true);
249 tbl.setAttribute('width', '100%');
252 if (Pman.hasPerm('Core.ChangePassword','S')) {
255 new Roo.Toolbar.Fill(),
258 text: "Change Password",
259 cls: 'x-btn-text-icon',
260 icon: rootURL + '/Pman/templates/images/change-password.gif',
261 handler : function(){
262 Pman.PasswordChange.show({});
268 if (this.topMenuItems.length) {
270 Roo.each(this.topMenuItems, function (mi) {
278 if (this.subMenuItems.length) {
280 this.subMenuItems.sort(function (a,b) {
281 return a.seqid > b.seqid ? 1 : -1;
283 // chop off last seperator.
284 // since we always add it.. just chop of last item
285 this.subMenuItems.pop();
287 var btn = new Roo.Toolbar.Button(
289 text: "Add New Item",
290 cls: 'x-btn-text-icon',
291 icon: Roo.rootURL + 'images/default/dd/drop-add.gif',
293 items : this.subMenuItems
297 this.pulldownMenu = btn.menu;
305 cls: 'x-btn-text-icon',
306 icon: rootURL + '/Pman/templates/images/logout.gif',
307 handler: function() {
314 // this.layout.endUpdate();
318 finalize : function() {
322 window.onbeforeunload = function(e) {
323 e = e || window.event;
324 var r = "Closing this window will loose changes, are you sure you want to do that?";
326 // For IE and Firefox
336 Roo.MessageBox.hide();
337 if (Roo.get('loading-mask')) {
338 Roo.get('loading-mask').remove();
342 this.buildCompleted = true; // now we can force refreshes on everything..
345 // does the URL indicate we want to see a system..
346 if (AppTrackOnLoad * 1 > 0) {
347 this.onLoadTrack(AppTrackOnLoad,false);
352 var forceAdmin = function(data)
354 if (!data || !data.id) {
355 //Roo.log("Force Admin");
356 Pman.Dialog.PersonStaff.show(
359 company_id : Pman.Login.authUser.company_id_id * 1,
360 company_id_name : Pman.Login.authUser.company_id_name
367 Roo.state.Manager.set('Pman.Login.username', data.email),
368 window.onbeforeunload = false;
369 document.location = baseURL + '?ts=' + Math.random();
372 var forceCompany = function(data) {
373 if (Pman.Login.authUser.company_id * 1 > 0) {
377 if (!data || !data.id) {
378 Pman.Dialog.CoreCompanies.show( { id : 0, comptype: 'OWNER' }, function(data) {
379 Roo.log("company dialog returned");
385 Pman.Login.authUser.company_id_id = data.id;
386 Pman.Login.authUser.company_id = data.id;
387 Pman.Login.authUser.company_id_name = data.name;
388 Roo.log("forcing admin");
392 if (Pman.Login.authUser.id < 0) {
393 // admin company has been created - create the user..
394 if (Pman.Login.authUser.company_id_id* 1 > 0) {
412 onLoadTrack : function(id,cb) {
413 this.onLoadTrackCall(id, cb, 'DocumentsCirc_');
415 onLoadTrackEdit : function(id,cb) {
416 this.onLoadTrackCall(id, cb, 'Documents_');
420 /// ----------- FIXME -----
423 onLoadTrackCall : function(id,cb, cls) {
424 Roo.get(document.body).mask("Loading Document details");
427 url: baseURL + '/Roo/Documents.html',
432 success : function(res) {
434 Roo.get(document.body).unmask();
437 switch(data.in_out) {
438 case 'IN' : cls+='In';break;
439 case 'OUT' : cls+='Out';break;
440 case 'WIP' : cls+='Wip';break;
442 Roo.MessageBox.alert("Error", "invalid in_out");
445 Pman.Dialog[cls].show(data, cb ? cb : Pman.refreshActivePanel);
448 failure: function() {
449 Roo.get(document.body).unmask();
459 refreshActivePanel : function() {
460 var actpan = this.layout.getRegion('center').getActivePanel();
461 if (actpan.controller && actpan.controller.paging) {
462 actpan.controller.paging.onClick('refresh');
466 var agid = Pman.layout.getRegion('center').getActivePanel().id;
470 Pman.Tab[agid].paging.onClick('refresh');
472 toCidV : function(data) {
473 return 'C' + data.in_out.substring(0,1) + data.cid;
479 * Does the authenticated user have permission to see this.
481 * @param {String} name the [Module].[permission] to check for
482 * @param {Char} lvl - which type of permission to use (eg. S=show...)
483 * @returns {Boolean} tue indicates permission allowed
485 hasPerm: function(name, lvl) {
487 (typeof(Pman.Login.authUser) != 'object')
489 (typeof(Pman.Login.authUser.perms) != 'object')
491 (typeof(Pman.Login.authUser.perms[name]) != 'string')
496 return Pman.Login.authUser.perms[name].indexOf(lvl) > -1;
501 * Is there a permission defined for this (used by module registration.)
503 * @param {String} name the [Module].[permission] to check for
504 * @returns {Boolean} tue indicates permission exists.
506 hasPermExists: function(name) {
508 (typeof(Pman.Login.authUser) != 'object')
510 (typeof(Pman.Login.authUser.perms) != 'object')
512 (typeof(Pman.Login.authUser.perms[name]) != 'string')
530 processResponse : function (response)
534 res = Roo.decode(response.responseText);
536 if (typeof(res) != 'object') {
537 res = { success : false, errorMsg : res, errors : true };
539 if (typeof(res.success) == 'undefined') {
544 res = { success : false, errorMsg : response.responseText, errors : true };
548 genericDelete : function(tab,tbl) {
553 var s = tab.grid.getSelectionModel().getSelections();
555 Roo.MessageBox.alert("Error", "Select at least one Row to delete" );
558 var reader = tab.grid.reader || tab.grid.ds.reader;
559 for(var i = 0; i < s.length; i++) {
560 r.push(reader.getId(s[i].json));
563 Roo.MessageBox.confirm("Confirm", "Are you sure you want to delete that?",
568 // what about the toolbar??
569 tab.grid.getView().mainWrap.mask("Deleting");
571 url: baseURL + '/Roo/'+tbl+'.php',
574 _delete : r.join(',')
576 success: function(response) {
577 tab.grid.getView().mainWrap.unmask();
579 tab.paging.onClick('refresh');
580 } else if (tab.grid.footer && tab.grid.footer.onClick) {
581 // new xtype built grids
582 tab.grid.footer.onClick('refresh');
583 } else if (tab.refresh) {
584 tab.refresh(); // this might cause problems as panels have a refresh method?
586 tab.grid.getDataSource().load();
592 failure: function(act) {
598 msg = "Error deleting";
600 tab.grid.getView().mainWrap.unmask();
601 Roo.MessageBox.alert("Error", msg);
612 standardActionFailed : function(f, act, cb) {
614 if (act.failureType == 'client') {
615 Roo.MessageBox.alert("Error", "Please Correct all the errors in red", cb);
618 if (act.failureType == 'connect') {
619 Roo.MessageBox.alert("Error", "Problem Connecting to Server - please try again.", cb);
623 if (act.type == 'submit') {
625 Roo.MessageBox.alert("Error", typeof(act.result.errorMsg) == 'string' ?
626 String.format('{0}', act.result.errorMsg) :
627 "Saving failed = fix errors and try again", cb);
631 // what about load failing..
632 Roo.MessageBox.alert("Error", "Error loading details",cb);
635 * Depreciated - USE new Pman.Request
636 * We need to replace all the uses with this, however the api is slightly different,
637 * the success argument is res.data, not res..
640 request : function(c) {
641 return new Pman.Request(c);
646 // depreciated - use Pman.Download()
648 download : function(c) {
650 return new Pman.Download(c);
653 // fixme - move to document manager...
654 downloadRevision : function(doc, rev)
657 url: baseURL + '/Documents/Doc/DownloadRev/'+ doc.id + '/' + rev + '/' +
658 doc.project_id_code + '-' + doc.cidV + '-' + rev + '-' + doc.filename
664 exportCSV : function(c) {
666 for(var i=0;i < c.csvFormat.length;i++) {
667 c.params['csvCols['+i+']'] = c.csvFormat[i][0];
668 c.params['csvTitles['+i+']'] = c.csvFormat[i][1];
670 c.url += '?' + Roo.urlEncode(c.params);
676 prettyDate : function (value)
678 if (typeof(value) == 'string') {
679 var ds = Date.parseDate(value, 'Y-m-d H:i:s');
681 return this.prettyDate(ds);
683 ds = Date.parseDate(value, 'Y-m-d');
685 return this.prettyDate(ds);
694 var daysSince = Math.floor(td.getElapsed(value) / (1000 * 60*60*24));
696 return value.dateFormat('D H:i');
700 if (td.dateFormat('m') == value.dateFormat('m')) {
701 return value.dateFormat('dS D');
704 if (td.dateFormat('Y') == value.dateFormat('Y')) {
705 return value.dateFormat('dS M');
707 return value.dateFormat('d M Y');
709 loadException : function(a,b,c,d)
711 if (d && d.authFailure) {
715 Roo.MessageBox.alert("Problem Loading Data", a.message || c.statusText);
721 * Routine to flash alerts in the title bar..
726 notifyActive : false,
728 notifyTitle: function(msg)
730 if (this.notifyActive ) {
735 var stopper = function() {
737 document.title = oldtitle;
740 Roo.get(document.body).on('mousemove', stopper, this);
741 var oldtitle = document.title;
744 var ivl = window.setInterval(function() {
747 Roo.get(document.body).un('mousemove', stopper, this);
748 _this.notifyActive = false;
749 document.title = oldtitle;
750 window.clearInterval(ivl);
754 document.title = s ? msg : oldtitle;
756 }, 1000); // every 120 secs = 2mins..
757 document.title = msg;
763 * @property {Array} appModules - array based on AppModules global
770 xregister : function(obj)
774 if (!Pman.appModules === false) {
775 Pman.appModules = typeof(AppModules ) == 'undefined'? [] :
776 AppModules.split(',');
781 // ignore registration of objects which are disabled.
782 // global supplied by master.html
783 appDisabled = typeof(appDisabled) == 'undefined' ? [] : appDisabled;
787 // previously we did not a good naming policy for module and parts
788 // most things that are called module here, really are 'parts'
789 // new versions should have 'part' as [ module : part ]
790 if (typeof(obj.part) != 'undefined') {
792 var permname = obj.part.join('.');
793 // we now have permission...
794 // obj.moduleOwner '.' lname
797 if (appDisabled.indexOf(permname) > -1) {
798 Roo.log(permname + " is Disabled for this site");
809 // false parent... use it..
814 if (obj.parent === Pman || obj.parent == 'Pman') {
815 // Roo.log("PARENT OF : " + obj.name + " replacing with fake");
816 obj.parent = Pman.fakeRoot;
819 if (typeof(obj.parent) == 'undefined') {
820 Roo.log("Parent is undefined");
827 if (obj.parent === false) {
829 Roo.log('ignoring top level object (as parent===false found)');
833 // this is an error condition - the parent does not exist..
834 // technically it should not happen..
836 // hack for Pman parent == Pman..
837 if (obj.parent == obj.module) {
845 * fired before building on each compoenent
846 * used to apply permissions.
849 xbeforebuild : function(obj)
851 if (typeof(obj.part) != 'undefined') {
853 if (!obj.part[1].length) {
854 obj.part[1] = obj.part[0];
856 var permname = obj.part.join('.');
858 Roo.log("CHECKING: "+ permname);
860 // we now have permission...
861 // obj.moduleOwner '.' lname
863 if (Pman.hasPermExists(permname) && !Pman.hasPerm(permname,'S')) {
864 // it's a turned off permission...
865 Roo.log(permname + " is Disabled for this user");
878 * DEPRICATED : use Roo.XComponents now..
881 modKey : '00-admin-xxxx',
882 module : Pman.Tab.projectMgr, << really a components..
883 part : [ 'Admin', 'ProjectManager' ]
890 register : function(obj)
893 //this.xregister(obj);
896 // old style calls go in here..
897 // we need to convert the object so that it looks a bit like an XCompoenent..
899 obj.render = function()
902 Roo.log("Skip module, as parent does not exist");
906 //if (typeof(mod) == 'function') {
909 if (typeof(this.region) == 'undefined') {
910 Roo.log("Module does not have region defined, skipping");
914 if (this.module.disabled) {
915 Roo.log("Module disabled, should not rendering")
920 if (!this.parent.layout) {
921 Roo.log("Module parent does not have property layout.")
926 // honour DEPRICATED permname setings..
927 // new code should use PART name, and matching permissions.
928 if (this.permname && this.permname.length) {
929 if (!Pman.hasPerm(this.permname, 'S')) {
934 this.add(this.parent.layout, this.region);
935 this.el = this.layout;
940 // map some of the standard properties..
941 obj.order = obj.modKey;
947 // the other issue we have is that
950 // Roo.log("CALLING XComponent register with : " + obj.name);
952 // this will call xregister as it's the on.register handler..
953 Roo.XComponent.register(obj.isTop ? obj : Roo.apply(obj.module, obj));
956 invertColor : function(c)
960 for(var i = 0; i < 3; i++){
961 ca[i] = parseInt(c.charAt((i*2)+1) + c.charAt((i*2)+2), 16);
966 Roo.each(ca, function(hi) {
967 var h = parseInt(255-hi).toString(16);