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={};}
24 Pman = new Roo.Document(
26 /// appVersion: '1.7', // fixme = needs to be removed - use Global AppVersion
29 rightNames: { }, /// register right names here - so they can be translated and rendered.
31 * @property {Roo.menu.Menu} pulldownMenu - the 'add menu pulldown, you can use it to add items..
37 buildCompleted : false, // flag to say if we are building interface..
39 'beforeload' : true, // fired after page ready, before module building.
40 'load' : true, // fired after module building
41 'authrefreshed' : true // fire on auth updated?? - should be on Login?!?!?
47 // kludge to fix firebug debugger
48 if (typeof(console) == 'undefined') {
49 console = { log : function() { } };
53 if (Roo.get('loading')) {
54 Roo.get('loading').remove();
57 Roo.state.Manager.setProvider(new Roo.state.CookieProvider());
61 if (AppLinkError.length) {
62 Roo.MessageBox.alert("Error", AppLinkError, function() {
70 if (showNewPass.length) {
71 Pman.PasswordChange.show( { passwordReset : showNewPass },
73 // fail and success we do a load...
85 if (Roo.get('loading-logo-tile')) {
86 Roo.get('loading-logo-tile').remove();
88 if (Roo.get('loading-logo-tile-top')) {
89 Roo.get('loading-logo-tile-top').remove();
91 if (Roo.get('loading-logo-bottom')) {
92 Roo.get('loading-logo-bottom').remove();
94 if (Roo.get('loading-logo-center')) {
95 Roo.get('loading-logo-center').remove();
106 //this.fireEvent('beforeload',this);
111 return; // already loaded
113 if (Roo.get('loading')) {
114 Roo.get('loading').remove();
116 if (Roo.get('loading-mask')) {
117 Roo.get('loading-mask').show();
122 this.stime = new Date();
123 this.layout = new Roo.BorderLayout(document.body, {
137 alwaysShowTabs: true,
150 this.fireEvent('beforeload',this);
154 this.layout.beginUpdate();
155 this.layout.add('north', new Roo.ContentPanel('title', 'North'));
156 var au = Pman.Login.authUser;
157 if (au.id > 0 && au.company_id_background_color && au.company_id_background_color.length) {
158 Roo.get('title').dom.style.backgroundColor = '#' + au.company_id_background_color;
159 Roo.get('headerInformation').dom.style.color = this.invertColor('#' + au.company_id_background_color);
161 if (au.id > 0 && au.company_id_logo_id * 1 > 0) {
162 Roo.get('headerInformation-company-logo').dom.src = baseURL +
163 '/Images/' + au.company_id_logo_id + '/' + au.company_id_logo_id_filename;
165 Roo.get('headerInformation-company-logo').dom.src = Roo.BLANK_IMAGE_URL;
168 Roo.get('headerInformation').dom.innerHTML = String.format(
169 "You are Logged in as <b>{0} ({1})</b>", // to {4} v{3}", // for <b>{2}</b>",
170 au.name, au.email, au.company_id_name,
171 AppVersion , appNameShort
175 document.title = appName + ' v' + AppVersion + ' - ' + au.company_id_name;
176 Roo.QuickTips.init();
181 //this.mainLayout.beginUpdate();
182 //var maskDom = Roo.get(document.body)._maskMsg.dom
183 this.layout.beginUpdate();
185 Pman.building = true;
187 this.buildModules(this,
190 _this.layout.getRegion('center').showPanel(0);
191 _this.layout.endUpdate();
192 _this.addTopToolbar();
194 _this.fireEvent('load',this);
196 if (!_this.layout.getRegion('south').panels.length) {
197 _this.layout.getRegion('south').hide();
208 addTopToolbar : function()
210 //console.log( "t6:" + ((new Date())-stime));
211 //this.mainLayout.endUpdate();
212 // make a new tab to hold administration stuff...
215 //console.log( "t7:" + ((new Date())-stime));
216 var se = Pman.layout.getRegion('center').tabs.stripEl;
217 var tbh = se.createChild(
218 { tag: 'td', style: 'width:100%;' });
220 var lotb = new Roo.Toolbar(tbh);
223 var tbl = se.child('table', true);
224 tbl.setAttribute('width', '100%');
227 new Roo.Toolbar.Fill(),
230 text: "Change Password",
231 cls: 'x-btn-text-icon',
232 icon: rootURL + '/Pman/templates/images/change-password.gif',
233 handler : function(){
234 Pman.PasswordChange.show({});
240 if (this.topMenuItems.length) {
242 Roo.each(this.topMenuItems, function (mi) {
250 if (this.subMenuItems.length) {
252 this.subMenuItems.sort(function (a,b) {
253 return a.seqid > b.seqid ? 1 : -1;
255 // chop off last seperator.
256 // since we always add it.. just chop of last item
257 this.subMenuItems.pop();
259 var btn = new Roo.Toolbar.Button(
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
269 this.pulldownMenu = btn.menu;
277 cls: 'x-btn-text-icon',
278 icon: rootURL + '/Pman/templates/images/logout.gif',
279 handler: function() {
286 // this.layout.endUpdate();
290 finalize : function() {
294 window.onbeforeunload = function(e) {
295 e = e || window.event;
296 var r = "Closing this window will loose changes, are you sure you want to do that?";
298 // For IE and Firefox
308 Roo.MessageBox.hide();
309 if (Roo.get('loading-mask')) {
310 Roo.get('loading-mask').remove();
314 this.buildCompleted = true; // now we can force refreshes on everything..
317 // does the URL indicate we want to see a system..
318 if (AppTrackOnLoad * 1 > 0) {
319 this.onLoadTrack(AppTrackOnLoad,false);
324 var forceAdmin = function(data)
326 if (!data || !data.id) {
327 //Roo.log("Force Admin");
328 Pman.Dialog.PersonStaff.show(
331 company_id : Pman.Login.authUser.company_id_id * 1,
332 company_id_name : Pman.Login.authUser.company_id_name
339 Roo.state.Manager.set('Pman.Login.username', data.email),
340 window.onbeforeunload = false;
341 document.location = baseURL + '?ts=' + Math.random();
344 var forceCompany = function(data) {
345 if (Pman.Login.authUser.company_id * 1 > 0) {
349 if (!data || !data.id) {
350 Pman.Dialog.Companies.show( { id : 0, isOwner : 1, comptype: 'OWNER' }, function(data) {
355 Pman.Login.authUser.company_id_id = data.id;
356 Pman.Login.authUser.company_id = data.id;
357 Pman.Login.authUser.company_id_name = data.name;
361 if (Pman.Login.authUser.id < 0) {
362 // admin company has been created - create the user..
363 if (Pman.Login.authUser.company_id_id* 1 > 0) {
381 onLoadTrack : function(id,cb) {
382 this.onLoadTrackCall(id, cb, 'DocumentsCirc_');
384 onLoadTrackEdit : function(id,cb) {
385 this.onLoadTrackCall(id, cb, 'Documents_');
389 /// ----------- FIXME -----
392 onLoadTrackCall : function(id,cb, cls) {
393 Roo.get(document.body).mask("Loading Document details");
396 url: baseURL + '/Roo/Documents.html',
401 success : function(data) {
402 Roo.get(document.body).unmask();
405 switch(data.in_out) {
406 case 'IN' : cls+='In';break;
407 case 'OUT' : cls+='Out';break;
408 case 'WIP' : cls+='Wip';break;
410 Roo.MessageBox.alert("Error", "invalid in_out");
413 Pman.Dialog[cls].show(data, cb ? cb : Pman.refreshActivePanel);
416 failure: function() {
417 Roo.get(document.body).unmask();
427 refreshActivePanel : function() {
428 var actpan = this.layout.getRegion('center').getActivePanel();
429 if (actpan.controller && actpan.controller.paging) {
430 actpan.controller.paging.onClick('refresh');
434 var agid = Pman.layout.getRegion('center').getActivePanel().id;
438 Pman.Tab[agid].paging.onClick('refresh');
440 toCidV : function(data) {
441 return 'C' + data.in_out.substring(0,1) + data.cid;
447 * Does the authenticated user have permission to see this.
449 * @param {String} name the [Module].[permission] to check for
450 * @param {Char} lvl - which type of permission to use (eg. S=show...)
451 * @returns {Boolean} tue indicates permission allowed
453 hasPerm: function(name, lvl) {
455 (typeof(Pman.Login.authUser) != 'object')
457 (typeof(Pman.Login.authUser.perms) != 'object')
459 (typeof(Pman.Login.authUser.perms[name]) != 'string')
464 return Pman.Login.authUser.perms[name].indexOf(lvl) > -1;
469 * Is there a permission defined for this (used by module registration.)
471 * @param {String} name the [Module].[permission] to check for
472 * @returns {Boolean} tue indicates permission exists.
474 hasPermExists: function(name) {
476 (typeof(Pman.Login.authUser) != 'object')
478 (typeof(Pman.Login.authUser.perms) != 'object')
480 (typeof(Pman.Login.authUser.perms[name]) != 'string')
498 processResponse : function (response)
502 res = Roo.decode(response.responseText);
504 if (typeof(res) != 'object') {
505 res = { success : false, errorMsg : res, errors : true };
507 if (typeof(res.success) == 'undefined') {
512 res = { success : false, errorMsg : response.responseText, errors : true };
516 genericDelete : function(tab,tbl) {
521 var s = tab.grid.getSelectionModel().getSelections();
523 Roo.MessageBox.alert("Error", "Select at least one Row to delete" );
527 for(var i = 0; i < s.length; i++) {
528 r.push(s[i].data.id);
531 Roo.MessageBox.confirm("Confirm", "Are you sure you want to delete that?",
536 // what about the toolbar??
537 tab.grid.getView().mainWrap.mask("Deleting");
539 url: baseURL + '/Roo/'+tbl+'.php',
542 _delete : r.join(',')
544 success: function(response) {
545 tab.grid.getView().mainWrap.unmask();
547 tab.paging.onClick('refresh');
548 } else if (tab.refresh) {
550 } else if (tab.grid.footer && tab.grid.footer.onClick) {
551 // new xtype built grids
552 tab.grid.footer.onClick('refresh');
554 tab.grid.getDataSource().load();
560 failure: function(act) {
561 tab.grid.getView().mainWrap.unmask();
562 Roo.MessageBox.alert("Error", "Error Deleting");
573 standardActionFailed : function(f, act, cb) {
575 if (act.failureType == 'client') {
576 Roo.MessageBox.alert("Error", "Please Correct all the errors in red", cb);
579 if (act.failureType == 'connect') {
580 Roo.MessageBox.alert("Error", "Problem Connecting to Server - please try again.", cb);
584 if (act.type == 'submit') {
586 Roo.MessageBox.alert("Error", typeof(act.result.errorMsg) == 'string' ?
587 String.format('{0}', act.result.errorMsg) :
588 "Saving failed = fix errors and try again", cb);
592 // what about load failing..
593 Roo.MessageBox.alert("Error", "Error loading details",cb);
596 * Depreciated - USE new Pman.Request
600 request : function(c) {
601 var r= new Roo.data.Connection({
602 timeout : typeof(c.timeout) == 'undefined' ? 30000 : c.timeout
609 success: function(response, opts) { // check successfull...
611 var res = Pman.processResponse(response);
613 if (!res.success) { // error!
615 if (true === c.failure.call(this,response, opts)) {
619 Roo.MessageBox.hide();
620 Roo.MessageBox.alert("Error", res.errorMsg ? res.errorMsg : "Error Sending");
624 c.success.call(this, res.data);
628 failure : function(response, opts) { // check successfull...
631 if (true === c.failure.call(this,response, opts)) {
635 Roo.MessageBox.hide();
636 Roo.MessageBox.alert("Error", "Connection timed out sending");
646 // depreciated - use Pman.Download()
648 download : function(c) {
650 return new Pman.Download(c);
653 // fixme - move to document manager...
654 downloadRevision : function(doc, rev)
657 url: baseURL + '/Documents/Doc/DownloadRev/'+ doc.id + '/' + rev + '/' +
658 doc.project_id_code + '-' + doc.cidV + '-' + rev + '-' + doc.filename
664 exportCSV : function(c) {
666 for(var i=0;i < c.csvFormat.length;i++) {
667 c.params['csvCols['+i+']'] = c.csvFormat[i][0];
668 c.params['csvTitles['+i+']'] = c.csvFormat[i][1];
670 c.url += '?' + Roo.urlEncode(c.params);
676 prettyDate : function (value)
678 if (typeof(value) == 'string') {
679 var ds = Date.parseDate(value, 'Y-m-d H:i:s');
681 return this.prettyDate(ds);
683 ds = Date.parseDate(value, 'Y-m-d');
685 return this.prettyDate(ds);
694 var daysSince = Math.floor(td.getElapsed(value) / (1000 * 60*60*24));
696 return value.dateFormat('D H:i');
700 if (td.dateFormat('m') == value.dateFormat('m')) {
701 return value.dateFormat('dS D');
704 if (td.dateFormat('Y') == value.dateFormat('Y')) {
705 return value.dateFormat('dS M');
707 return value.dateFormat('d M Y');
709 loadException : function(a,b,c,d)
711 if (d && d.authFailure) {
715 Roo.MessageBox.alert("Problem Loading Data", a.message || c.statusText);
721 * Routine to flash alerts in the title bar..
726 notifyActive : false,
728 notifyTitle: function(msg)
730 if (this.notifyActive ) {
735 var stopper = function() {
737 document.title = oldtitle;
740 Roo.get(document.body).on('mousemove', stopper, this);
741 var oldtitle = document.title;
744 var ivl = window.setInterval(function() {
747 Roo.get(document.body).un('mousemove', stopper, this);
748 _this.notifyActive = false;
749 document.title = oldtitle;
750 window.clearInterval(ivl);
754 document.title = s ? msg : oldtitle;
756 }, 1000); // every 120 secs = 2mins..
757 document.title = msg;
763 * @property {Array} appModules - array based on AppModules global
772 modKey : '00-admin-xxxx',
773 module : Pman.Tab.projectMgr, << really a components..
774 part : [ 'Admin', 'ProjectManager' ]
781 register : function(obj)
786 if (!this.appModules === false) {
787 this.appModules = typeof(AppModules ) == 'undefined'? [] :
788 AppModules.split(',');
793 // ignore registration of objects which are disabled.
794 // global supplied by master.html
795 appDisabled = typeof(appDisabled) == 'undefined' ? [] : appDisabled;
799 // previously we did not a good naming policy for module and parts
800 // most things that are called module here, really are 'parts'
801 // new versions should have 'part' as [ module : part ]
804 if (typeof(obj.part) != 'undefined') {
806 var permname = obj.part.join('.');
807 // we now have permission...
808 // obj.moduleOwner '.' lname
810 if (this.hasPermExists(permname) && !this.hasPerm(permname,'S')) {
811 // it's a turned off permission...
812 Roo.log(permname + " is Disabled for this user");
815 if (appDisabled.indexOf(permname) > -1) {
816 Roo.log(permname + " is Disabled for this site");
828 if (obj.parent === false) {
829 //console.log('skip module (no parent)' + obj.modkey);
832 // this is an error condition - the parent does not exist..
833 // technically it should not happen..
834 console.log("Parent is missing");
838 if (!obj.parent.modules) {
839 obj.parent.modules = new Roo.util.MixedCollection(false, function(o) { return o.modKey });
842 obj.parent.modules.add(obj);
846 buildModules : function(parent, onComplete)
850 var cmp = function(a,b) {
851 return String(a).toUpperCase() > String(b).toUpperCase() ? 1 : -1;
854 if (!parent.modules) {
857 parent.modules.keySort('ASC', cmp );
861 // add modules to their parents..
862 var addMod = function(m) {
863 // console.log(m.modKey);
866 if (m.module.modules) {
867 m.module.modules.keySort('ASC', cmp );
868 m.module.modules.each(addMod);
871 m.finalize.name = m.name + " (clean up) ";
872 mods.push(m.finalize);
877 parent.modules.each(addMod);
878 //this.allmods = mods;
882 if (onComplete) onComplete();
885 // flash it up as modal - so we store the mask!?
886 Roo.MessageBox.show({ title: 'loading' });
887 Roo.MessageBox.show({
888 title: "Please wait...",
889 msg: "Building Interface...",
897 var progressRun = function() {
902 Roo.MessageBox.updateProgress(
903 (n+1)/mods.length, "Building Interface " + (n+1) +
904 " of " + mods.length +
905 (mod.name ? (' - ' + mod.name) : '')
910 if (typeof(mod) == 'function') {
913 } else if (mod.parent.layout && !mod.module.disabled) {
914 // honour permname setings..
915 if (mod.permname && mod.permname.length) {
916 if (Pman.hasPerm(mod.permname, 'S')) {
917 mod.module.add(mod.parent.layout, mod.region);
920 mod.module.add(mod.parent.layout, mod.region);
928 if (n >= mods.length) {
934 progressRun.defer(10, Pman);
936 progressRun.defer(1, Pman);
942 invertColor : function(c)
946 for(var i = 0; i < 3; i++){
947 ca[i] = parseInt(c.charAt((i*2)+1) + c.charAt((i*2)+2), 16);
952 Roo.each(ca, function(hi) {
953 var h = parseInt(255-hi).toString(16);