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); });
23 Roo.XComponent.on('buildComplete', function(e) { return Pman.finalize(); });
28 Pman = new Roo.Document(
30 /// appVersion: '1.7', // fixme = needs to be removed - use Global AppVersion
33 rightNames: { }, /// register right names here - so they can be translated and rendered.
35 * @property {Roo.menu.Menu} pulldownMenu - the 'add menu pulldown, you can use it to add items..
41 buildCompleted : false, // flag to say if we are building interface..
43 'beforeload' : true, // fired after page ready, before module building.
44 'load' : true, // fired after module building
45 'authrefreshed' : true // fire on auth updated?? - should be on Login?!?!?
51 // kludge to fix firebug debugger
52 if (typeof(console) == 'undefined') {
53 console = { log : function() { } };
57 if (Roo.get('loading')) {
58 Roo.get('loading').remove();
61 Roo.state.Manager.setProvider(new Roo.state.CookieProvider());
65 if (AppLinkError.length) {
66 Roo.MessageBox.alert("Error", AppLinkError, function() {
74 if (showNewPass.length) {
75 Pman.PasswordChange.show( { passwordReset : showNewPass },
77 // fail and success we do a load...
89 if (Roo.get('loading-logo-tile')) {
90 Roo.get('loading-logo-tile').remove();
92 if (Roo.get('loading-logo-tile-top')) {
93 Roo.get('loading-logo-tile-top').remove();
95 if (Roo.get('loading-logo-bottom')) {
96 Roo.get('loading-logo-bottom').remove();
98 if (Roo.get('loading-logo-center')) {
99 Roo.get('loading-logo-center').remove();
119 //this.fireEvent('beforeload',this);
124 return; // already loaded
126 if (Roo.get('loading')) {
127 Roo.get('loading').remove();
129 if (Roo.get('loading-mask')) {
130 Roo.get('loading-mask').show();
135 this.stime = new Date();
136 this.layout = new Roo.BorderLayout(document.body, {
150 alwaysShowTabs: true,
164 Pman.register( Roo.apply(this.fakeRoot, {
170 // creates all the modules ready to load..
172 this.fireEvent('beforeload',this);
176 this.layout.beginUpdate();
177 this.layout.add('north', new Roo.ContentPanel('title', 'North'));
178 var au = Pman.Login.authUser;
179 if (au.id > 0 && au.company_id_background_color && au.company_id_background_color.length) {
180 Roo.get('title').dom.style.backgroundColor = '#' + au.company_id_background_color;
181 Roo.get('headerInformation').dom.style.color = this.invertColor('#' + au.company_id_background_color);
183 if (au.id > 0 && au.company_id_logo_id * 1 > 0) {
184 Roo.get('headerInformation-company-logo').dom.src = baseURL +
185 '/Images/' + au.company_id_logo_id + '/' + au.company_id_logo_id_filename;
187 Roo.get('headerInformation-company-logo').dom.src = Roo.BLANK_IMAGE_URL;
190 Roo.get('headerInformation').dom.innerHTML = String.format(
191 "You are Logged in as <b>{0} ({1})</b>", // to {4} v{3}", // for <b>{2}</b>",
192 au.name, au.email, au.company_id_name,
193 AppVersion , appNameShort
197 document.title = appName + ' v' + AppVersion + ' - ' + au.company_id_name;
198 Roo.QuickTips.init();
203 //this.mainLayout.beginUpdate();
204 //var maskDom = Roo.get(document.body)._maskMsg.dom
205 this.layout.beginUpdate();
207 Pman.building = true;
209 this.buildModules(this,
217 addTopToolbar : function()
219 //console.log( "t6:" + ((new Date())-stime));
220 //this.mainLayout.endUpdate();
221 // make a new tab to hold administration stuff...
224 //console.log( "t7:" + ((new Date())-stime));
225 var se = Pman.layout.getRegion('center').tabs.stripEl;
226 var tbh = se.createChild(
227 { tag: 'td', style: 'width:100%;' });
229 var lotb = new Roo.Toolbar(tbh);
232 var tbl = se.child('table', true);
233 tbl.setAttribute('width', '100%');
236 new Roo.Toolbar.Fill(),
239 text: "Change Password",
240 cls: 'x-btn-text-icon',
241 icon: rootURL + '/Pman/templates/images/change-password.gif',
242 handler : function(){
243 Pman.PasswordChange.show({});
249 if (this.topMenuItems.length) {
251 Roo.each(this.topMenuItems, function (mi) {
259 if (this.subMenuItems.length) {
261 this.subMenuItems.sort(function (a,b) {
262 return a.seqid > b.seqid ? 1 : -1;
264 // chop off last seperator.
265 // since we always add it.. just chop of last item
266 this.subMenuItems.pop();
268 var btn = new Roo.Toolbar.Button(
270 text: "Add New Item",
271 cls: 'x-btn-text-icon',
272 icon: Roo.rootURL + 'images/default/dd/drop-add.gif',
274 items : this.subMenuItems
278 this.pulldownMenu = btn.menu;
286 cls: 'x-btn-text-icon',
287 icon: rootURL + '/Pman/templates/images/logout.gif',
288 handler: function() {
295 // this.layout.endUpdate();
299 finalize : function() {
303 window.onbeforeunload = function(e) {
304 e = e || window.event;
305 var r = "Closing this window will loose changes, are you sure you want to do that?";
307 // For IE and Firefox
317 Roo.MessageBox.hide();
318 if (Roo.get('loading-mask')) {
319 Roo.get('loading-mask').remove();
323 this.buildCompleted = true; // now we can force refreshes on everything..
326 // does the URL indicate we want to see a system..
327 if (AppTrackOnLoad * 1 > 0) {
328 this.onLoadTrack(AppTrackOnLoad,false);
333 var forceAdmin = function(data)
335 if (!data || !data.id) {
336 //Roo.log("Force Admin");
337 Pman.Dialog.PersonStaff.show(
340 company_id : Pman.Login.authUser.company_id_id * 1,
341 company_id_name : Pman.Login.authUser.company_id_name
348 Roo.state.Manager.set('Pman.Login.username', data.email),
349 window.onbeforeunload = false;
350 document.location = baseURL + '?ts=' + Math.random();
353 var forceCompany = function(data) {
354 if (Pman.Login.authUser.company_id * 1 > 0) {
358 if (!data || !data.id) {
359 Pman.Dialog.Companies.show( { id : 0, isOwner : 1, comptype: 'OWNER' }, function(data) {
364 Pman.Login.authUser.company_id_id = data.id;
365 Pman.Login.authUser.company_id = data.id;
366 Pman.Login.authUser.company_id_name = data.name;
370 if (Pman.Login.authUser.id < 0) {
371 // admin company has been created - create the user..
372 if (Pman.Login.authUser.company_id_id* 1 > 0) {
390 onLoadTrack : function(id,cb) {
391 this.onLoadTrackCall(id, cb, 'DocumentsCirc_');
393 onLoadTrackEdit : function(id,cb) {
394 this.onLoadTrackCall(id, cb, 'Documents_');
398 /// ----------- FIXME -----
401 onLoadTrackCall : function(id,cb, cls) {
402 Roo.get(document.body).mask("Loading Document details");
405 url: baseURL + '/Roo/Documents.html',
410 success : function(data) {
411 Roo.get(document.body).unmask();
414 switch(data.in_out) {
415 case 'IN' : cls+='In';break;
416 case 'OUT' : cls+='Out';break;
417 case 'WIP' : cls+='Wip';break;
419 Roo.MessageBox.alert("Error", "invalid in_out");
422 Pman.Dialog[cls].show(data, cb ? cb : Pman.refreshActivePanel);
425 failure: function() {
426 Roo.get(document.body).unmask();
436 refreshActivePanel : function() {
437 var actpan = this.layout.getRegion('center').getActivePanel();
438 if (actpan.controller && actpan.controller.paging) {
439 actpan.controller.paging.onClick('refresh');
443 var agid = Pman.layout.getRegion('center').getActivePanel().id;
447 Pman.Tab[agid].paging.onClick('refresh');
449 toCidV : function(data) {
450 return 'C' + data.in_out.substring(0,1) + data.cid;
456 * Does the authenticated user have permission to see this.
458 * @param {String} name the [Module].[permission] to check for
459 * @param {Char} lvl - which type of permission to use (eg. S=show...)
460 * @returns {Boolean} tue indicates permission allowed
462 hasPerm: function(name, lvl) {
464 (typeof(Pman.Login.authUser) != 'object')
466 (typeof(Pman.Login.authUser.perms) != 'object')
468 (typeof(Pman.Login.authUser.perms[name]) != 'string')
473 return Pman.Login.authUser.perms[name].indexOf(lvl) > -1;
478 * Is there a permission defined for this (used by module registration.)
480 * @param {String} name the [Module].[permission] to check for
481 * @returns {Boolean} tue indicates permission exists.
483 hasPermExists: function(name) {
485 (typeof(Pman.Login.authUser) != 'object')
487 (typeof(Pman.Login.authUser.perms) != 'object')
489 (typeof(Pman.Login.authUser.perms[name]) != 'string')
507 processResponse : function (response)
511 res = Roo.decode(response.responseText);
513 if (typeof(res) != 'object') {
514 res = { success : false, errorMsg : res, errors : true };
516 if (typeof(res.success) == 'undefined') {
521 res = { success : false, errorMsg : response.responseText, errors : true };
525 genericDelete : function(tab,tbl) {
530 var s = tab.grid.getSelectionModel().getSelections();
532 Roo.MessageBox.alert("Error", "Select at least one Row to delete" );
536 for(var i = 0; i < s.length; i++) {
537 r.push(s[i].data.id);
540 Roo.MessageBox.confirm("Confirm", "Are you sure you want to delete that?",
545 // what about the toolbar??
546 tab.grid.getView().mainWrap.mask("Deleting");
548 url: baseURL + '/Roo/'+tbl+'.php',
551 _delete : r.join(',')
553 success: function(response) {
554 tab.grid.getView().mainWrap.unmask();
556 tab.paging.onClick('refresh');
557 } else if (tab.refresh) {
559 } else if (tab.grid.footer && tab.grid.footer.onClick) {
560 // new xtype built grids
561 tab.grid.footer.onClick('refresh');
563 tab.grid.getDataSource().load();
569 failure: function(act) {
570 tab.grid.getView().mainWrap.unmask();
571 Roo.MessageBox.alert("Error", "Error Deleting");
582 standardActionFailed : function(f, act, cb) {
584 if (act.failureType == 'client') {
585 Roo.MessageBox.alert("Error", "Please Correct all the errors in red", cb);
588 if (act.failureType == 'connect') {
589 Roo.MessageBox.alert("Error", "Problem Connecting to Server - please try again.", cb);
593 if (act.type == 'submit') {
595 Roo.MessageBox.alert("Error", typeof(act.result.errorMsg) == 'string' ?
596 String.format('{0}', act.result.errorMsg) :
597 "Saving failed = fix errors and try again", cb);
601 // what about load failing..
602 Roo.MessageBox.alert("Error", "Error loading details",cb);
605 * Depreciated - USE new Pman.Request
609 request : function(c) {
610 var r= new Roo.data.Connection({
611 timeout : typeof(c.timeout) == 'undefined' ? 30000 : c.timeout
618 success: function(response, opts) { // check successfull...
620 var res = Pman.processResponse(response);
622 if (!res.success) { // error!
624 if (true === c.failure.call(this,response, opts)) {
628 Roo.MessageBox.hide();
629 Roo.MessageBox.alert("Error", res.errorMsg ? res.errorMsg : "Error Sending");
633 c.success.call(this, res.data);
637 failure : function(response, opts) { // check successfull...
640 if (true === c.failure.call(this,response, opts)) {
644 Roo.MessageBox.hide();
645 Roo.MessageBox.alert("Error", "Connection timed out sending");
655 // depreciated - use Pman.Download()
657 download : function(c) {
659 return new Pman.Download(c);
662 // fixme - move to document manager...
663 downloadRevision : function(doc, rev)
666 url: baseURL + '/Documents/Doc/DownloadRev/'+ doc.id + '/' + rev + '/' +
667 doc.project_id_code + '-' + doc.cidV + '-' + rev + '-' + doc.filename
673 exportCSV : function(c) {
675 for(var i=0;i < c.csvFormat.length;i++) {
676 c.params['csvCols['+i+']'] = c.csvFormat[i][0];
677 c.params['csvTitles['+i+']'] = c.csvFormat[i][1];
679 c.url += '?' + Roo.urlEncode(c.params);
685 prettyDate : function (value)
687 if (typeof(value) == 'string') {
688 var ds = Date.parseDate(value, 'Y-m-d H:i:s');
690 return this.prettyDate(ds);
692 ds = Date.parseDate(value, 'Y-m-d');
694 return this.prettyDate(ds);
703 var daysSince = Math.floor(td.getElapsed(value) / (1000 * 60*60*24));
705 return value.dateFormat('D H:i');
709 if (td.dateFormat('m') == value.dateFormat('m')) {
710 return value.dateFormat('dS D');
713 if (td.dateFormat('Y') == value.dateFormat('Y')) {
714 return value.dateFormat('dS M');
716 return value.dateFormat('d M Y');
718 loadException : function(a,b,c,d)
720 if (d && d.authFailure) {
724 Roo.MessageBox.alert("Problem Loading Data", a.message || c.statusText);
730 * Routine to flash alerts in the title bar..
735 notifyActive : false,
737 notifyTitle: function(msg)
739 if (this.notifyActive ) {
744 var stopper = function() {
746 document.title = oldtitle;
749 Roo.get(document.body).on('mousemove', stopper, this);
750 var oldtitle = document.title;
753 var ivl = window.setInterval(function() {
756 Roo.get(document.body).un('mousemove', stopper, this);
757 _this.notifyActive = false;
758 document.title = oldtitle;
759 window.clearInterval(ivl);
763 document.title = s ? msg : oldtitle;
765 }, 1000); // every 120 secs = 2mins..
766 document.title = msg;
772 * @property {Array} appModules - array based on AppModules global
779 xregister : function(obj)
783 if (!this.appModules === false) {
784 this.appModules = typeof(AppModules ) == 'undefined'? [] :
785 AppModules.split(',');
790 // ignore registration of objects which are disabled.
791 // global supplied by master.html
792 appDisabled = typeof(appDisabled) == 'undefined' ? [] : appDisabled;
796 // previously we did not a good naming policy for module and parts
797 // most things that are called module here, really are 'parts'
798 // new versions should have 'part' as [ module : part ]
801 if (typeof(obj.part) != 'undefined') {
803 var permname = obj.part.join('.');
804 // we now have permission...
805 // obj.moduleOwner '.' lname
807 if (this.hasPermExists(permname) && !this.hasPerm(permname,'S')) {
808 // it's a turned off permission...
809 Roo.log(permname + " is Disabled for this user");
813 if (appDisabled.indexOf(permname) > -1) {
814 Roo.log(permname + " is Disabled for this site");
823 // false parent... use it..
828 if (obj.parent === Pman) {
829 obj.parent = Pman.fakeRoot;
832 if (typeof(obj.parent) == 'undefined') {
833 console.log("Parent is undefined");
840 if (obj.parent === false) {
842 console.log('ignoring top level object (as parent===false found)');
846 // this is an error condition - the parent does not exist..
847 // technically it should not happen..
849 // hack for Pman parent == Pman..
850 if (obj.parent == obj.module) {
858 * DEPRICATED : use Roo.XComponents now..
861 modKey : '00-admin-xxxx',
862 module : Pman.Tab.projectMgr, << really a components..
863 part : [ 'Admin', 'ProjectManager' ]
870 register : function(obj)
873 //this.xregister(obj);
876 // old style calls go in here..
877 // we need to convert the object so that it looks a bit like an XCompoenent..
879 obj.render = function()
882 Roo.log("Skip module, as parent does not exist");
886 //if (typeof(mod) == 'function') {
889 if (typeof(this.region) == 'undefined') {
890 Roo.log("Module does not have region defined, skipping");
894 if (this.module.disabled) {
895 Roo.log("Module disabled, should not rendering")
900 if (!this.parent.layout) {
901 Roo.log("Module parent does not have property layout.")
906 // honour DEPRICATED permname setings..
907 // new code should use PART name, and matching permissions.
908 if (this.permname && this.permname.length) {
909 if (Pman.hasPerm(this.permname, 'S')) {
910 this.add(this.parent.layout, this.region);
914 this.add(this.parent.layout, this.region);
917 // map some of the standard properties..
918 obj.order = obj.modKey;
924 // the other issue we have is that
927 // Roo.log("CALLING XComponent register with : " + obj.name);
929 // this will call xregister as it's the on.register handler..
930 Roo.XComponent.register(obj.isTop ? obj : Roo.apply(obj.module, obj));
938 if (!obj.parent.modules) {
939 obj.parent.modules = new Roo.util.MixedCollection(false, function(o) { return o.modKey });
942 obj.parent.modules.add(obj);
947 buildModules : function(parent, onComplete)
949 Roo.XComponent.build();
952 var cmp = function(a,b) {
953 return String(a).toUpperCase() > String(b).toUpperCase() ? 1 : -1;
956 if (!parent.modules) {
959 parent.modules.keySort('ASC', cmp );
963 // add modules to their parents..
964 var addMod = function(m) {
965 // console.log(m.modKey);
968 if (m.module.modules) {
969 m.module.modules.keySort('ASC', cmp );
970 m.module.modules.each(addMod);
973 m.finalize.name = m.name + " (clean up) ";
974 mods.push(m.finalize);
979 parent.modules.each(addMod);
980 //this.allmods = mods;
984 if (onComplete) onComplete();
987 // flash it up as modal - so we store the mask!?
988 Roo.MessageBox.show({ title: 'loading' });
989 Roo.MessageBox.show({
990 title: "Please wait...",
991 msg: "Building Interface...",
999 var progressRun = function() {
1004 Roo.MessageBox.updateProgress(
1005 (n+1)/mods.length, "Building Interface " + (n+1) +
1006 " of " + mods.length +
1007 (mod.name ? (' - ' + mod.name) : '')
1012 if (typeof(mod) == 'function') {
1015 } else if (typeof(mod.region) == 'undefined') {
1016 Roo.log("Module does not have region defined, skipping");
1019 } else if (mod.parent.layout && !mod.module.disabled) {
1020 // honour permname setings..
1021 if (mod.permname && mod.permname.length) {
1022 if (Pman.hasPerm(mod.permname, 'S')) {
1023 mod.module.add(mod.parent.layout, mod.region);
1026 mod.module.add(mod.parent.layout, mod.region);
1032 if (n >= mods.length) {
1038 progressRun.defer(10, Pman);
1040 progressRun.defer(1, Pman);
1046 invertColor : function(c)
1050 for(var i = 0; i < 3; i++){
1051 ca[i] = parseInt(c.charAt((i*2)+1) + c.charAt((i*2)+2), 16);
1056 Roo.each(ca, function(hi) {
1057 var h = parseInt(255-hi).toString(16);