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();
108 //this.fireEvent('beforeload',this);
113 return; // already loaded
115 if (Roo.get('loading')) {
116 Roo.get('loading').remove();
118 if (Roo.get('loading-mask')) {
119 Roo.get('loading-mask').show();
124 this.stime = new Date();
125 this.layout = new Roo.BorderLayout(document.body, {
139 alwaysShowTabs: true,
163 // creates all the modules ready to load..
165 this.fireEvent('beforeload',this);
169 this.layout.beginUpdate();
170 this.layout.add('north', new Roo.ContentPanel('title', 'North'));
171 var au = Pman.Login.authUser;
172 if (au.id > 0 && au.company_id_background_color && au.company_id_background_color.length) {
173 Roo.get('title').dom.style.backgroundColor = '#' + au.company_id_background_color;
174 Roo.get('headerInformation').dom.style.color = this.invertColor('#' + au.company_id_background_color);
176 if (au.id > 0 && au.company_id_logo_id * 1 > 0) {
177 Roo.get('headerInformation-company-logo').dom.src = baseURL +
178 '/Images/' + au.company_id_logo_id + '/' + au.company_id_logo_id_filename;
180 Roo.get('headerInformation-company-logo').dom.src = Roo.BLANK_IMAGE_URL;
183 Roo.get('headerInformation').dom.innerHTML = String.format(
184 "You are Logged in as <b>{0} ({1})</b>", // to {4} v{3}", // for <b>{2}</b>",
185 au.name, au.email, au.company_id_name,
186 AppVersion , appNameShort
190 document.title = appName + ' v' + AppVersion + ' - ' + au.company_id_name;
191 Roo.QuickTips.init();
196 //this.mainLayout.beginUpdate();
197 //var maskDom = Roo.get(document.body)._maskMsg.dom
198 this.layout.beginUpdate();
200 Pman.building = true;
202 this.buildModules(this,
205 _this.layout.getRegion('center').showPanel(0);
206 _this.layout.endUpdate();
207 _this.addTopToolbar();
209 _this.fireEvent('load',this);
211 if (!_this.layout.getRegion('south').panels.length) {
212 _this.layout.getRegion('south').hide();
223 addTopToolbar : function()
225 //console.log( "t6:" + ((new Date())-stime));
226 //this.mainLayout.endUpdate();
227 // make a new tab to hold administration stuff...
230 //console.log( "t7:" + ((new Date())-stime));
231 var se = Pman.layout.getRegion('center').tabs.stripEl;
232 var tbh = se.createChild(
233 { tag: 'td', style: 'width:100%;' });
235 var lotb = new Roo.Toolbar(tbh);
238 var tbl = se.child('table', true);
239 tbl.setAttribute('width', '100%');
242 new Roo.Toolbar.Fill(),
245 text: "Change Password",
246 cls: 'x-btn-text-icon',
247 icon: rootURL + '/Pman/templates/images/change-password.gif',
248 handler : function(){
249 Pman.PasswordChange.show({});
255 if (this.topMenuItems.length) {
257 Roo.each(this.topMenuItems, function (mi) {
265 if (this.subMenuItems.length) {
267 this.subMenuItems.sort(function (a,b) {
268 return a.seqid > b.seqid ? 1 : -1;
270 // chop off last seperator.
271 // since we always add it.. just chop of last item
272 this.subMenuItems.pop();
274 var btn = new Roo.Toolbar.Button(
276 text: "Add New Item",
277 cls: 'x-btn-text-icon',
278 icon: Roo.rootURL + 'images/default/dd/drop-add.gif',
280 items : this.subMenuItems
284 this.pulldownMenu = btn.menu;
292 cls: 'x-btn-text-icon',
293 icon: rootURL + '/Pman/templates/images/logout.gif',
294 handler: function() {
301 // this.layout.endUpdate();
305 finalize : function() {
309 window.onbeforeunload = function(e) {
310 e = e || window.event;
311 var r = "Closing this window will loose changes, are you sure you want to do that?";
313 // For IE and Firefox
323 Roo.MessageBox.hide();
324 if (Roo.get('loading-mask')) {
325 Roo.get('loading-mask').remove();
329 this.buildCompleted = true; // now we can force refreshes on everything..
332 // does the URL indicate we want to see a system..
333 if (AppTrackOnLoad * 1 > 0) {
334 this.onLoadTrack(AppTrackOnLoad,false);
339 var forceAdmin = function(data)
341 if (!data || !data.id) {
342 //Roo.log("Force Admin");
343 Pman.Dialog.PersonStaff.show(
346 company_id : Pman.Login.authUser.company_id_id * 1,
347 company_id_name : Pman.Login.authUser.company_id_name
354 Roo.state.Manager.set('Pman.Login.username', data.email),
355 window.onbeforeunload = false;
356 document.location = baseURL + '?ts=' + Math.random();
359 var forceCompany = function(data) {
360 if (Pman.Login.authUser.company_id * 1 > 0) {
364 if (!data || !data.id) {
365 Pman.Dialog.Companies.show( { id : 0, isOwner : 1, comptype: 'OWNER' }, function(data) {
370 Pman.Login.authUser.company_id_id = data.id;
371 Pman.Login.authUser.company_id = data.id;
372 Pman.Login.authUser.company_id_name = data.name;
376 if (Pman.Login.authUser.id < 0) {
377 // admin company has been created - create the user..
378 if (Pman.Login.authUser.company_id_id* 1 > 0) {
396 onLoadTrack : function(id,cb) {
397 this.onLoadTrackCall(id, cb, 'DocumentsCirc_');
399 onLoadTrackEdit : function(id,cb) {
400 this.onLoadTrackCall(id, cb, 'Documents_');
404 /// ----------- FIXME -----
407 onLoadTrackCall : function(id,cb, cls) {
408 Roo.get(document.body).mask("Loading Document details");
411 url: baseURL + '/Roo/Documents.html',
416 success : function(data) {
417 Roo.get(document.body).unmask();
420 switch(data.in_out) {
421 case 'IN' : cls+='In';break;
422 case 'OUT' : cls+='Out';break;
423 case 'WIP' : cls+='Wip';break;
425 Roo.MessageBox.alert("Error", "invalid in_out");
428 Pman.Dialog[cls].show(data, cb ? cb : Pman.refreshActivePanel);
431 failure: function() {
432 Roo.get(document.body).unmask();
442 refreshActivePanel : function() {
443 var actpan = this.layout.getRegion('center').getActivePanel();
444 if (actpan.controller && actpan.controller.paging) {
445 actpan.controller.paging.onClick('refresh');
449 var agid = Pman.layout.getRegion('center').getActivePanel().id;
453 Pman.Tab[agid].paging.onClick('refresh');
455 toCidV : function(data) {
456 return 'C' + data.in_out.substring(0,1) + data.cid;
462 * Does the authenticated user have permission to see this.
464 * @param {String} name the [Module].[permission] to check for
465 * @param {Char} lvl - which type of permission to use (eg. S=show...)
466 * @returns {Boolean} tue indicates permission allowed
468 hasPerm: function(name, lvl) {
470 (typeof(Pman.Login.authUser) != 'object')
472 (typeof(Pman.Login.authUser.perms) != 'object')
474 (typeof(Pman.Login.authUser.perms[name]) != 'string')
479 return Pman.Login.authUser.perms[name].indexOf(lvl) > -1;
484 * Is there a permission defined for this (used by module registration.)
486 * @param {String} name the [Module].[permission] to check for
487 * @returns {Boolean} tue indicates permission exists.
489 hasPermExists: function(name) {
491 (typeof(Pman.Login.authUser) != 'object')
493 (typeof(Pman.Login.authUser.perms) != 'object')
495 (typeof(Pman.Login.authUser.perms[name]) != 'string')
513 processResponse : function (response)
517 res = Roo.decode(response.responseText);
519 if (typeof(res) != 'object') {
520 res = { success : false, errorMsg : res, errors : true };
522 if (typeof(res.success) == 'undefined') {
527 res = { success : false, errorMsg : response.responseText, errors : true };
531 genericDelete : function(tab,tbl) {
536 var s = tab.grid.getSelectionModel().getSelections();
538 Roo.MessageBox.alert("Error", "Select at least one Row to delete" );
542 for(var i = 0; i < s.length; i++) {
543 r.push(s[i].data.id);
546 Roo.MessageBox.confirm("Confirm", "Are you sure you want to delete that?",
551 // what about the toolbar??
552 tab.grid.getView().mainWrap.mask("Deleting");
554 url: baseURL + '/Roo/'+tbl+'.php',
557 _delete : r.join(',')
559 success: function(response) {
560 tab.grid.getView().mainWrap.unmask();
562 tab.paging.onClick('refresh');
563 } else if (tab.refresh) {
565 } else if (tab.grid.footer && tab.grid.footer.onClick) {
566 // new xtype built grids
567 tab.grid.footer.onClick('refresh');
569 tab.grid.getDataSource().load();
575 failure: function(act) {
576 tab.grid.getView().mainWrap.unmask();
577 Roo.MessageBox.alert("Error", "Error Deleting");
588 standardActionFailed : function(f, act, cb) {
590 if (act.failureType == 'client') {
591 Roo.MessageBox.alert("Error", "Please Correct all the errors in red", cb);
594 if (act.failureType == 'connect') {
595 Roo.MessageBox.alert("Error", "Problem Connecting to Server - please try again.", cb);
599 if (act.type == 'submit') {
601 Roo.MessageBox.alert("Error", typeof(act.result.errorMsg) == 'string' ?
602 String.format('{0}', act.result.errorMsg) :
603 "Saving failed = fix errors and try again", cb);
607 // what about load failing..
608 Roo.MessageBox.alert("Error", "Error loading details",cb);
611 * Depreciated - USE new Pman.Request
615 request : function(c) {
616 var r= new Roo.data.Connection({
617 timeout : typeof(c.timeout) == 'undefined' ? 30000 : c.timeout
624 success: function(response, opts) { // check successfull...
626 var res = Pman.processResponse(response);
628 if (!res.success) { // error!
630 if (true === c.failure.call(this,response, opts)) {
634 Roo.MessageBox.hide();
635 Roo.MessageBox.alert("Error", res.errorMsg ? res.errorMsg : "Error Sending");
639 c.success.call(this, res.data);
643 failure : function(response, opts) { // check successfull...
646 if (true === c.failure.call(this,response, opts)) {
650 Roo.MessageBox.hide();
651 Roo.MessageBox.alert("Error", "Connection timed out sending");
661 // depreciated - use Pman.Download()
663 download : function(c) {
665 return new Pman.Download(c);
668 // fixme - move to document manager...
669 downloadRevision : function(doc, rev)
672 url: baseURL + '/Documents/Doc/DownloadRev/'+ doc.id + '/' + rev + '/' +
673 doc.project_id_code + '-' + doc.cidV + '-' + rev + '-' + doc.filename
679 exportCSV : function(c) {
681 for(var i=0;i < c.csvFormat.length;i++) {
682 c.params['csvCols['+i+']'] = c.csvFormat[i][0];
683 c.params['csvTitles['+i+']'] = c.csvFormat[i][1];
685 c.url += '?' + Roo.urlEncode(c.params);
691 prettyDate : function (value)
693 if (typeof(value) == 'string') {
694 var ds = Date.parseDate(value, 'Y-m-d H:i:s');
696 return this.prettyDate(ds);
698 ds = Date.parseDate(value, 'Y-m-d');
700 return this.prettyDate(ds);
709 var daysSince = Math.floor(td.getElapsed(value) / (1000 * 60*60*24));
711 return value.dateFormat('D H:i');
715 if (td.dateFormat('m') == value.dateFormat('m')) {
716 return value.dateFormat('dS D');
719 if (td.dateFormat('Y') == value.dateFormat('Y')) {
720 return value.dateFormat('dS M');
722 return value.dateFormat('d M Y');
724 loadException : function(a,b,c,d)
726 if (d && d.authFailure) {
730 Roo.MessageBox.alert("Problem Loading Data", a.message || c.statusText);
736 * Routine to flash alerts in the title bar..
741 notifyActive : false,
743 notifyTitle: function(msg)
745 if (this.notifyActive ) {
750 var stopper = function() {
752 document.title = oldtitle;
755 Roo.get(document.body).on('mousemove', stopper, this);
756 var oldtitle = document.title;
759 var ivl = window.setInterval(function() {
762 Roo.get(document.body).un('mousemove', stopper, this);
763 _this.notifyActive = false;
764 document.title = oldtitle;
765 window.clearInterval(ivl);
769 document.title = s ? msg : oldtitle;
771 }, 1000); // every 120 secs = 2mins..
772 document.title = msg;
778 * @property {Array} appModules - array based on AppModules global
785 xregister : function(obj)
789 if (!this.appModules === false) {
790 this.appModules = typeof(AppModules ) == 'undefined'? [] :
791 AppModules.split(',');
796 // ignore registration of objects which are disabled.
797 // global supplied by master.html
798 appDisabled = typeof(appDisabled) == 'undefined' ? [] : appDisabled;
802 // previously we did not a good naming policy for module and parts
803 // most things that are called module here, really are 'parts'
804 // new versions should have 'part' as [ module : part ]
807 if (typeof(obj.part) != 'undefined') {
809 var permname = obj.part.join('.');
810 // we now have permission...
811 // obj.moduleOwner '.' lname
813 if (this.hasPermExists(permname) && !this.hasPerm(permname,'S')) {
814 // it's a turned off permission...
815 Roo.log(permname + " is Disabled for this user");
819 if (appDisabled.indexOf(permname) > -1) {
820 Roo.log(permname + " is Disabled for this site");
831 if (obj.parent === false) {
833 console.log('ignoring top level object (as parent===false found)');
837 // this is an error condition - the parent does not exist..
838 // technically it should not happen..
839 console.log("Parent is undefined");
844 // hack for Pman parent == Pman..
845 if (obj.parent == obj.module) {
853 * DEPRICATED : use Roo.XComponents now..
856 modKey : '00-admin-xxxx',
857 module : Pman.Tab.projectMgr, << really a components..
858 part : [ 'Admin', 'ProjectManager' ]
865 register : function(obj)
870 Roo.log("CALLING XComponent register with : " + obj.name);
871 Roo.XComponent.register(obj);
879 if (!obj.parent.modules) {
880 obj.parent.modules = new Roo.util.MixedCollection(false, function(o) { return o.modKey });
883 obj.parent.modules.add(obj);
888 buildModules : function(parent, onComplete)
890 Roo.XComponent.build();
893 var cmp = function(a,b) {
894 return String(a).toUpperCase() > String(b).toUpperCase() ? 1 : -1;
897 if (!parent.modules) {
900 parent.modules.keySort('ASC', cmp );
904 // add modules to their parents..
905 var addMod = function(m) {
906 // console.log(m.modKey);
909 if (m.module.modules) {
910 m.module.modules.keySort('ASC', cmp );
911 m.module.modules.each(addMod);
914 m.finalize.name = m.name + " (clean up) ";
915 mods.push(m.finalize);
920 parent.modules.each(addMod);
921 //this.allmods = mods;
925 if (onComplete) onComplete();
928 // flash it up as modal - so we store the mask!?
929 Roo.MessageBox.show({ title: 'loading' });
930 Roo.MessageBox.show({
931 title: "Please wait...",
932 msg: "Building Interface...",
940 var progressRun = function() {
945 Roo.MessageBox.updateProgress(
946 (n+1)/mods.length, "Building Interface " + (n+1) +
947 " of " + mods.length +
948 (mod.name ? (' - ' + mod.name) : '')
953 if (typeof(mod) == 'function') {
956 } else if (typeof(mod.region) == 'undefined') {
957 Roo.log("Module does not have region defined, skipping");
960 } else if (mod.parent.layout && !mod.module.disabled) {
961 // honour permname setings..
962 if (mod.permname && mod.permname.length) {
963 if (Pman.hasPerm(mod.permname, 'S')) {
964 mod.module.add(mod.parent.layout, mod.region);
967 mod.module.add(mod.parent.layout, mod.region);
973 if (n >= mods.length) {
979 progressRun.defer(10, Pman);
981 progressRun.defer(1, Pman);
987 invertColor : function(c)
991 for(var i = 0; i < 3; i++){
992 ca[i] = parseInt(c.charAt((i*2)+1) + c.charAt((i*2)+2), 16);
997 Roo.each(ca, function(hi) {
998 var h = parseInt(255-hi).toString(16);