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 (Roo.get('loading')) {
41 Roo.get('loading').remove();
44 Roo.state.Manager.setProvider(new Roo.state.CookieProvider());
48 if (AppLinkError.length) {
49 Roo.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 (Roo.get('loading')) {
101 Roo.get('loading').remove();
103 if (Roo.get('loading-mask')) {
104 Roo.get('loading-mask').show();
111 Roo.MessageBox.show({
112 title: "Please wait...",
113 msg: "Building Interface...",
120 //Pman.onLoadBuild();
121 //Roo.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 Roo.BorderLayout(document.body, {
144 alwaysShowTabs: true,
155 this.fireEvent('beforeload',this);
159 this.layout.beginUpdate();
160 this.layout.add('north', new Roo.ContentPanel('title', 'North'));
161 var au = Pman.Login.authUser;
162 if (au.id > 0 && au.company_id_background_color.length) {
163 Roo.get('title').dom.style.backgroundColor = '#' + au.company_id_background_color;
164 Roo.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 Roo.get('headerInformation-company-logo').dom.src = baseURL +
168 '/Images/' + au.company_id_logo_id + '/' + au.company_id_logo_id_filename;
170 Roo.get('headerInformation-company-logo').dom.src = Roo.BLANK_IMAGE_URL;
173 Roo.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 Roo.QuickTips.init();
186 //this.mainLayout.beginUpdate();
187 //var maskDom = Roo.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 Roo.Toolbar(tbh);
222 var tbl = se.child('table', true);
223 tbl.setAttribute('width', '100%');
226 new Roo.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: Roo.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 Roo.MessageBox.hide();
306 if (Roo.get('loading-mask')) {
307 Roo.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 Roo.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 Roo.get(document.body).mask("Loading Document details");
385 url: baseURL + '/Roo/Documents.html',
390 success : function(data) {
391 Roo.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 Roo.MessageBox.alert("Error", "invalid in_out");
402 Pman.Dialog[cls].show(data, cb ? cb : Pman.refreshActivePanel);
405 failure: function() {
406 Roo.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 = Roo.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 Roo.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 Roo.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 Roo.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 Roo.MessageBox.alert("Error", "Please Correct all the errors in red", cb);
538 if (act.failureType == 'connect') {
539 Roo.MessageBox.alert("Error", "Problem Connecting to Server - please try again.", cb);
543 if (act.type == 'submit') {
545 Roo.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 Roo.MessageBox.alert("Error", "Error loading details",cb);
556 * similar to Roo.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 Roo.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");
611 // depreciated - use Pman.Download()
613 download : function(c) {
615 return new Pman.Download(c);
618 // fixme - move to document manager...
619 downloadRevision : function(doc, rev)
622 url: baseURL + '/Documents/Doc/DownloadRev/'+ doc.id + '/' + rev + '/' +
623 doc.project_id_code + '-' + doc.cidV + '-' + rev + '-' + doc.filename
629 exportCSV : function(c) {
631 for(var i=0;i < c.csvFormat.length;i++) {
632 c.params['csvCols['+i+']'] = c.csvFormat[i][0];
633 c.params['csvTitles['+i+']'] = c.csvFormat[i][1];
635 c.url += '?' + Roo.urlEncode(c.params);
641 prettyDate : function (value)
643 if (typeof(value) == 'string') {
644 var ds = Date.parseDate(value, 'Y-m-d H:i:s');
646 return this.prettyDate(ds);
648 ds = Date.parseDate(value, 'Y-m-d');
650 return this.prettyDate(ds);
659 var daysSince = Math.floor(td.getElapsed(value) / (1000 * 60*60*24));
661 return value.dateFormat('D H:i');
665 if (td.dateFormat('m') == value.dateFormat('m')) {
666 return value.dateFormat('dS D');
669 if (td.dateFormat('Y') == value.dateFormat('Y')) {
670 return value.dateFormat('dS M');
672 return value.dateFormat('d M Y');
674 loadException : function(a,b,c,d)
676 if (d && d.authFailure) {
680 Roo.MessageBox.alert("Problem Loading Data", a.message || c.statusText);
686 * Routine to flash alerts in the title bar..
691 notifyActive : false,
693 notifyTitle: function(msg)
695 if (this.notifyActive ) {
700 var stopper = function() {
702 document.title = oldtitle;
705 Roo.get(document.body).on('mousemove', stopper, this);
706 var oldtitle = document.title;
709 var ivl = window.setInterval(function() {
712 Roo.get(document.body).un('mousemove', stopper, this);
713 _this.notifyActive = false;
714 document.title = oldtitle;
715 window.clearInterval(ivl);
719 document.title = s ? msg : oldtitle;
721 }, 1000); // every 120 secs = 2mins..
722 document.title = msg;
733 modKey : '00-admin-xxxx',
734 module : Pman.Tab.projectMgr,
740 register : function(obj) {
742 if (obj.parent === false) {
743 //console.log('skip module (no parent)' + obj.modkey);
749 if (!obj.parent.modules) {
750 obj.parent.modules = new Roo.util.MixedCollection(false, function(o) { return o.modKey });
753 obj.parent.modules.add(obj);
757 buildModules : function(parent, onComplete)
761 var cmp = function(a,b) {
762 return String(a).toUpperCase() > String(b).toUpperCase() ? 1 : -1;
765 if (!parent.modules) {
768 parent.modules.keySort('ASC', cmp );
772 // add modules to their parents..
773 var addMod = function(m) {
774 // console.log(m.modKey);
777 if (m.module.modules) {
778 m.module.modules.keySort('ASC', cmp );
779 m.module.modules.each(addMod);
782 m.finalize.name = m.name + " (clean up) ";
783 mods.push(m.finalize);
788 parent.modules.each(addMod);
789 //this.allmods = mods;
793 if (onComplete) onComplete();
796 // flash it up as modal - so we store the mask!?
797 Roo.MessageBox.show({ title: 'loading' });
798 Roo.MessageBox.show({
799 title: "Please wait...",
800 msg: "Building Interface...",
808 var progressRun = function() {
813 Roo.MessageBox.updateProgress(
814 (n+1)/mods.length, "Building Interface " + (n+1) +
815 " of " + mods.length +
816 (mod.name ? (' - ' + mod.name) : '')
821 if (typeof(mod) == 'function') {
825 if (mod.parent.layout && !mod.module.disabled) {
826 mod.module.add(mod.parent.layout, mod.region);
833 if (n >= mods.length) {
839 progressRun.defer(10, Pman);
841 progressRun.defer(1, Pman);
847 gtranslate : function(str, src, dest, cb) {
851 var x = new Roo.data.ScriptTagProxy({
852 url: 'http://ajax.googleapis.com/ajax/services/language/translate',
853 callbackParam : 'callback'
859 langpair : src + '|' +dest
862 readRecords : function (o) {
863 if (!o.responseData) {
866 return o.responseData.translatedText;
879 invertColor : function(c)
883 for(var i = 0; i < 3; i++){
884 ca[i] = parseInt(c.charAt((i*2)+1) + c.charAt((i*2)+2), 16);
889 Roo.each(ca, function(hi) {
890 var h = parseInt(255-hi).toString(16);