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,
152 this.fireEvent('beforeload',this);
156 this.layout.beginUpdate();
157 this.layout.add('north', new Roo.ContentPanel('title', 'North'));
158 var au = Pman.Login.authUser;
159 if (au.id > 0 && au.company_id_background_color && au.company_id_background_color.length) {
160 Roo.get('title').dom.style.backgroundColor = '#' + au.company_id_background_color;
161 Roo.get('headerInformation').dom.style.color = this.invertColor('#' + au.company_id_background_color);
163 if (au.id > 0 && au.company_id_logo_id * 1 > 0) {
164 Roo.get('headerInformation-company-logo').dom.src = baseURL +
165 '/Images/' + au.company_id_logo_id + '/' + au.company_id_logo_id_filename;
167 Roo.get('headerInformation-company-logo').dom.src = Roo.BLANK_IMAGE_URL;
170 Roo.get('headerInformation').dom.innerHTML = String.format(
171 "You are Logged in as <b>{0} ({1})</b>", // to {4} v{3}", // for <b>{2}</b>",
172 au.name, au.email, au.company_id_name,
173 AppVersion , appNameShort
177 document.title = appName + ' v' + AppVersion + ' - ' + au.company_id_name;
178 Roo.QuickTips.init();
183 //this.mainLayout.beginUpdate();
184 //var maskDom = Roo.get(document.body)._maskMsg.dom
185 this.layout.beginUpdate();
187 Pman.building = true;
189 this.buildModules(this,
192 _this.layout.getRegion('center').showPanel(0);
193 _this.layout.endUpdate();
194 _this.addTopToolbar();
196 _this.fireEvent('load',this);
198 if (!_this.layout.getRegion('south').panels.length) {
199 _this.layout.getRegion('south').hide();
210 addTopToolbar : function()
212 //console.log( "t6:" + ((new Date())-stime));
213 //this.mainLayout.endUpdate();
214 // make a new tab to hold administration stuff...
217 //console.log( "t7:" + ((new Date())-stime));
218 var se = Pman.layout.getRegion('center').tabs.stripEl;
219 var tbh = se.createChild(
220 { tag: 'td', style: 'width:100%;' });
222 var lotb = new Roo.Toolbar(tbh);
225 var tbl = se.child('table', true);
226 tbl.setAttribute('width', '100%');
229 new Roo.Toolbar.Fill(),
232 text: "Change Password",
233 cls: 'x-btn-text-icon',
234 icon: rootURL + '/Pman/templates/images/change-password.gif',
235 handler : function(){
236 Pman.PasswordChange.show({});
242 if (this.topMenuItems.length) {
244 Roo.each(this.topMenuItems, function (mi) {
252 if (this.subMenuItems.length) {
254 this.subMenuItems.sort(function (a,b) {
255 return a.seqid > b.seqid ? 1 : -1;
257 // chop off last seperator.
258 // since we always add it.. just chop of last item
259 this.subMenuItems.pop();
261 var btn = new Roo.Toolbar.Button(
263 text: "Add New Item",
264 cls: 'x-btn-text-icon',
265 icon: Roo.rootURL + 'images/default/dd/drop-add.gif',
267 items : this.subMenuItems
271 this.pulldownMenu = btn.menu;
279 cls: 'x-btn-text-icon',
280 icon: rootURL + '/Pman/templates/images/logout.gif',
281 handler: function() {
288 // this.layout.endUpdate();
292 finalize : function() {
296 window.onbeforeunload = function(e) {
297 e = e || window.event;
298 var r = "Closing this window will loose changes, are you sure you want to do that?";
300 // For IE and Firefox
310 Roo.MessageBox.hide();
311 if (Roo.get('loading-mask')) {
312 Roo.get('loading-mask').remove();
316 this.buildCompleted = true; // now we can force refreshes on everything..
319 // does the URL indicate we want to see a system..
320 if (AppTrackOnLoad * 1 > 0) {
321 this.onLoadTrack(AppTrackOnLoad,false);
326 var forceAdmin = function(data)
328 if (!data || !data.id) {
329 //Roo.log("Force Admin");
330 Pman.Dialog.PersonStaff.show(
333 company_id : Pman.Login.authUser.company_id_id * 1,
334 company_id_name : Pman.Login.authUser.company_id_name
341 Roo.state.Manager.set('Pman.Login.username', data.email),
342 window.onbeforeunload = false;
343 document.location = baseURL + '?ts=' + Math.random();
346 var forceCompany = function(data) {
347 if (Pman.Login.authUser.company_id * 1 > 0) {
351 if (!data || !data.id) {
352 Pman.Dialog.Companies.show( { id : 0, isOwner : 1, comptype: 'OWNER' }, function(data) {
357 Pman.Login.authUser.company_id_id = data.id;
358 Pman.Login.authUser.company_id = data.id;
359 Pman.Login.authUser.company_id_name = data.name;
363 if (Pman.Login.authUser.id < 0) {
364 // admin company has been created - create the user..
365 if (Pman.Login.authUser.company_id_id* 1 > 0) {
383 onLoadTrack : function(id,cb) {
384 this.onLoadTrackCall(id, cb, 'DocumentsCirc_');
386 onLoadTrackEdit : function(id,cb) {
387 this.onLoadTrackCall(id, cb, 'Documents_');
391 /// ----------- FIXME -----
394 onLoadTrackCall : function(id,cb, cls) {
395 Roo.get(document.body).mask("Loading Document details");
398 url: baseURL + '/Roo/Documents.html',
403 success : function(data) {
404 Roo.get(document.body).unmask();
407 switch(data.in_out) {
408 case 'IN' : cls+='In';break;
409 case 'OUT' : cls+='Out';break;
410 case 'WIP' : cls+='Wip';break;
412 Roo.MessageBox.alert("Error", "invalid in_out");
415 Pman.Dialog[cls].show(data, cb ? cb : Pman.refreshActivePanel);
418 failure: function() {
419 Roo.get(document.body).unmask();
429 refreshActivePanel : function() {
430 var actpan = this.layout.getRegion('center').getActivePanel();
431 if (actpan.controller && actpan.controller.paging) {
432 actpan.controller.paging.onClick('refresh');
436 var agid = Pman.layout.getRegion('center').getActivePanel().id;
440 Pman.Tab[agid].paging.onClick('refresh');
442 toCidV : function(data) {
443 return 'C' + data.in_out.substring(0,1) + data.cid;
449 * Does the authenticated user have permission to see this.
451 * @param {String} name the [Module].[permission] to check for
452 * @param {Char} lvl - which type of permission to use (eg. S=show...)
453 * @returns {Boolean} tue indicates permission allowed
455 hasPerm: function(name, lvl) {
457 (typeof(Pman.Login.authUser) != 'object')
459 (typeof(Pman.Login.authUser.perms) != 'object')
461 (typeof(Pman.Login.authUser.perms[name]) != 'string')
466 return Pman.Login.authUser.perms[name].indexOf(lvl) > -1;
471 * Is there a permission defined for this (used by module registration.)
473 * @param {String} name the [Module].[permission] to check for
474 * @returns {Boolean} tue indicates permission exists.
476 hasPermExists: function(name) {
478 (typeof(Pman.Login.authUser) != 'object')
480 (typeof(Pman.Login.authUser.perms) != 'object')
482 (typeof(Pman.Login.authUser.perms[name]) != 'string')
500 processResponse : function (response)
504 res = Roo.decode(response.responseText);
506 if (typeof(res) != 'object') {
507 res = { success : false, errorMsg : res, errors : true };
509 if (typeof(res.success) == 'undefined') {
514 res = { success : false, errorMsg : response.responseText, errors : true };
518 genericDelete : function(tab,tbl) {
523 var s = tab.grid.getSelectionModel().getSelections();
525 Roo.MessageBox.alert("Error", "Select at least one Row to delete" );
529 for(var i = 0; i < s.length; i++) {
530 r.push(s[i].data.id);
533 Roo.MessageBox.confirm("Confirm", "Are you sure you want to delete that?",
538 // what about the toolbar??
539 tab.grid.getView().mainWrap.mask("Deleting");
541 url: baseURL + '/Roo/'+tbl+'.php',
544 _delete : r.join(',')
546 success: function(response) {
547 tab.grid.getView().mainWrap.unmask();
549 tab.paging.onClick('refresh');
550 } else if (tab.refresh) {
552 } else if (tab.grid.footer && tab.grid.footer.onClick) {
553 // new xtype built grids
554 tab.grid.footer.onClick('refresh');
556 tab.grid.getDataSource().load();
562 failure: function(act) {
563 tab.grid.getView().mainWrap.unmask();
564 Roo.MessageBox.alert("Error", "Error Deleting");
575 standardActionFailed : function(f, act, cb) {
577 if (act.failureType == 'client') {
578 Roo.MessageBox.alert("Error", "Please Correct all the errors in red", cb);
581 if (act.failureType == 'connect') {
582 Roo.MessageBox.alert("Error", "Problem Connecting to Server - please try again.", cb);
586 if (act.type == 'submit') {
588 Roo.MessageBox.alert("Error", typeof(act.result.errorMsg) == 'string' ?
589 String.format('{0}', act.result.errorMsg) :
590 "Saving failed = fix errors and try again", cb);
594 // what about load failing..
595 Roo.MessageBox.alert("Error", "Error loading details",cb);
598 * Depreciated - USE new Pman.Request
602 request : function(c) {
603 var r= new Roo.data.Connection({
604 timeout : typeof(c.timeout) == 'undefined' ? 30000 : c.timeout
611 success: function(response, opts) { // check successfull...
613 var res = Pman.processResponse(response);
615 if (!res.success) { // error!
617 if (true === c.failure.call(this,response, opts)) {
621 Roo.MessageBox.hide();
622 Roo.MessageBox.alert("Error", res.errorMsg ? res.errorMsg : "Error Sending");
626 c.success.call(this, res.data);
630 failure : function(response, opts) { // check successfull...
633 if (true === c.failure.call(this,response, opts)) {
637 Roo.MessageBox.hide();
638 Roo.MessageBox.alert("Error", "Connection timed out sending");
648 // depreciated - use Pman.Download()
650 download : function(c) {
652 return new Pman.Download(c);
655 // fixme - move to document manager...
656 downloadRevision : function(doc, rev)
659 url: baseURL + '/Documents/Doc/DownloadRev/'+ doc.id + '/' + rev + '/' +
660 doc.project_id_code + '-' + doc.cidV + '-' + rev + '-' + doc.filename
666 exportCSV : function(c) {
668 for(var i=0;i < c.csvFormat.length;i++) {
669 c.params['csvCols['+i+']'] = c.csvFormat[i][0];
670 c.params['csvTitles['+i+']'] = c.csvFormat[i][1];
672 c.url += '?' + Roo.urlEncode(c.params);
678 prettyDate : function (value)
680 if (typeof(value) == 'string') {
681 var ds = Date.parseDate(value, 'Y-m-d H:i:s');
683 return this.prettyDate(ds);
685 ds = Date.parseDate(value, 'Y-m-d');
687 return this.prettyDate(ds);
696 var daysSince = Math.floor(td.getElapsed(value) / (1000 * 60*60*24));
698 return value.dateFormat('D H:i');
702 if (td.dateFormat('m') == value.dateFormat('m')) {
703 return value.dateFormat('dS D');
706 if (td.dateFormat('Y') == value.dateFormat('Y')) {
707 return value.dateFormat('dS M');
709 return value.dateFormat('d M Y');
711 loadException : function(a,b,c,d)
713 if (d && d.authFailure) {
717 Roo.MessageBox.alert("Problem Loading Data", a.message || c.statusText);
723 * Routine to flash alerts in the title bar..
728 notifyActive : false,
730 notifyTitle: function(msg)
732 if (this.notifyActive ) {
737 var stopper = function() {
739 document.title = oldtitle;
742 Roo.get(document.body).on('mousemove', stopper, this);
743 var oldtitle = document.title;
746 var ivl = window.setInterval(function() {
749 Roo.get(document.body).un('mousemove', stopper, this);
750 _this.notifyActive = false;
751 document.title = oldtitle;
752 window.clearInterval(ivl);
756 document.title = s ? msg : oldtitle;
758 }, 1000); // every 120 secs = 2mins..
759 document.title = msg;
765 * @property {Array} appModules - array based on AppModules global
772 xregister : function(obj)
776 if (!this.appModules === false) {
777 this.appModules = typeof(AppModules ) == 'undefined'? [] :
778 AppModules.split(',');
783 // ignore registration of objects which are disabled.
784 // global supplied by master.html
785 appDisabled = typeof(appDisabled) == 'undefined' ? [] : appDisabled;
789 // previously we did not a good naming policy for module and parts
790 // most things that are called module here, really are 'parts'
791 // new versions should have 'part' as [ module : part ]
794 if (typeof(obj.part) != 'undefined') {
796 var permname = obj.part.join('.');
797 // we now have permission...
798 // obj.moduleOwner '.' lname
800 if (this.hasPermExists(permname) && !this.hasPerm(permname,'S')) {
801 // it's a turned off permission...
802 Roo.log(permname + " is Disabled for this user");
806 if (appDisabled.indexOf(permname) > -1) {
807 Roo.log(permname + " is Disabled for this site");
818 if (obj.parent === false) {
820 console.log('skip module (no parent)');
824 // this is an error condition - the parent does not exist..
825 // technically it should not happen..
826 console.log("Parent is undefined");
836 * DEPRICATED : use Roo.XComponents now..
839 modKey : '00-admin-xxxx',
840 module : Pman.Tab.projectMgr, << really a components..
841 part : [ 'Admin', 'ProjectManager' ]
848 register : function(obj)
852 Roo.XComponent.register(obj);
860 if (!obj.parent.modules) {
861 obj.parent.modules = new Roo.util.MixedCollection(false, function(o) { return o.modKey });
864 obj.parent.modules.add(obj);
869 buildModules : function(parent, onComplete)
871 Roo.XComponent.build();
874 var cmp = function(a,b) {
875 return String(a).toUpperCase() > String(b).toUpperCase() ? 1 : -1;
878 if (!parent.modules) {
881 parent.modules.keySort('ASC', cmp );
885 // add modules to their parents..
886 var addMod = function(m) {
887 // console.log(m.modKey);
890 if (m.module.modules) {
891 m.module.modules.keySort('ASC', cmp );
892 m.module.modules.each(addMod);
895 m.finalize.name = m.name + " (clean up) ";
896 mods.push(m.finalize);
901 parent.modules.each(addMod);
902 //this.allmods = mods;
906 if (onComplete) onComplete();
909 // flash it up as modal - so we store the mask!?
910 Roo.MessageBox.show({ title: 'loading' });
911 Roo.MessageBox.show({
912 title: "Please wait...",
913 msg: "Building Interface...",
921 var progressRun = function() {
926 Roo.MessageBox.updateProgress(
927 (n+1)/mods.length, "Building Interface " + (n+1) +
928 " of " + mods.length +
929 (mod.name ? (' - ' + mod.name) : '')
934 if (typeof(mod) == 'function') {
937 } else if (typeof(mod.region) == 'undefined') {
938 Roo.log("Module does not have region defined, skipping");
941 } else if (mod.parent.layout && !mod.module.disabled) {
942 // honour permname setings..
943 if (mod.permname && mod.permname.length) {
944 if (Pman.hasPerm(mod.permname, 'S')) {
945 mod.module.add(mod.parent.layout, mod.region);
948 mod.module.add(mod.parent.layout, mod.region);
954 if (n >= mods.length) {
960 progressRun.defer(10, Pman);
962 progressRun.defer(1, Pman);
968 invertColor : function(c)
972 for(var i = 0; i < 3; i++){
973 ca[i] = parseInt(c.charAt((i*2)+1) + c.charAt((i*2)+2), 16);
978 Roo.each(ca, function(hi) {
979 var h = parseInt(255-hi).toString(16);