1 //<script type="text/javascript">
5 * >>> Pman.layout.getRegion('center').tabs.stripWrap
7 * var tbh = Pman.layout.getRegion('center').tabs.stripWrap.child('div').createChild(
9 * {tag: 'div', style: 'display:block;position:absolute;top:2;left:300;width:100%;height:25px'});
13 * - gtranslate moved to Pman.GoogleTranslate
18 if (typeof(_T) == 'undefined') { _T={};}
22 Roo.XComponent.on('register', function(e) { return Pman.xregister(e); });
26 Pman = new Roo.Document(
28 /// appVersion: '1.7', // fixme = needs to be removed - use Global AppVersion
31 rightNames: { }, /// register right names here - so they can be translated and rendered.
33 * @property {Roo.menu.Menu} pulldownMenu - the 'add menu pulldown, you can use it to add items..
39 buildCompleted : false, // flag to say if we are building interface..
41 'beforeload' : true, // fired after page ready, before module building.
42 'load' : true, // fired after module building
43 'authrefreshed' : true // fire on auth updated?? - should be on Login?!?!?
49 // kludge to fix firebug debugger
50 if (typeof(console) == 'undefined') {
51 console = { log : function() { } };
55 if (Roo.get('loading')) {
56 Roo.get('loading').remove();
59 Roo.state.Manager.setProvider(new Roo.state.CookieProvider());
63 if (AppLinkError.length) {
64 Roo.MessageBox.alert("Error", AppLinkError, function() {
72 if (showNewPass.length) {
73 Pman.PasswordChange.show( { passwordReset : showNewPass },
75 // fail and success we do a load...
87 if (Roo.get('loading-logo-tile')) {
88 Roo.get('loading-logo-tile').remove();
90 if (Roo.get('loading-logo-tile-top')) {
91 Roo.get('loading-logo-tile-top').remove();
93 if (Roo.get('loading-logo-bottom')) {
94 Roo.get('loading-logo-bottom').remove();
96 if (Roo.get('loading-logo-center')) {
97 Roo.get('loading-logo-center').remove();
117 //this.fireEvent('beforeload',this);
122 return; // already loaded
124 if (Roo.get('loading')) {
125 Roo.get('loading').remove();
127 if (Roo.get('loading-mask')) {
128 Roo.get('loading-mask').show();
133 this.stime = new Date();
134 this.layout = new Roo.BorderLayout(document.body, {
148 alwaysShowTabs: true,
162 Pman.register( Roo.apply(this.fakeRoot, {
168 // creates all the modules ready to load..
170 this.fireEvent('beforeload',this);
174 this.layout.beginUpdate();
175 this.layout.add('north', new Roo.ContentPanel('title', 'North'));
176 var au = Pman.Login.authUser;
177 if (au.id > 0 && au.company_id_background_color && au.company_id_background_color.length) {
178 Roo.get('title').dom.style.backgroundColor = '#' + au.company_id_background_color;
179 Roo.get('headerInformation').dom.style.color = this.invertColor('#' + au.company_id_background_color);
181 if (au.id > 0 && au.company_id_logo_id * 1 > 0) {
182 Roo.get('headerInformation-company-logo').dom.src = baseURL +
183 '/Images/' + au.company_id_logo_id + '/' + au.company_id_logo_id_filename;
185 Roo.get('headerInformation-company-logo').dom.src = Roo.BLANK_IMAGE_URL;
188 Roo.get('headerInformation').dom.innerHTML = String.format(
189 "You are Logged in as <b>{0} ({1})</b>", // to {4} v{3}", // for <b>{2}</b>",
190 au.name, au.email, au.company_id_name,
191 AppVersion , appNameShort
195 document.title = appName + ' v' + AppVersion + ' - ' + au.company_id_name;
196 Roo.QuickTips.init();
201 //this.mainLayout.beginUpdate();
202 //var maskDom = Roo.get(document.body)._maskMsg.dom
203 this.layout.beginUpdate();
205 Pman.building = true;
207 this.buildModules(this,
210 _this.layout.getRegion('center').showPanel(0);
211 _this.layout.endUpdate();
212 _this.addTopToolbar();
214 _this.fireEvent('load',this);
216 if (!_this.layout.getRegion('south').panels.length) {
217 _this.layout.getRegion('south').hide();
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 var se = Pman.layout.getRegion('center').tabs.stripEl;
237 var tbh = se.createChild(
238 { tag: 'td', style: 'width:100%;' });
240 var lotb = new Roo.Toolbar(tbh);
243 var tbl = se.child('table', true);
244 tbl.setAttribute('width', '100%');
247 new Roo.Toolbar.Fill(),
250 text: "Change Password",
251 cls: 'x-btn-text-icon',
252 icon: rootURL + '/Pman/templates/images/change-password.gif',
253 handler : function(){
254 Pman.PasswordChange.show({});
260 if (this.topMenuItems.length) {
262 Roo.each(this.topMenuItems, function (mi) {
270 if (this.subMenuItems.length) {
272 this.subMenuItems.sort(function (a,b) {
273 return a.seqid > b.seqid ? 1 : -1;
275 // chop off last seperator.
276 // since we always add it.. just chop of last item
277 this.subMenuItems.pop();
279 var btn = new Roo.Toolbar.Button(
281 text: "Add New Item",
282 cls: 'x-btn-text-icon',
283 icon: Roo.rootURL + 'images/default/dd/drop-add.gif',
285 items : this.subMenuItems
289 this.pulldownMenu = btn.menu;
297 cls: 'x-btn-text-icon',
298 icon: rootURL + '/Pman/templates/images/logout.gif',
299 handler: function() {
306 // this.layout.endUpdate();
310 finalize : function() {
314 window.onbeforeunload = function(e) {
315 e = e || window.event;
316 var r = "Closing this window will loose changes, are you sure you want to do that?";
318 // For IE and Firefox
328 Roo.MessageBox.hide();
329 if (Roo.get('loading-mask')) {
330 Roo.get('loading-mask').remove();
334 this.buildCompleted = true; // now we can force refreshes on everything..
337 // does the URL indicate we want to see a system..
338 if (AppTrackOnLoad * 1 > 0) {
339 this.onLoadTrack(AppTrackOnLoad,false);
344 var forceAdmin = function(data)
346 if (!data || !data.id) {
347 //Roo.log("Force Admin");
348 Pman.Dialog.PersonStaff.show(
351 company_id : Pman.Login.authUser.company_id_id * 1,
352 company_id_name : Pman.Login.authUser.company_id_name
359 Roo.state.Manager.set('Pman.Login.username', data.email),
360 window.onbeforeunload = false;
361 document.location = baseURL + '?ts=' + Math.random();
364 var forceCompany = function(data) {
365 if (Pman.Login.authUser.company_id * 1 > 0) {
369 if (!data || !data.id) {
370 Pman.Dialog.Companies.show( { id : 0, isOwner : 1, comptype: 'OWNER' }, function(data) {
375 Pman.Login.authUser.company_id_id = data.id;
376 Pman.Login.authUser.company_id = data.id;
377 Pman.Login.authUser.company_id_name = data.name;
381 if (Pman.Login.authUser.id < 0) {
382 // admin company has been created - create the user..
383 if (Pman.Login.authUser.company_id_id* 1 > 0) {
401 onLoadTrack : function(id,cb) {
402 this.onLoadTrackCall(id, cb, 'DocumentsCirc_');
404 onLoadTrackEdit : function(id,cb) {
405 this.onLoadTrackCall(id, cb, 'Documents_');
409 /// ----------- FIXME -----
412 onLoadTrackCall : function(id,cb, cls) {
413 Roo.get(document.body).mask("Loading Document details");
416 url: baseURL + '/Roo/Documents.html',
421 success : function(data) {
422 Roo.get(document.body).unmask();
425 switch(data.in_out) {
426 case 'IN' : cls+='In';break;
427 case 'OUT' : cls+='Out';break;
428 case 'WIP' : cls+='Wip';break;
430 Roo.MessageBox.alert("Error", "invalid in_out");
433 Pman.Dialog[cls].show(data, cb ? cb : Pman.refreshActivePanel);
436 failure: function() {
437 Roo.get(document.body).unmask();
447 refreshActivePanel : function() {
448 var actpan = this.layout.getRegion('center').getActivePanel();
449 if (actpan.controller && actpan.controller.paging) {
450 actpan.controller.paging.onClick('refresh');
454 var agid = Pman.layout.getRegion('center').getActivePanel().id;
458 Pman.Tab[agid].paging.onClick('refresh');
460 toCidV : function(data) {
461 return 'C' + data.in_out.substring(0,1) + data.cid;
467 * Does the authenticated user have permission to see this.
469 * @param {String} name the [Module].[permission] to check for
470 * @param {Char} lvl - which type of permission to use (eg. S=show...)
471 * @returns {Boolean} tue indicates permission allowed
473 hasPerm: function(name, lvl) {
475 (typeof(Pman.Login.authUser) != 'object')
477 (typeof(Pman.Login.authUser.perms) != 'object')
479 (typeof(Pman.Login.authUser.perms[name]) != 'string')
484 return Pman.Login.authUser.perms[name].indexOf(lvl) > -1;
489 * Is there a permission defined for this (used by module registration.)
491 * @param {String} name the [Module].[permission] to check for
492 * @returns {Boolean} tue indicates permission exists.
494 hasPermExists: function(name) {
496 (typeof(Pman.Login.authUser) != 'object')
498 (typeof(Pman.Login.authUser.perms) != 'object')
500 (typeof(Pman.Login.authUser.perms[name]) != 'string')
518 processResponse : function (response)
522 res = Roo.decode(response.responseText);
524 if (typeof(res) != 'object') {
525 res = { success : false, errorMsg : res, errors : true };
527 if (typeof(res.success) == 'undefined') {
532 res = { success : false, errorMsg : response.responseText, errors : true };
536 genericDelete : function(tab,tbl) {
541 var s = tab.grid.getSelectionModel().getSelections();
543 Roo.MessageBox.alert("Error", "Select at least one Row to delete" );
547 for(var i = 0; i < s.length; i++) {
548 r.push(s[i].data.id);
551 Roo.MessageBox.confirm("Confirm", "Are you sure you want to delete that?",
556 // what about the toolbar??
557 tab.grid.getView().mainWrap.mask("Deleting");
559 url: baseURL + '/Roo/'+tbl+'.php',
562 _delete : r.join(',')
564 success: function(response) {
565 tab.grid.getView().mainWrap.unmask();
567 tab.paging.onClick('refresh');
568 } else if (tab.refresh) {
570 } else if (tab.grid.footer && tab.grid.footer.onClick) {
571 // new xtype built grids
572 tab.grid.footer.onClick('refresh');
574 tab.grid.getDataSource().load();
580 failure: function(act) {
581 tab.grid.getView().mainWrap.unmask();
582 Roo.MessageBox.alert("Error", "Error Deleting");
593 standardActionFailed : function(f, act, cb) {
595 if (act.failureType == 'client') {
596 Roo.MessageBox.alert("Error", "Please Correct all the errors in red", cb);
599 if (act.failureType == 'connect') {
600 Roo.MessageBox.alert("Error", "Problem Connecting to Server - please try again.", cb);
604 if (act.type == 'submit') {
606 Roo.MessageBox.alert("Error", typeof(act.result.errorMsg) == 'string' ?
607 String.format('{0}', act.result.errorMsg) :
608 "Saving failed = fix errors and try again", cb);
612 // what about load failing..
613 Roo.MessageBox.alert("Error", "Error loading details",cb);
616 * Depreciated - USE new Pman.Request
620 request : function(c) {
621 var r= new Roo.data.Connection({
622 timeout : typeof(c.timeout) == 'undefined' ? 30000 : c.timeout
629 success: function(response, opts) { // check successfull...
631 var res = Pman.processResponse(response);
633 if (!res.success) { // error!
635 if (true === c.failure.call(this,response, opts)) {
639 Roo.MessageBox.hide();
640 Roo.MessageBox.alert("Error", res.errorMsg ? res.errorMsg : "Error Sending");
644 c.success.call(this, res.data);
648 failure : function(response, opts) { // check successfull...
651 if (true === c.failure.call(this,response, opts)) {
655 Roo.MessageBox.hide();
656 Roo.MessageBox.alert("Error", "Connection timed out sending");
666 // depreciated - use Pman.Download()
668 download : function(c) {
670 return new Pman.Download(c);
673 // fixme - move to document manager...
674 downloadRevision : function(doc, rev)
677 url: baseURL + '/Documents/Doc/DownloadRev/'+ doc.id + '/' + rev + '/' +
678 doc.project_id_code + '-' + doc.cidV + '-' + rev + '-' + doc.filename
684 exportCSV : function(c) {
686 for(var i=0;i < c.csvFormat.length;i++) {
687 c.params['csvCols['+i+']'] = c.csvFormat[i][0];
688 c.params['csvTitles['+i+']'] = c.csvFormat[i][1];
690 c.url += '?' + Roo.urlEncode(c.params);
696 prettyDate : function (value)
698 if (typeof(value) == 'string') {
699 var ds = Date.parseDate(value, 'Y-m-d H:i:s');
701 return this.prettyDate(ds);
703 ds = Date.parseDate(value, 'Y-m-d');
705 return this.prettyDate(ds);
714 var daysSince = Math.floor(td.getElapsed(value) / (1000 * 60*60*24));
716 return value.dateFormat('D H:i');
720 if (td.dateFormat('m') == value.dateFormat('m')) {
721 return value.dateFormat('dS D');
724 if (td.dateFormat('Y') == value.dateFormat('Y')) {
725 return value.dateFormat('dS M');
727 return value.dateFormat('d M Y');
729 loadException : function(a,b,c,d)
731 if (d && d.authFailure) {
735 Roo.MessageBox.alert("Problem Loading Data", a.message || c.statusText);
741 * Routine to flash alerts in the title bar..
746 notifyActive : false,
748 notifyTitle: function(msg)
750 if (this.notifyActive ) {
755 var stopper = function() {
757 document.title = oldtitle;
760 Roo.get(document.body).on('mousemove', stopper, this);
761 var oldtitle = document.title;
764 var ivl = window.setInterval(function() {
767 Roo.get(document.body).un('mousemove', stopper, this);
768 _this.notifyActive = false;
769 document.title = oldtitle;
770 window.clearInterval(ivl);
774 document.title = s ? msg : oldtitle;
776 }, 1000); // every 120 secs = 2mins..
777 document.title = msg;
783 * @property {Array} appModules - array based on AppModules global
790 xregister : function(obj)
794 if (!this.appModules === false) {
795 this.appModules = typeof(AppModules ) == 'undefined'? [] :
796 AppModules.split(',');
801 // ignore registration of objects which are disabled.
802 // global supplied by master.html
803 appDisabled = typeof(appDisabled) == 'undefined' ? [] : appDisabled;
807 // previously we did not a good naming policy for module and parts
808 // most things that are called module here, really are 'parts'
809 // new versions should have 'part' as [ module : part ]
812 if (typeof(obj.part) != 'undefined') {
814 var permname = obj.part.join('.');
815 // we now have permission...
816 // obj.moduleOwner '.' lname
818 if (this.hasPermExists(permname) && !this.hasPerm(permname,'S')) {
819 // it's a turned off permission...
820 Roo.log(permname + " is Disabled for this user");
824 if (appDisabled.indexOf(permname) > -1) {
825 Roo.log(permname + " is Disabled for this site");
834 // false parent... use it..
839 if (obj.parent === Pman) {
840 obj.parent = Pman.fakeRoot;
843 if (typeof(obj.parent) == 'undefined') {
844 console.log("Parent is undefined");
851 if (obj.parent === false) {
853 console.log('ignoring top level object (as parent===false found)');
857 // this is an error condition - the parent does not exist..
858 // technically it should not happen..
860 // hack for Pman parent == Pman..
861 if (obj.parent == obj.module) {
869 * DEPRICATED : use Roo.XComponents now..
872 modKey : '00-admin-xxxx',
873 module : Pman.Tab.projectMgr, << really a components..
874 part : [ 'Admin', 'ProjectManager' ]
881 register : function(obj)
884 //this.xregister(obj);
887 // old style calls go in here..
888 // we need to convert the object so that it looks a bit like an XCompoenent..
890 obj.render = function()
893 Roo.log("Skip module, as parent does not exist");
896 //if (typeof(mod) == 'function') {
899 if (typeof(this.region) == 'undefined') {
900 Roo.log("Module does not have region defined, skipping");
904 if (this.module.disabled) {
905 Roo.log("Module disabled, should not rendering")
910 if (!this.parent.layout) {
911 Roo.log("Module parent does not have property layout.")
916 // honour DEPRICATED permname setings..
917 // new code should use PART name, and matching permissions.
918 if (this.permname && this.permname.length) {
919 if (Pman.hasPerm(this.permname, 'S')) {
920 this.module.add(this.parent.layout, this.region);
924 this.module.add(this.parent.layout, this.region);
929 Roo.log("CALLING XComponent register with : " + obj.name);
931 // this will call xregister as it's the on.register handler..
932 Roo.XComponent.register(obj);
940 if (!obj.parent.modules) {
941 obj.parent.modules = new Roo.util.MixedCollection(false, function(o) { return o.modKey });
944 obj.parent.modules.add(obj);
949 buildModules : function(parent, onComplete)
951 Roo.XComponent.build();
954 var cmp = function(a,b) {
955 return String(a).toUpperCase() > String(b).toUpperCase() ? 1 : -1;
958 if (!parent.modules) {
961 parent.modules.keySort('ASC', cmp );
965 // add modules to their parents..
966 var addMod = function(m) {
967 // console.log(m.modKey);
970 if (m.module.modules) {
971 m.module.modules.keySort('ASC', cmp );
972 m.module.modules.each(addMod);
975 m.finalize.name = m.name + " (clean up) ";
976 mods.push(m.finalize);
981 parent.modules.each(addMod);
982 //this.allmods = mods;
986 if (onComplete) onComplete();
989 // flash it up as modal - so we store the mask!?
990 Roo.MessageBox.show({ title: 'loading' });
991 Roo.MessageBox.show({
992 title: "Please wait...",
993 msg: "Building Interface...",
1001 var progressRun = function() {
1006 Roo.MessageBox.updateProgress(
1007 (n+1)/mods.length, "Building Interface " + (n+1) +
1008 " of " + mods.length +
1009 (mod.name ? (' - ' + mod.name) : '')
1014 if (typeof(mod) == 'function') {
1017 } else if (typeof(mod.region) == 'undefined') {
1018 Roo.log("Module does not have region defined, skipping");
1021 } else if (mod.parent.layout && !mod.module.disabled) {
1022 // honour permname setings..
1023 if (mod.permname && mod.permname.length) {
1024 if (Pman.hasPerm(mod.permname, 'S')) {
1025 mod.module.add(mod.parent.layout, mod.region);
1028 mod.module.add(mod.parent.layout, mod.region);
1034 if (n >= mods.length) {
1040 progressRun.defer(10, Pman);
1042 progressRun.defer(1, Pman);
1048 invertColor : function(c)
1052 for(var i = 0; i < 3; i++){
1053 ca[i] = parseInt(c.charAt((i*2)+1) + c.charAt((i*2)+2), 16);
1058 Roo.each(ca, function(hi) {
1059 var h = parseInt(255-hi).toString(16);