1 //<script type="text/javascript">
7 * - gtranslate moved to Pman.GoogleTranslate
12 if (typeof(_T) == 'undefined') { _T={};}
16 Roo.XComponent.on('register', function(e) {
17 if (typeof(Pman) != 'undefined') { return Pman.xregister(e); } return true;
19 Roo.XComponent.on('beforebuild', function(e) {
20 if (typeof(Pman) != 'undefined') { return Pman.xbeforebuild(e); } return true;
23 Roo.XComponent.on('buildcomplete',
25 Pman.building = false;
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 if (!Pman.layout.getRegion('center').tabs) {
240 Roo.log("Error could not find tabs? - not adding toolbar?");
244 var se = Pman.layout.getRegion('center').tabs.stripEl;
245 var tbh = se.createChild(
246 { tag: 'td', style: 'width:100%;' });
248 var lotb = new Roo.Toolbar(tbh);
251 var tbl = se.child('table', true);
252 tbl.setAttribute('width', '100%');
255 if (Pman.hasPerm('Core.ChangePassword','S')) {
258 new Roo.Toolbar.Fill(),
261 text: "Change Password",
262 cls: 'x-btn-text-icon',
263 icon: rootURL + '/Pman/templates/images/change-password.gif',
264 handler : function(){
265 Pman.PasswordChange.show({});
271 if (this.topMenuItems.length) {
273 Roo.each(this.topMenuItems, function (mi) {
281 if (this.subMenuItems.length) {
283 this.subMenuItems.sort(function (a,b) {
284 return a.seqid > b.seqid ? 1 : -1;
286 // chop off last seperator.
287 // since we always add it.. just chop of last item
288 this.subMenuItems.pop();
290 var btn = new Roo.Toolbar.Button(
292 text: "Add New Item",
293 cls: 'x-btn-text-icon',
294 icon: Roo.rootURL + 'images/default/dd/drop-add.gif',
296 items : this.subMenuItems
300 this.pulldownMenu = btn.menu;
308 cls: 'x-btn-text-icon',
309 icon: rootURL + '/Pman/templates/images/logout.gif',
310 handler: function() {
317 // this.layout.endUpdate();
321 finalize : function() {
325 window.onbeforeunload = function(e) {
326 e = e || window.event;
327 var r = "Closing this window will loose changes, are you sure you want to do that?";
329 // For IE and Firefox
339 Roo.MessageBox.hide();
340 if (Roo.get('loading-mask')) {
341 Roo.get('loading-mask').remove();
345 this.buildCompleted = true; // now we can force refreshes on everything..
348 // does the URL indicate we want to see a system..
349 if (AppTrackOnLoad * 1 > 0) {
350 this.onLoadTrack(AppTrackOnLoad,false);
355 var forceAdmin = function(data)
357 if (!data || !data.id) {
358 //Roo.log("Force Admin");
359 Pman.Dialog.PersonStaff.show(
362 company_id : Pman.Login.authUser.company_id_id * 1,
363 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_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 if (typeof(obj.part) != 'undefined') {
856 if (!obj.part[1].length) {
857 obj.part[1] = obj.part[0];
859 var permname = obj.part.join('.');
861 Roo.log("CHECKING: "+ permname);
863 // we now have permission...
864 // obj.moduleOwner '.' lname
866 if (Pman.hasPermExists(permname) && !Pman.hasPerm(permname,'S')) {
867 // it's a turned off permission...
868 Roo.log(permname + " is Disabled for this user");
881 * DEPRICATED : use Roo.XComponents now..
884 modKey : '00-admin-xxxx',
885 module : Pman.Tab.projectMgr, << really a components..
886 part : [ 'Admin', 'ProjectManager' ]
893 register : function(obj)
896 //this.xregister(obj);
899 // old style calls go in here..
900 // we need to convert the object so that it looks a bit like an XCompoenent..
902 obj.render = function()
905 Roo.log("Skip module, as parent does not exist");
909 //if (typeof(mod) == 'function') {
912 if (typeof(this.region) == 'undefined') {
913 Roo.log("Module does not have region defined, skipping");
917 if (this.module.disabled) {
918 Roo.log("Module disabled, should not rendering")
923 if (!this.parent.layout) {
924 Roo.log("Module parent does not have property layout.")
929 // honour DEPRICATED permname setings..
930 // new code should use PART name, and matching permissions.
931 if (this.permname && this.permname.length) {
932 if (!Pman.hasPerm(this.permname, 'S')) {
937 this.add(this.parent.layout, this.region);
938 this.el = this.layout;
943 // map some of the standard properties..
944 obj.order = obj.modKey;
950 // the other issue we have is that
953 // Roo.log("CALLING XComponent register with : " + obj.name);
955 // this will call xregister as it's the on.register handler..
956 Roo.XComponent.register(obj.isTop ? obj : Roo.apply(obj.module, obj));
959 invertColor : function(c)
963 for(var i = 0; i < 3; i++){
964 ca[i] = parseInt(c.charAt((i*2)+1) + c.charAt((i*2)+2), 16);
969 Roo.each(ca, function(hi) {
970 var h = parseInt(255-hi).toString(16);