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 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 if (Pman.hasPerm('Core.ChangePassword','S')) {
253 new Roo.Toolbar.Fill(),
256 text: "Change Password",
257 cls: 'x-btn-text-icon',
258 icon: rootURL + '/Pman/templates/images/change-password.gif',
259 handler : function(){
260 Pman.PasswordChange.show({});
266 if (this.topMenuItems.length) {
268 Roo.each(this.topMenuItems, function (mi) {
276 if (this.subMenuItems.length) {
278 this.subMenuItems.sort(function (a,b) {
279 return a.seqid > b.seqid ? 1 : -1;
281 // chop off last seperator.
282 // since we always add it.. just chop of last item
283 this.subMenuItems.pop();
285 var btn = new Roo.Toolbar.Button(
287 text: "Add New Item",
288 cls: 'x-btn-text-icon',
289 icon: Roo.rootURL + 'images/default/dd/drop-add.gif',
291 items : this.subMenuItems
295 this.pulldownMenu = btn.menu;
303 cls: 'x-btn-text-icon',
304 icon: rootURL + '/Pman/templates/images/logout.gif',
305 handler: function() {
312 // this.layout.endUpdate();
316 finalize : function() {
320 window.onbeforeunload = function(e) {
321 e = e || window.event;
322 var r = "Closing this window will loose changes, are you sure you want to do that?";
324 // For IE and Firefox
334 Roo.MessageBox.hide();
335 if (Roo.get('loading-mask')) {
336 Roo.get('loading-mask').remove();
340 this.buildCompleted = true; // now we can force refreshes on everything..
343 // does the URL indicate we want to see a system..
344 if (AppTrackOnLoad * 1 > 0) {
345 this.onLoadTrack(AppTrackOnLoad,false);
350 var forceAdmin = function(data)
352 if (!data || !data.id) {
353 //Roo.log("Force Admin");
354 Pman.Dialog.PersonStaff.show(
357 company_id : Pman.Login.authUser.company_id_id * 1,
358 company_id_name : Pman.Login.authUser.company_id_name
365 Roo.state.Manager.set('Pman.Login.username', data.email),
366 window.onbeforeunload = false;
367 document.location = baseURL + '?ts=' + Math.random();
370 var forceCompany = function(data) {
371 if (Pman.Login.authUser.company_id * 1 > 0) {
375 if (!data || !data.id) {
376 Pman.Dialog.CoreCompanies.show( { id : 0, comptype: 'OWNER' }, function(data) {
377 Roo.log("company dialog returned");
383 Pman.Login.authUser.company_id_id = data.id;
384 Pman.Login.authUser.company_id = data.id;
385 Pman.Login.authUser.company_id_name = data.name;
386 Roo.log("forcing admin");
390 if (Pman.Login.authUser.id < 0) {
391 // admin company has been created - create the user..
392 if (Pman.Login.authUser.company_id_id* 1 > 0) {
410 onLoadTrack : function(id,cb) {
411 this.onLoadTrackCall(id, cb, 'DocumentsCirc_');
413 onLoadTrackEdit : function(id,cb) {
414 this.onLoadTrackCall(id, cb, 'Documents_');
418 /// ----------- FIXME -----
421 onLoadTrackCall : function(id,cb, cls) {
422 Roo.get(document.body).mask("Loading Document details");
425 url: baseURL + '/Roo/Documents.html',
430 success : function(res) {
432 Roo.get(document.body).unmask();
435 switch(data.in_out) {
436 case 'IN' : cls+='In';break;
437 case 'OUT' : cls+='Out';break;
438 case 'WIP' : cls+='Wip';break;
440 Roo.MessageBox.alert("Error", "invalid in_out");
443 Pman.Dialog[cls].show(data, cb ? cb : Pman.refreshActivePanel);
446 failure: function() {
447 Roo.get(document.body).unmask();
457 refreshActivePanel : function() {
458 var actpan = this.layout.getRegion('center').getActivePanel();
459 if (actpan.controller && actpan.controller.paging) {
460 actpan.controller.paging.onClick('refresh');
464 var agid = Pman.layout.getRegion('center').getActivePanel().id;
468 Pman.Tab[agid].paging.onClick('refresh');
470 toCidV : function(data) {
471 return 'C' + data.in_out.substring(0,1) + data.cid;
477 * Does the authenticated user have permission to see this.
479 * @param {String} name the [Module].[permission] to check for
480 * @param {Char} lvl - which type of permission to use (eg. S=show...)
481 * @returns {Boolean} tue indicates permission allowed
483 hasPerm: function(name, lvl) {
485 (typeof(Pman.Login.authUser) != 'object')
487 (typeof(Pman.Login.authUser.perms) != 'object')
489 (typeof(Pman.Login.authUser.perms[name]) != 'string')
494 return Pman.Login.authUser.perms[name].indexOf(lvl) > -1;
499 * Is there a permission defined for this (used by module registration.)
501 * @param {String} name the [Module].[permission] to check for
502 * @returns {Boolean} tue indicates permission exists.
504 hasPermExists: function(name) {
506 (typeof(Pman.Login.authUser) != 'object')
508 (typeof(Pman.Login.authUser.perms) != 'object')
510 (typeof(Pman.Login.authUser.perms[name]) != 'string')
528 processResponse : function (response)
532 res = Roo.decode(response.responseText);
534 if (typeof(res) != 'object') {
535 res = { success : false, errorMsg : res, errors : true };
537 if (typeof(res.success) == 'undefined') {
542 res = { success : false, errorMsg : response.responseText, errors : true };
546 genericDelete : function(tab,tbl) {
551 var s = tab.grid.getSelectionModel().getSelections();
553 Roo.MessageBox.alert("Error", "Select at least one Row to delete" );
556 var reader = tab.grid.reader || tab.grid.ds.reader;
557 for(var i = 0; i < s.length; i++) {
558 r.push(reader.getId(s[i]));
561 Roo.MessageBox.confirm("Confirm", "Are you sure you want to delete that?",
566 // what about the toolbar??
567 tab.grid.getView().mainWrap.mask("Deleting");
569 url: baseURL + '/Roo/'+tbl+'.php',
572 _delete : r.join(',')
574 success: function(response) {
575 tab.grid.getView().mainWrap.unmask();
577 tab.paging.onClick('refresh');
578 } else if (tab.grid.footer && tab.grid.footer.onClick) {
579 // new xtype built grids
580 tab.grid.footer.onClick('refresh');
581 } else if (tab.refresh) {
582 tab.refresh(); // this might cause problems as panels have a refresh method?
584 tab.grid.getDataSource().load();
590 failure: function(act) {
596 msg = "Error deleting";
598 tab.grid.getView().mainWrap.unmask();
599 Roo.MessageBox.alert("Error", msg);
610 standardActionFailed : function(f, act, cb) {
612 if (act.failureType == 'client') {
613 Roo.MessageBox.alert("Error", "Please Correct all the errors in red", cb);
616 if (act.failureType == 'connect') {
617 Roo.MessageBox.alert("Error", "Problem Connecting to Server - please try again.", cb);
621 if (act.type == 'submit') {
623 Roo.MessageBox.alert("Error", typeof(act.result.errorMsg) == 'string' ?
624 String.format('{0}', act.result.errorMsg) :
625 "Saving failed = fix errors and try again", cb);
629 // what about load failing..
630 Roo.MessageBox.alert("Error", "Error loading details",cb);
633 * Depreciated - USE new Pman.Request
634 * We need to replace all the uses with this, however the api is slightly different,
635 * the success argument is res.data, not res..
638 request : function(c) {
639 return new Pman.Request(c);
644 // depreciated - use Pman.Download()
646 download : function(c) {
648 return new Pman.Download(c);
651 // fixme - move to document manager...
652 downloadRevision : function(doc, rev)
655 url: baseURL + '/Documents/Doc/DownloadRev/'+ doc.id + '/' + rev + '/' +
656 doc.project_id_code + '-' + doc.cidV + '-' + rev + '-' + doc.filename
662 exportCSV : function(c) {
664 for(var i=0;i < c.csvFormat.length;i++) {
665 c.params['csvCols['+i+']'] = c.csvFormat[i][0];
666 c.params['csvTitles['+i+']'] = c.csvFormat[i][1];
668 c.url += '?' + Roo.urlEncode(c.params);
674 prettyDate : function (value)
676 if (typeof(value) == 'string') {
677 var ds = Date.parseDate(value, 'Y-m-d H:i:s');
679 return this.prettyDate(ds);
681 ds = Date.parseDate(value, 'Y-m-d');
683 return this.prettyDate(ds);
692 var daysSince = Math.floor(td.getElapsed(value) / (1000 * 60*60*24));
694 return value.dateFormat('D H:i');
698 if (td.dateFormat('m') == value.dateFormat('m')) {
699 return value.dateFormat('dS D');
702 if (td.dateFormat('Y') == value.dateFormat('Y')) {
703 return value.dateFormat('dS M');
705 return value.dateFormat('d M Y');
707 loadException : function(a,b,c,d)
709 if (d && d.authFailure) {
713 Roo.MessageBox.alert("Problem Loading Data", a.message || c.statusText);
719 * Routine to flash alerts in the title bar..
724 notifyActive : false,
726 notifyTitle: function(msg)
728 if (this.notifyActive ) {
733 var stopper = function() {
735 document.title = oldtitle;
738 Roo.get(document.body).on('mousemove', stopper, this);
739 var oldtitle = document.title;
742 var ivl = window.setInterval(function() {
745 Roo.get(document.body).un('mousemove', stopper, this);
746 _this.notifyActive = false;
747 document.title = oldtitle;
748 window.clearInterval(ivl);
752 document.title = s ? msg : oldtitle;
754 }, 1000); // every 120 secs = 2mins..
755 document.title = msg;
761 * @property {Array} appModules - array based on AppModules global
768 xregister : function(obj)
772 if (!Pman.appModules === false) {
773 Pman.appModules = typeof(AppModules ) == 'undefined'? [] :
774 AppModules.split(',');
779 // ignore registration of objects which are disabled.
780 // global supplied by master.html
781 appDisabled = typeof(appDisabled) == 'undefined' ? [] : appDisabled;
785 // previously we did not a good naming policy for module and parts
786 // most things that are called module here, really are 'parts'
787 // new versions should have 'part' as [ module : part ]
788 if (typeof(obj.part) != 'undefined') {
790 var permname = obj.part.join('.');
791 // we now have permission...
792 // obj.moduleOwner '.' lname
795 if (appDisabled.indexOf(permname) > -1) {
796 Roo.log('disabled!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!');
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);