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 if (typeof(_T) == 'undefined') { _T={};}
18 Pman = new Roo.Document(
20 /// appVersion: '1.7', // fixme = needs to be removed - use Global AppVersion
23 rightNames: { }, /// register right names here - so they can be translated and rendered.
24 buildCompleted : false, // flag to say if we are building interface..
26 'beforeload' : true, // fired after page ready, before module building.
27 'load' : true, // fired after module building
28 'authrefreshed' : true // fire on auth updated?? - should be on Login?!?!?
34 // kludge to fix firebug debugger
35 if (typeof(console) == 'undefined') {
36 console = { log : function() { } };
40 if (Ext.get('loading')) {
41 Ext.get('loading').remove();
44 Ext.state.Manager.setProvider(new Ext.state.CookieProvider());
48 if (AppLinkError.length) {
49 Ext.MessageBox.alert("Error", AppLinkError, function() {
57 if (showNewPass.length) {
58 Pman.PasswordChange.show( { passwordReset : showNewPass },
60 // fail and success we do a load...
72 if (Roo.get('loading-logo-tile')) {
73 Roo.get('loading-logo-tile').remove();
75 if (Roo.get('loading-logo-tile-top')) {
76 Roo.get('loading-logo-tile-top').remove();
78 if (Roo.get('loading-logo-bottom')) {
79 Roo.get('loading-logo-bottom').remove();
81 if (Roo.get('loading-logo-center')) {
82 Roo.get('loading-logo-center').remove();
93 //this.fireEvent('beforeload',this);
98 return; // already loaded
100 if (Ext.get('loading')) {
101 Ext.get('loading').remove();
103 if (Ext.get('loading-mask')) {
104 Ext.get('loading-mask').show();
111 Ext.MessageBox.show({
112 title: "Please wait...",
113 msg: "Building Interface...",
120 //Pman.onLoadBuild();
121 //Ext.get(document.body).mask("Building Interface");
122 //Pman.onLoadBuild.defer(100, Pman);
123 //Pman.onLoadBuild();
126 //onLoadBuild : function() {
129 this.stime = new Date();
130 this.layout = new Ext.BorderLayout(document.body, {
144 alwaysShowTabs: true,
155 this.fireEvent('beforeload',this);
159 this.layout.beginUpdate();
160 this.layout.add('north', new Ext.ContentPanel('title', 'North'));
161 var au = Pman.Login.authUser;
162 if (au.id > 0 && au.company_id_background_color.length) {
163 Ext.get('title').dom.style.backgroundColor = '#' + au.company_id_background_color;
164 Ext.get('headerInformation').dom.style.color = this.invertColor('#' + au.company_id_background_color);
166 if (au.id > 0 && au.company_id_logo_id * 1 > 0) {
167 Ext.get('headerInformation-company-logo').dom.src = baseURL +
168 '/Images/' + au.company_id_logo_id + '/' + au.company_id_logo_id_filename;
170 Ext.get('headerInformation-company-logo').dom.src = Roo.BLANK_IMAGE_URL;
173 Ext.get('headerInformation').dom.innerHTML = String.format(
174 "You are Logged in as <b>{0} ({1})</b>", // to {4} v{3}", // for <b>{2}</b>",
175 au.name, au.email, au.company_id_name,
176 AppVersion , appNameShort
180 document.title = appName + ' v' + AppVersion + ' - ' + au.company_id_name;
181 Ext.QuickTips.init();
186 //this.mainLayout.beginUpdate();
187 //var maskDom = Ext.get(document.body)._maskMsg.dom
188 this.layout.beginUpdate();
190 Pman.building = true;
192 this.buildModules(this,
195 _this.layout.getRegion('center').showPanel(0);
196 _this.layout.endUpdate();
197 _this.addTopToolbar();
199 _this.fireEvent('load',this);
207 addTopToolbar : function()
209 //console.log( "t6:" + ((new Date())-stime));
210 //this.mainLayout.endUpdate();
211 // make a new tab to hold administration stuff...
214 //console.log( "t7:" + ((new Date())-stime));
215 var se = Pman.layout.getRegion('center').tabs.stripEl;
216 var tbh = se.createChild(
217 { tag: 'td', style: 'width:100%;' });
219 var lotb = new Ext.Toolbar(tbh);
222 var tbl = se.child('table', true);
223 tbl.setAttribute('width', '100%');
226 new Ext.Toolbar.Fill(),
229 text: "Change Password",
230 cls: 'x-btn-text-icon',
231 icon: rootURL + '/Pman/templates/images/change-password.gif',
232 handler : function(){
233 Pman.PasswordChange.show({});
239 if (this.topMenuItems.length) {
241 Roo.each(this.topMenuItems, function (mi) {
249 if (this.subMenuItems.length) {
251 this.subMenuItems.sort(function (a,b) {
252 return a.seqid > b.seqid ? 1 : -1;
254 // chop off last seperator.
255 // since we always add it.. just chop of last item
256 this.subMenuItems.pop();
261 text: "Add New Item",
262 cls: 'x-btn-text-icon',
263 icon: Ext.rootURL + 'images/default/dd/drop-add.gif',
265 items : this.subMenuItems
274 cls: 'x-btn-text-icon',
275 icon: rootURL + '/Pman/templates/images/logout.gif',
276 handler: function() {
283 // this.layout.endUpdate();
287 finalize : function() {
291 window.onbeforeunload = function(e) {
292 var e = e || window.event;
293 var r = "Closing this window will loose changes, are you sure you want to do that?";
295 // For IE and Firefox
305 Ext.MessageBox.hide();
306 if (Ext.get('loading-mask')) {
307 Ext.get('loading-mask').remove();
311 this.buildCompleted = true; // now we can force refreshes on everything..
314 // does the URL indicate we want to see a system..
315 if (AppTrackOnLoad * 1 > 0) {
316 this.onLoadTrack(AppTrackOnLoad,false);
321 var forceAdmin = function(data)
323 if (!data || !data.id) {
324 Pman.Dialog.PersonStaff.show(
327 company_id : Pman.Login.authUser.company_id * 1,
328 company_id_name : Pman.Login.authUser.company_id_name
335 Ext.state.Manager.set('Pman.Login.username', data.email),
336 window.onbeforeunload = false;
337 document.location = baseURL + '?ts=' + Math.random();
340 var forceCompany = function(data) {
341 if (Pman.Login.authUser.company_id * 1 > 0) {
345 if (!data || !data.id) {
346 Pman.Dialog.Companies.show( { id : 0, isOwner : 1, comptype: 'OWNER' }, function(data) {
351 Pman.Login.authUser.company_id = data.id;
352 Pman.Login.authUser.company_id_name = data.name;
356 if (Pman.Login.authUser.id < 0) {
370 onLoadTrack : function(id,cb) {
371 this.onLoadTrackCall(id, cb, 'DocumentsCirc_');
373 onLoadTrackEdit : function(id,cb) {
374 this.onLoadTrackCall(id, cb, 'Documents_');
378 /// ----------- FIXME -----
381 onLoadTrackCall : function(id,cb, cls) {
382 Ext.get(document.body).mask("Loading Document details");
385 url: baseURL + '/Roo/Documents.html',
390 success : function(data) {
391 Ext.get(document.body).unmask();
394 switch(data.in_out) {
395 case 'IN' : cls+='In';break;
396 case 'OUT' : cls+='Out';break;
397 case 'WIP' : cls+='Wip';break;
399 Ext.MessageBox.alert("Error", "invalid in_out");
402 Pman.Dialog[cls].show(data, cb ? cb : Pman.refreshActivePanel);
405 failure: function() {
406 Ext.get(document.body).unmask();
417 * eg. has Pman.hasPerm('Admin.Admin_Tab', 'S') == showlist..
420 hasPerm: function(name, lvl) {
421 if (typeof(Pman.Login.authUser) != 'object') {
424 if (typeof(Pman.Login.authUser.perms[name]) != 'string') {
427 return Pman.Login.authUser.perms[name].indexOf(lvl) > -1;
444 processResponse : function (response)
448 res = Ext.decode(response.responseText);
450 if (typeof(res) != 'object') {
451 res = { success : false, errorMsg : res, errors : true };
453 if (typeof(res.success) == 'undefined') {
458 res = { success : false, errorMsg : response.responseText, errors : true };
462 genericDelete : function(tab,tbl) {
467 var s = tab.grid.getSelectionModel().getSelections();
469 Ext.MessageBox.alert("Error", "Select at least one Row to delete" );
473 for(var i = 0; i < s.length; i++) {
474 r.push(s[i].data.id);
477 Ext.MessageBox.confirm("Confirm", "Are you sure you want to delete that?",
482 // what about the toolbar??
483 tab.grid.getView().mainWrap.mask("Deleting");
485 url: baseURL + '/Roo/'+tbl+'.php',
488 _delete : r.join(',')
490 success: function(response) {
491 tab.grid.getView().mainWrap.unmask();
493 tab.paging.onClick('refresh');
494 } else if (tab.refresh) {
496 } else if (tab.grid.footer && tab.grid.footer.onClick) {
497 // new xtype built grids
498 tab.grid.footer.onClick('refresh');
500 tab.grid.getDataSource().load();
506 failure: function(act) {
507 tab.grid.getView().mainWrap.unmask();
508 Ext.MessageBox.alert("Error", "Error Deleting");
515 refreshActivePanel : function() {
516 var actpan = this.layout.getRegion('center').getActivePanel();
517 if (actpan.controller && actpan.controller.paging) {
518 actpan.controller.paging.onClick('refresh');
522 var agid = Pman.layout.getRegion('center').getActivePanel().id;
526 Pman.Tab[agid].paging.onClick('refresh');
528 toCidV : function(data) {
529 return 'C' + data.in_out.substring(0,1) + data.cid;
532 standardActionFailed : function(f, act, cb) {
534 if (act.failureType == 'client') {
535 Ext.MessageBox.alert("Error", "Please Correct all the errors in red", cb);
538 if (act.failureType == 'connect') {
539 Ext.MessageBox.alert("Error", "Problem Connecting to Server - please try again.", cb);
543 if (act.type == 'submit') {
545 Ext.MessageBox.alert("Error", typeof(act.result.errorMsg) == 'string' ?
546 String.format('{0}', act.result.errorMsg) :
547 "Saving failed = fix errors and try again", cb);
551 // what about load failing..
552 Ext.MessageBox.alert("Error", "Error loading details",cb);
556 * similar to Ext.Ajax, but handles our responses better...
560 * c.failure() == failure function..
561 * c.success(data) == success function..
565 request : function(c) {
566 var r= new Roo.data.Connection({
567 timeout : typeof(c.timeout) == 'undefined' ? 30000 c.timeout
574 success: function(response, opts) { // check successfull...
576 var res = Pman.processResponse(response);
578 if (!res.success) { // error!
580 if (true === c.failure.call(this,response, opts)) {
584 Roo.MessageBox.hide();
585 Ext.MessageBox.alert("Error", res.errorMsg ? res.errorMsg : "Error Sending");
589 c.success.call(this, res.data);
593 failure : function(response, opts) { // check successfull...
596 if (true === c.failure.call(this,response, opts)) {
600 Roo.MessageBox.hide();
601 Roo.MessageBox.alert("Error", "Connection timed out sending");
602 console.log(response);
611 createCsvFrame: function()
615 document.body.removeChild(this.csvFrame);
619 this.csvFrame = document.createElement('iframe');
620 this.csvFrame.id = id;
621 this.csvFrame.name = id;
622 this.csvFrame.className = 'x-hidden';
624 this.csvFrame.src = Ext.SSL_SECURE_URL;
626 document.body.appendChild(this.csvFrame);
629 document.frames[id].name = id;
642 download : function(c) {
645 // as ie seems buggy...
646 window.open( c.url + '?' + Roo.urlEncode(c.params || {}), '_blank');
651 this.createCsvFrame();
653 var r = { responseText : "", responseXML : null };
655 var frame = this.csvFrame;
659 frame.contentWindow.document :
660 (frame.contentDocument || window.frames[this.csvFrame.id].document);
662 if(doc && doc.body && doc.body.innerHTML.length){
663 // alert(doc.body.innerHTML);
664 Ext.MessageBox.alert("Error download",doc.body.innerHTML);
671 Ext.EventManager.removeListener(frame, 'load', cb, this);
674 Ext.EventManager.on( this.csvFrame, 'load', cb, this);
675 this.csvFrame.src = c.url;
677 downloadRevision : function(doc, rev)
680 url: baseURL + '/Documents/Doc/DownloadRev/'+ doc.id + '/' + rev + '/' +
681 doc.project_id_code + '-' + doc.cidV + '-' + rev + '-' + doc.filename
685 exportCSV : function(c) {
686 //this.createCsvFrame();
687 for(var i=0;i < c.csvFormat.length;i++) {
688 c.params['csvCols['+i+']'] = c.csvFormat[i][0];
689 c.params['csvTitles['+i+']'] = c.csvFormat[i][1];
693 c.url += '?' + Ext.urlEncode(c.params);
697 prettyDate : function (value)
699 if (typeof(value) == 'string') {
700 var ds = Date.parseDate(value, 'Y-m-d H:i:s');
702 return this.prettyDate(ds);
704 ds = Date.parseDate(value, 'Y-m-d');
706 return this.prettyDate(ds);
715 var daysSince = Math.floor(td.getElapsed(value) / (1000 * 60*60*24));
717 return value.dateFormat('D H:i');
721 if (td.dateFormat('m') == value.dateFormat('m')) {
722 return value.dateFormat('dS D');
725 if (td.dateFormat('Y') == value.dateFormat('Y')) {
726 return value.dateFormat('dS M');
728 return value.dateFormat('d M Y');
730 loadException : function(a,b,c,d)
732 if (d && d.authFailure) {
736 Roo.MessageBox.alert("Problem Loading Data", a.message || c.statusText);
742 * Routine to flash alerts in the title bar..
747 notifyActive : false,
749 notifyTitle: function(msg)
751 if (this.notifyActive ) {
756 var stopper = function() {
758 document.title = oldtitle;
761 Roo.get(document.body).on('mousemove', stopper, this);
762 var oldtitle = document.title;
765 var ivl = window.setInterval(function() {
768 Roo.get(document.body).un('mousemove', stopper, this);
769 _this.notifyActive = false;
770 document.title = oldtitle;
771 window.clearInterval(ivl);
775 document.title = s ? msg : oldtitle;
777 }, 1000); // every 120 secs = 2mins..
778 document.title = msg;
789 modKey : '00-admin-xxxx',
790 module : Pman.Tab.projectMgr,
796 register : function(obj) {
798 if (obj.parent === false) {
799 //console.log('skip module (no parent)' + obj.modkey);
805 if (!obj.parent.modules) {
806 obj.parent.modules = new Roo.util.MixedCollection(false, function(o) { return o.modKey });
809 obj.parent.modules.add(obj);
813 buildModules : function(parent, onComplete)
817 var cmp = function(a,b) {
818 return String(a).toUpperCase() > String(b).toUpperCase() ? 1 : -1;
821 if (!parent.modules) {
824 parent.modules.keySort('ASC', cmp );
828 // add modules to their parents..
829 var addMod = function(m) {
830 // console.log(m.modKey);
833 if (m.module.modules) {
834 m.module.modules.keySort('ASC', cmp );
835 m.module.modules.each(addMod);
838 m.finalize.name = m.name + " (clean up) ";
839 mods.push(m.finalize);
844 parent.modules.each(addMod);
845 //this.allmods = mods;
849 if (onComplete) onComplete();
852 // flash it up as modal - so we store the mask!?
853 Ext.MessageBox.show({ title: 'loading' });
854 Ext.MessageBox.show({
855 title: "Please wait...",
856 msg: "Building Interface...",
864 var progressRun = function() {
869 Ext.MessageBox.updateProgress(
870 (n+1)/mods.length, "Building Interface " + (n+1) +
871 " of " + mods.length +
872 (mod.name ? (' - ' + mod.name) : '')
877 if (typeof(mod) == 'function') {
881 if (mod.parent.layout && !mod.module.disabled) {
882 mod.module.add(mod.parent.layout, mod.region);
889 if (n >= mods.length) {
895 progressRun.defer(10, Pman);
897 progressRun.defer(1, Pman);
903 gtranslate : function(str, src, dest, cb) {
907 var x = new Roo.data.ScriptTagProxy({
908 url: 'http://ajax.googleapis.com/ajax/services/language/translate',
909 callbackParam : 'callback'
915 langpair : src + '|' +dest
918 readRecords : function (o) {
919 if (!o.responseData) {
922 return o.responseData.translatedText;
935 invertColor : function(c)
939 for(var i = 0; i < 3; i++){
940 ca[i] = parseInt(c.charAt((i*2)+1) + c.charAt((i*2)+2), 16);
945 Roo.each(ca, function(hi) {
946 var h = parseInt(255-hi).toString(16);