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) { if (typeof(Pman) != 'undefined') { return Pman.xregister(e); } });
23 Roo.XComponent.on('buildComplete',
26 Pman.layout.getRegion('center').showPanel(0);
27 Pman.layout.endUpdate();
30 Pman.fireEvent('load',this);
32 if (!Pman.layout.getRegion('south').panels.length) {
33 Pman.layout.getRegion('south').hide();
42 Pman = new Roo.Document(
44 /// appVersion: '1.7', // fixme = needs to be removed - use Global AppVersion
47 rightNames: { }, /// register right names here - so they can be translated and rendered.
49 * @property {Roo.menu.Menu} pulldownMenu - the 'add menu pulldown, you can use it to add items..
55 buildCompleted : false, // flag to say if we are building interface..
57 'beforeload' : true, // fired after page ready, before module building.
58 'load' : true, // fired after module building
59 'authrefreshed' : true // fire on auth updated?? - should be on Login?!?!?
65 // kludge to fix firebug debugger
66 if (typeof(console) == 'undefined') {
67 console = { log : function() { } };
71 if (Roo.get('loading')) {
72 Roo.get('loading').remove();
75 Roo.state.Manager.setProvider(new Roo.state.CookieProvider());
79 if (AppLinkError.length) {
80 Roo.MessageBox.alert("Error", AppLinkError, function() {
88 if (showNewPass.length) {
89 Pman.PasswordChange.show( { passwordReset : showNewPass },
91 // fail and success we do a load...
103 if (Roo.get('loading-logo-tile')) {
104 Roo.get('loading-logo-tile').remove();
106 if (Roo.get('loading-logo-tile-top')) {
107 Roo.get('loading-logo-tile-top').remove();
109 if (Roo.get('loading-logo-bottom')) {
110 Roo.get('loading-logo-bottom').remove();
112 if (Roo.get('loading-logo-center')) {
113 Roo.get('loading-logo-center').remove();
119 fakeRoot : new Roo.XComponent( {
128 render : function (el) { this.el = this.layout; }
134 //this.fireEvent('beforeload',this);
139 return; // already loaded
141 if (Roo.get('loading')) {
142 Roo.get('loading').remove();
144 if (Roo.get('loading-mask')) {
145 Roo.get('loading-mask').show();
150 this.stime = new Date();
151 this.layout = new Roo.BorderLayout(document.body, {
165 alwaysShowTabs: true,
177 this.fakeRoot.layout = this.layout;
179 Pman.register( Roo.apply(this.fakeRoot, {
186 // creates all the modules ready to load..
188 this.fireEvent('beforeload',this);
192 this.layout.beginUpdate();
193 this.layout.add('north', new Roo.ContentPanel('title', 'North'));
194 var au = Pman.Login.authUser;
195 if (au.id > 0 && au.company_id_background_color && au.company_id_background_color.length) {
196 Roo.get('title').dom.style.backgroundColor = '#' + au.company_id_background_color;
197 Roo.get('headerInformation').dom.style.color = this.invertColor('#' + au.company_id_background_color);
199 if (au.id > 0 && au.company_id_logo_id * 1 > 0) {
200 Roo.get('headerInformation-company-logo').dom.src = baseURL +
201 '/Images/' + au.company_id_logo_id + '/' + au.company_id_logo_id_filename;
203 Roo.get('headerInformation-company-logo').dom.src = Roo.BLANK_IMAGE_URL;
206 Roo.get('headerInformation').dom.innerHTML = String.format(
207 "You are Logged in as <b>{0} ({1})</b>", // to {4} v{3}", // for <b>{2}</b>",
208 au.name, au.email, au.company_id_name,
209 AppVersion , appNameShort
213 document.title = appName + ' v' + AppVersion + ' - ' + au.company_id_name;
214 Roo.QuickTips.init();
219 //this.mainLayout.beginUpdate();
220 //var maskDom = Roo.get(document.body)._maskMsg.dom
221 this.layout.beginUpdate();
223 Pman.building = true;
224 Roo.XComponent.build();
231 addTopToolbar : function()
233 //console.log( "t6:" + ((new Date())-stime));
234 //this.mainLayout.endUpdate();
235 // make a new tab to hold administration stuff...
238 //console.log( "t7:" + ((new Date())-stime));
239 var se = Pman.layout.getRegion('center').tabs.stripEl;
240 var tbh = se.createChild(
241 { tag: 'td', style: 'width:100%;' });
243 var lotb = new Roo.Toolbar(tbh);
246 var tbl = se.child('table', true);
247 tbl.setAttribute('width', '100%');
250 new Roo.Toolbar.Fill(),
253 text: "Change Password",
254 cls: 'x-btn-text-icon',
255 icon: rootURL + '/Pman/templates/images/change-password.gif',
256 handler : function(){
257 Pman.PasswordChange.show({});
263 if (this.topMenuItems.length) {
265 Roo.each(this.topMenuItems, function (mi) {
273 if (this.subMenuItems.length) {
275 this.subMenuItems.sort(function (a,b) {
276 return a.seqid > b.seqid ? 1 : -1;
278 // chop off last seperator.
279 // since we always add it.. just chop of last item
280 this.subMenuItems.pop();
282 var btn = new Roo.Toolbar.Button(
284 text: "Add New Item",
285 cls: 'x-btn-text-icon',
286 icon: Roo.rootURL + 'images/default/dd/drop-add.gif',
288 items : this.subMenuItems
292 this.pulldownMenu = btn.menu;
300 cls: 'x-btn-text-icon',
301 icon: rootURL + '/Pman/templates/images/logout.gif',
302 handler: function() {
309 // this.layout.endUpdate();
313 finalize : function() {
317 window.onbeforeunload = function(e) {
318 e = e || window.event;
319 var r = "Closing this window will loose changes, are you sure you want to do that?";
321 // For IE and Firefox
331 Roo.MessageBox.hide();
332 if (Roo.get('loading-mask')) {
333 Roo.get('loading-mask').remove();
337 this.buildCompleted = true; // now we can force refreshes on everything..
340 // does the URL indicate we want to see a system..
341 if (AppTrackOnLoad * 1 > 0) {
342 this.onLoadTrack(AppTrackOnLoad,false);
347 var forceAdmin = function(data)
349 if (!data || !data.id) {
350 //Roo.log("Force Admin");
351 Pman.Dialog.PersonStaff.show(
354 company_id : Pman.Login.authUser.company_id_id * 1,
355 company_id_name : Pman.Login.authUser.company_id_name
362 Roo.state.Manager.set('Pman.Login.username', data.email),
363 window.onbeforeunload = false;
364 document.location = baseURL + '?ts=' + Math.random();
367 var forceCompany = function(data) {
368 if (Pman.Login.authUser.company_id * 1 > 0) {
372 if (!data || !data.id) {
373 Pman.Dialog.Companies.show( { id : 0, isOwner : 1, comptype: 'OWNER' }, function(data) {
378 Pman.Login.authUser.company_id_id = data.id;
379 Pman.Login.authUser.company_id = data.id;
380 Pman.Login.authUser.company_id_name = data.name;
384 if (Pman.Login.authUser.id < 0) {
385 // admin company has been created - create the user..
386 if (Pman.Login.authUser.company_id_id* 1 > 0) {
404 onLoadTrack : function(id,cb) {
405 this.onLoadTrackCall(id, cb, 'DocumentsCirc_');
407 onLoadTrackEdit : function(id,cb) {
408 this.onLoadTrackCall(id, cb, 'Documents_');
412 /// ----------- FIXME -----
415 onLoadTrackCall : function(id,cb, cls) {
416 Roo.get(document.body).mask("Loading Document details");
419 url: baseURL + '/Roo/Documents.html',
424 success : function(data) {
425 Roo.get(document.body).unmask();
428 switch(data.in_out) {
429 case 'IN' : cls+='In';break;
430 case 'OUT' : cls+='Out';break;
431 case 'WIP' : cls+='Wip';break;
433 Roo.MessageBox.alert("Error", "invalid in_out");
436 Pman.Dialog[cls].show(data, cb ? cb : Pman.refreshActivePanel);
439 failure: function() {
440 Roo.get(document.body).unmask();
450 refreshActivePanel : function() {
451 var actpan = this.layout.getRegion('center').getActivePanel();
452 if (actpan.controller && actpan.controller.paging) {
453 actpan.controller.paging.onClick('refresh');
457 var agid = Pman.layout.getRegion('center').getActivePanel().id;
461 Pman.Tab[agid].paging.onClick('refresh');
463 toCidV : function(data) {
464 return 'C' + data.in_out.substring(0,1) + data.cid;
470 * Does the authenticated user have permission to see this.
472 * @param {String} name the [Module].[permission] to check for
473 * @param {Char} lvl - which type of permission to use (eg. S=show...)
474 * @returns {Boolean} tue indicates permission allowed
476 hasPerm: function(name, lvl) {
478 (typeof(Pman.Login.authUser) != 'object')
480 (typeof(Pman.Login.authUser.perms) != 'object')
482 (typeof(Pman.Login.authUser.perms[name]) != 'string')
487 return Pman.Login.authUser.perms[name].indexOf(lvl) > -1;
492 * Is there a permission defined for this (used by module registration.)
494 * @param {String} name the [Module].[permission] to check for
495 * @returns {Boolean} tue indicates permission exists.
497 hasPermExists: function(name) {
499 (typeof(Pman.Login.authUser) != 'object')
501 (typeof(Pman.Login.authUser.perms) != 'object')
503 (typeof(Pman.Login.authUser.perms[name]) != 'string')
521 processResponse : function (response)
525 res = Roo.decode(response.responseText);
527 if (typeof(res) != 'object') {
528 res = { success : false, errorMsg : res, errors : true };
530 if (typeof(res.success) == 'undefined') {
535 res = { success : false, errorMsg : response.responseText, errors : true };
539 genericDelete : function(tab,tbl) {
544 var s = tab.grid.getSelectionModel().getSelections();
546 Roo.MessageBox.alert("Error", "Select at least one Row to delete" );
550 for(var i = 0; i < s.length; i++) {
551 r.push(s[i].data.id);
554 Roo.MessageBox.confirm("Confirm", "Are you sure you want to delete that?",
559 // what about the toolbar??
560 tab.grid.getView().mainWrap.mask("Deleting");
562 url: baseURL + '/Roo/'+tbl+'.php',
565 _delete : r.join(',')
567 success: function(response) {
568 tab.grid.getView().mainWrap.unmask();
570 tab.paging.onClick('refresh');
571 } else if (tab.refresh) {
573 } else if (tab.grid.footer && tab.grid.footer.onClick) {
574 // new xtype built grids
575 tab.grid.footer.onClick('refresh');
577 tab.grid.getDataSource().load();
583 failure: function(act) {
584 tab.grid.getView().mainWrap.unmask();
585 Roo.MessageBox.alert("Error", "Error Deleting");
596 standardActionFailed : function(f, act, cb) {
598 if (act.failureType == 'client') {
599 Roo.MessageBox.alert("Error", "Please Correct all the errors in red", cb);
602 if (act.failureType == 'connect') {
603 Roo.MessageBox.alert("Error", "Problem Connecting to Server - please try again.", cb);
607 if (act.type == 'submit') {
609 Roo.MessageBox.alert("Error", typeof(act.result.errorMsg) == 'string' ?
610 String.format('{0}', act.result.errorMsg) :
611 "Saving failed = fix errors and try again", cb);
615 // what about load failing..
616 Roo.MessageBox.alert("Error", "Error loading details",cb);
619 * Depreciated - USE new Pman.Request
623 request : function(c) {
624 var r= new Roo.data.Connection({
625 timeout : typeof(c.timeout) == 'undefined' ? 30000 : c.timeout
632 success: function(response, opts) { // check successfull...
634 var res = Pman.processResponse(response);
636 if (!res.success) { // error!
638 if (true === c.failure.call(this,response, opts)) {
642 Roo.MessageBox.hide();
643 Roo.MessageBox.alert("Error", res.errorMsg ? res.errorMsg : "Error Sending");
647 c.success.call(this, res.data);
651 failure : function(response, opts) { // check successfull...
654 if (true === c.failure.call(this,response, opts)) {
658 Roo.MessageBox.hide();
659 Roo.MessageBox.alert("Error", "Connection timed out sending");
669 // depreciated - use Pman.Download()
671 download : function(c) {
673 return new Pman.Download(c);
676 // fixme - move to document manager...
677 downloadRevision : function(doc, rev)
680 url: baseURL + '/Documents/Doc/DownloadRev/'+ doc.id + '/' + rev + '/' +
681 doc.project_id_code + '-' + doc.cidV + '-' + rev + '-' + doc.filename
687 exportCSV : function(c) {
689 for(var i=0;i < c.csvFormat.length;i++) {
690 c.params['csvCols['+i+']'] = c.csvFormat[i][0];
691 c.params['csvTitles['+i+']'] = c.csvFormat[i][1];
693 c.url += '?' + Roo.urlEncode(c.params);
699 prettyDate : function (value)
701 if (typeof(value) == 'string') {
702 var ds = Date.parseDate(value, 'Y-m-d H:i:s');
704 return this.prettyDate(ds);
706 ds = Date.parseDate(value, 'Y-m-d');
708 return this.prettyDate(ds);
717 var daysSince = Math.floor(td.getElapsed(value) / (1000 * 60*60*24));
719 return value.dateFormat('D H:i');
723 if (td.dateFormat('m') == value.dateFormat('m')) {
724 return value.dateFormat('dS D');
727 if (td.dateFormat('Y') == value.dateFormat('Y')) {
728 return value.dateFormat('dS M');
730 return value.dateFormat('d M Y');
732 loadException : function(a,b,c,d)
734 if (d && d.authFailure) {
738 Roo.MessageBox.alert("Problem Loading Data", a.message || c.statusText);
744 * Routine to flash alerts in the title bar..
749 notifyActive : false,
751 notifyTitle: function(msg)
753 if (this.notifyActive ) {
758 var stopper = function() {
760 document.title = oldtitle;
763 Roo.get(document.body).on('mousemove', stopper, this);
764 var oldtitle = document.title;
767 var ivl = window.setInterval(function() {
770 Roo.get(document.body).un('mousemove', stopper, this);
771 _this.notifyActive = false;
772 document.title = oldtitle;
773 window.clearInterval(ivl);
777 document.title = s ? msg : oldtitle;
779 }, 1000); // every 120 secs = 2mins..
780 document.title = msg;
786 * @property {Array} appModules - array based on AppModules global
793 xregister : function(obj)
797 if (!Pman.appModules === false) {
798 Pman.appModules = typeof(AppModules ) == 'undefined'? [] :
799 AppModules.split(',');
804 // ignore registration of objects which are disabled.
805 // global supplied by master.html
806 appDisabled = typeof(appDisabled) == 'undefined' ? [] : appDisabled;
810 // previously we did not a good naming policy for module and parts
811 // most things that are called module here, really are 'parts'
812 // new versions should have 'part' as [ module : part ]
815 if (typeof(obj.part) != 'undefined') {
817 var permname = obj.part.join('.');
818 // we now have permission...
819 // obj.moduleOwner '.' lname
820 Roo.log("CHECKING PERM: " + permname);
821 Roo.log("Exists: " + (Pman.hasPermExists(permname) ? 1 : 0));
822 Roo.log("has: " + (Pman.hasPerm(permname,'S') ? 1 : 0));
823 Roo.log(Pman.Login.authUser);
824 if (Pman.hasPermExists(permname) && !Pman.hasPerm(permname,'S')) {
825 // it's a turned off permission...
826 Roo.log(permname + " is Disabled for this user");
830 if (appDisabled.indexOf(permname) > -1) {
831 Roo.log(permname + " is Disabled for this site");
840 // false parent... use it..
845 if (obj.parent === Pman || obj.parent == 'Pman') {
846 Roo.log("PARENT OF : " + obj.name + " replacing with fake");
847 obj.parent = Pman.fakeRoot;
850 if (typeof(obj.parent) == 'undefined') {
851 console.log("Parent is undefined");
858 if (obj.parent === false) {
860 console.log('ignoring top level object (as parent===false found)');
864 // this is an error condition - the parent does not exist..
865 // technically it should not happen..
867 // hack for Pman parent == Pman..
868 if (obj.parent == obj.module) {
876 * DEPRICATED : use Roo.XComponents now..
879 modKey : '00-admin-xxxx',
880 module : Pman.Tab.projectMgr, << really a components..
881 part : [ 'Admin', 'ProjectManager' ]
888 register : function(obj)
891 //this.xregister(obj);
894 // old style calls go in here..
895 // we need to convert the object so that it looks a bit like an XCompoenent..
897 obj.render = function()
900 Roo.log("Skip module, as parent does not exist");
904 //if (typeof(mod) == 'function') {
907 if (typeof(this.region) == 'undefined') {
908 Roo.log("Module does not have region defined, skipping");
912 if (this.module.disabled) {
913 Roo.log("Module disabled, should not rendering")
918 if (!this.parent.layout) {
919 Roo.log("Module parent does not have property layout.")
924 // honour DEPRICATED permname setings..
925 // new code should use PART name, and matching permissions.
926 if (this.permname && this.permname.length) {
927 if (!Pman.hasPerm(this.permname, 'S')) {
932 this.add(this.parent.layout, this.region);
933 this.el = this.layout;
938 // map some of the standard properties..
939 obj.order = obj.modKey;
945 // the other issue we have is that
948 // Roo.log("CALLING XComponent register with : " + obj.name);
950 // this will call xregister as it's the on.register handler..
951 Roo.XComponent.register(obj.isTop ? obj : Roo.apply(obj.module, obj));
954 invertColor : function(c)
958 for(var i = 0; i < 3; i++){
959 ca[i] = parseInt(c.charAt((i*2)+1) + c.charAt((i*2)+2), 16);
964 Roo.each(ca, function(hi) {
965 var h = parseInt(255-hi).toString(16);