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,
164 // creates all the modules ready to load..
166 this.fireEvent('beforeload',this);
170 this.layout.beginUpdate();
171 this.layout.add('north', new Roo.ContentPanel('title', 'North'));
172 var au = Pman.Login.authUser;
173 if (au.id > 0 && au.company_id_background_color && au.company_id_background_color.length) {
174 Roo.get('title').dom.style.backgroundColor = '#' + au.company_id_background_color;
175 Roo.get('headerInformation').dom.style.color = this.invertColor('#' + au.company_id_background_color);
177 if (au.id > 0 && au.company_id_logo_id * 1 > 0) {
178 Roo.get('headerInformation-company-logo').dom.src = baseURL +
179 '/Images/' + au.company_id_logo_id + '/' + au.company_id_logo_id_filename;
181 Roo.get('headerInformation-company-logo').dom.src = Roo.BLANK_IMAGE_URL;
184 Roo.get('headerInformation').dom.innerHTML = String.format(
185 "You are Logged in as <b>{0} ({1})</b>", // to {4} v{3}", // for <b>{2}</b>",
186 au.name, au.email, au.company_id_name,
187 AppVersion , appNameShort
191 document.title = appName + ' v' + AppVersion + ' - ' + au.company_id_name;
192 Roo.QuickTips.init();
197 //this.mainLayout.beginUpdate();
198 //var maskDom = Roo.get(document.body)._maskMsg.dom
199 this.layout.beginUpdate();
201 Pman.building = true;
203 this.buildModules(this,
206 _this.layout.getRegion('center').showPanel(0);
207 _this.layout.endUpdate();
208 _this.addTopToolbar();
210 _this.fireEvent('load',this);
212 if (!_this.layout.getRegion('south').panels.length) {
213 _this.layout.getRegion('south').hide();
224 addTopToolbar : function()
226 //console.log( "t6:" + ((new Date())-stime));
227 //this.mainLayout.endUpdate();
228 // make a new tab to hold administration stuff...
231 //console.log( "t7:" + ((new Date())-stime));
232 var se = Pman.layout.getRegion('center').tabs.stripEl;
233 var tbh = se.createChild(
234 { tag: 'td', style: 'width:100%;' });
236 var lotb = new Roo.Toolbar(tbh);
239 var tbl = se.child('table', true);
240 tbl.setAttribute('width', '100%');
243 new Roo.Toolbar.Fill(),
246 text: "Change Password",
247 cls: 'x-btn-text-icon',
248 icon: rootURL + '/Pman/templates/images/change-password.gif',
249 handler : function(){
250 Pman.PasswordChange.show({});
256 if (this.topMenuItems.length) {
258 Roo.each(this.topMenuItems, function (mi) {
266 if (this.subMenuItems.length) {
268 this.subMenuItems.sort(function (a,b) {
269 return a.seqid > b.seqid ? 1 : -1;
271 // chop off last seperator.
272 // since we always add it.. just chop of last item
273 this.subMenuItems.pop();
275 var btn = new Roo.Toolbar.Button(
277 text: "Add New Item",
278 cls: 'x-btn-text-icon',
279 icon: Roo.rootURL + 'images/default/dd/drop-add.gif',
281 items : this.subMenuItems
285 this.pulldownMenu = btn.menu;
293 cls: 'x-btn-text-icon',
294 icon: rootURL + '/Pman/templates/images/logout.gif',
295 handler: function() {
302 // this.layout.endUpdate();
306 finalize : function() {
310 window.onbeforeunload = function(e) {
311 e = e || window.event;
312 var r = "Closing this window will loose changes, are you sure you want to do that?";
314 // For IE and Firefox
324 Roo.MessageBox.hide();
325 if (Roo.get('loading-mask')) {
326 Roo.get('loading-mask').remove();
330 this.buildCompleted = true; // now we can force refreshes on everything..
333 // does the URL indicate we want to see a system..
334 if (AppTrackOnLoad * 1 > 0) {
335 this.onLoadTrack(AppTrackOnLoad,false);
340 var forceAdmin = function(data)
342 if (!data || !data.id) {
343 //Roo.log("Force Admin");
344 Pman.Dialog.PersonStaff.show(
347 company_id : Pman.Login.authUser.company_id_id * 1,
348 company_id_name : Pman.Login.authUser.company_id_name
355 Roo.state.Manager.set('Pman.Login.username', data.email),
356 window.onbeforeunload = false;
357 document.location = baseURL + '?ts=' + Math.random();
360 var forceCompany = function(data) {
361 if (Pman.Login.authUser.company_id * 1 > 0) {
365 if (!data || !data.id) {
366 Pman.Dialog.Companies.show( { id : 0, isOwner : 1, comptype: 'OWNER' }, function(data) {
371 Pman.Login.authUser.company_id_id = data.id;
372 Pman.Login.authUser.company_id = data.id;
373 Pman.Login.authUser.company_id_name = data.name;
377 if (Pman.Login.authUser.id < 0) {
378 // admin company has been created - create the user..
379 if (Pman.Login.authUser.company_id_id* 1 > 0) {
397 onLoadTrack : function(id,cb) {
398 this.onLoadTrackCall(id, cb, 'DocumentsCirc_');
400 onLoadTrackEdit : function(id,cb) {
401 this.onLoadTrackCall(id, cb, 'Documents_');
405 /// ----------- FIXME -----
408 onLoadTrackCall : function(id,cb, cls) {
409 Roo.get(document.body).mask("Loading Document details");
412 url: baseURL + '/Roo/Documents.html',
417 success : function(data) {
418 Roo.get(document.body).unmask();
421 switch(data.in_out) {
422 case 'IN' : cls+='In';break;
423 case 'OUT' : cls+='Out';break;
424 case 'WIP' : cls+='Wip';break;
426 Roo.MessageBox.alert("Error", "invalid in_out");
429 Pman.Dialog[cls].show(data, cb ? cb : Pman.refreshActivePanel);
432 failure: function() {
433 Roo.get(document.body).unmask();
443 refreshActivePanel : function() {
444 var actpan = this.layout.getRegion('center').getActivePanel();
445 if (actpan.controller && actpan.controller.paging) {
446 actpan.controller.paging.onClick('refresh');
450 var agid = Pman.layout.getRegion('center').getActivePanel().id;
454 Pman.Tab[agid].paging.onClick('refresh');
456 toCidV : function(data) {
457 return 'C' + data.in_out.substring(0,1) + data.cid;
463 * Does the authenticated user have permission to see this.
465 * @param {String} name the [Module].[permission] to check for
466 * @param {Char} lvl - which type of permission to use (eg. S=show...)
467 * @returns {Boolean} tue indicates permission allowed
469 hasPerm: function(name, lvl) {
471 (typeof(Pman.Login.authUser) != 'object')
473 (typeof(Pman.Login.authUser.perms) != 'object')
475 (typeof(Pman.Login.authUser.perms[name]) != 'string')
480 return Pman.Login.authUser.perms[name].indexOf(lvl) > -1;
485 * Is there a permission defined for this (used by module registration.)
487 * @param {String} name the [Module].[permission] to check for
488 * @returns {Boolean} tue indicates permission exists.
490 hasPermExists: function(name) {
492 (typeof(Pman.Login.authUser) != 'object')
494 (typeof(Pman.Login.authUser.perms) != 'object')
496 (typeof(Pman.Login.authUser.perms[name]) != 'string')
514 processResponse : function (response)
518 res = Roo.decode(response.responseText);
520 if (typeof(res) != 'object') {
521 res = { success : false, errorMsg : res, errors : true };
523 if (typeof(res.success) == 'undefined') {
528 res = { success : false, errorMsg : response.responseText, errors : true };
532 genericDelete : function(tab,tbl) {
537 var s = tab.grid.getSelectionModel().getSelections();
539 Roo.MessageBox.alert("Error", "Select at least one Row to delete" );
543 for(var i = 0; i < s.length; i++) {
544 r.push(s[i].data.id);
547 Roo.MessageBox.confirm("Confirm", "Are you sure you want to delete that?",
552 // what about the toolbar??
553 tab.grid.getView().mainWrap.mask("Deleting");
555 url: baseURL + '/Roo/'+tbl+'.php',
558 _delete : r.join(',')
560 success: function(response) {
561 tab.grid.getView().mainWrap.unmask();
563 tab.paging.onClick('refresh');
564 } else if (tab.refresh) {
566 } else if (tab.grid.footer && tab.grid.footer.onClick) {
567 // new xtype built grids
568 tab.grid.footer.onClick('refresh');
570 tab.grid.getDataSource().load();
576 failure: function(act) {
577 tab.grid.getView().mainWrap.unmask();
578 Roo.MessageBox.alert("Error", "Error Deleting");
589 standardActionFailed : function(f, act, cb) {
591 if (act.failureType == 'client') {
592 Roo.MessageBox.alert("Error", "Please Correct all the errors in red", cb);
595 if (act.failureType == 'connect') {
596 Roo.MessageBox.alert("Error", "Problem Connecting to Server - please try again.", cb);
600 if (act.type == 'submit') {
602 Roo.MessageBox.alert("Error", typeof(act.result.errorMsg) == 'string' ?
603 String.format('{0}', act.result.errorMsg) :
604 "Saving failed = fix errors and try again", cb);
608 // what about load failing..
609 Roo.MessageBox.alert("Error", "Error loading details",cb);
612 * Depreciated - USE new Pman.Request
616 request : function(c) {
617 var r= new Roo.data.Connection({
618 timeout : typeof(c.timeout) == 'undefined' ? 30000 : c.timeout
625 success: function(response, opts) { // check successfull...
627 var res = Pman.processResponse(response);
629 if (!res.success) { // error!
631 if (true === c.failure.call(this,response, opts)) {
635 Roo.MessageBox.hide();
636 Roo.MessageBox.alert("Error", res.errorMsg ? res.errorMsg : "Error Sending");
640 c.success.call(this, res.data);
644 failure : function(response, opts) { // check successfull...
647 if (true === c.failure.call(this,response, opts)) {
651 Roo.MessageBox.hide();
652 Roo.MessageBox.alert("Error", "Connection timed out sending");
662 // depreciated - use Pman.Download()
664 download : function(c) {
666 return new Pman.Download(c);
669 // fixme - move to document manager...
670 downloadRevision : function(doc, rev)
673 url: baseURL + '/Documents/Doc/DownloadRev/'+ doc.id + '/' + rev + '/' +
674 doc.project_id_code + '-' + doc.cidV + '-' + rev + '-' + doc.filename
680 exportCSV : function(c) {
682 for(var i=0;i < c.csvFormat.length;i++) {
683 c.params['csvCols['+i+']'] = c.csvFormat[i][0];
684 c.params['csvTitles['+i+']'] = c.csvFormat[i][1];
686 c.url += '?' + Roo.urlEncode(c.params);
692 prettyDate : function (value)
694 if (typeof(value) == 'string') {
695 var ds = Date.parseDate(value, 'Y-m-d H:i:s');
697 return this.prettyDate(ds);
699 ds = Date.parseDate(value, 'Y-m-d');
701 return this.prettyDate(ds);
710 var daysSince = Math.floor(td.getElapsed(value) / (1000 * 60*60*24));
712 return value.dateFormat('D H:i');
716 if (td.dateFormat('m') == value.dateFormat('m')) {
717 return value.dateFormat('dS D');
720 if (td.dateFormat('Y') == value.dateFormat('Y')) {
721 return value.dateFormat('dS M');
723 return value.dateFormat('d M Y');
725 loadException : function(a,b,c,d)
727 if (d && d.authFailure) {
731 Roo.MessageBox.alert("Problem Loading Data", a.message || c.statusText);
737 * Routine to flash alerts in the title bar..
742 notifyActive : false,
744 notifyTitle: function(msg)
746 if (this.notifyActive ) {
751 var stopper = function() {
753 document.title = oldtitle;
756 Roo.get(document.body).on('mousemove', stopper, this);
757 var oldtitle = document.title;
760 var ivl = window.setInterval(function() {
763 Roo.get(document.body).un('mousemove', stopper, this);
764 _this.notifyActive = false;
765 document.title = oldtitle;
766 window.clearInterval(ivl);
770 document.title = s ? msg : oldtitle;
772 }, 1000); // every 120 secs = 2mins..
773 document.title = msg;
779 * @property {Array} appModules - array based on AppModules global
786 xregister : function(obj)
790 if (!this.appModules === false) {
791 this.appModules = typeof(AppModules ) == 'undefined'? [] :
792 AppModules.split(',');
797 // ignore registration of objects which are disabled.
798 // global supplied by master.html
799 appDisabled = typeof(appDisabled) == 'undefined' ? [] : appDisabled;
803 // previously we did not a good naming policy for module and parts
804 // most things that are called module here, really are 'parts'
805 // new versions should have 'part' as [ module : part ]
808 if (typeof(obj.part) != 'undefined') {
810 var permname = obj.part.join('.');
811 // we now have permission...
812 // obj.moduleOwner '.' lname
814 if (this.hasPermExists(permname) && !this.hasPerm(permname,'S')) {
815 // it's a turned off permission...
816 Roo.log(permname + " is Disabled for this user");
820 if (appDisabled.indexOf(permname) > -1) {
821 Roo.log(permname + " is Disabled for this site");
831 if (typeof(obj.parent) == 'undefined') {
832 console.log("Parent is undefined");
839 if (obj.parent === false) {
841 console.log('ignoring top level object (as parent===false found)');
845 // this is an error condition - the parent does not exist..
846 // technically it should not happen..
848 // hack for Pman parent == Pman..
849 if (obj.parent == obj.module) {
857 * DEPRICATED : use Roo.XComponents now..
860 modKey : '00-admin-xxxx',
861 module : Pman.Tab.projectMgr, << really a components..
862 part : [ 'Admin', 'ProjectManager' ]
869 register : function(obj)
872 //this.xregister(obj);
874 Roo.log("CALLING XComponent register with : " + obj.name);
876 // this will call xregister as it's the on.register handler..
877 Roo.XComponent.register(obj);
885 if (!obj.parent.modules) {
886 obj.parent.modules = new Roo.util.MixedCollection(false, function(o) { return o.modKey });
889 obj.parent.modules.add(obj);
894 buildModules : function(parent, onComplete)
896 Roo.XComponent.build();
899 var cmp = function(a,b) {
900 return String(a).toUpperCase() > String(b).toUpperCase() ? 1 : -1;
903 if (!parent.modules) {
906 parent.modules.keySort('ASC', cmp );
910 // add modules to their parents..
911 var addMod = function(m) {
912 // console.log(m.modKey);
915 if (m.module.modules) {
916 m.module.modules.keySort('ASC', cmp );
917 m.module.modules.each(addMod);
920 m.finalize.name = m.name + " (clean up) ";
921 mods.push(m.finalize);
926 parent.modules.each(addMod);
927 //this.allmods = mods;
931 if (onComplete) onComplete();
934 // flash it up as modal - so we store the mask!?
935 Roo.MessageBox.show({ title: 'loading' });
936 Roo.MessageBox.show({
937 title: "Please wait...",
938 msg: "Building Interface...",
946 var progressRun = function() {
951 Roo.MessageBox.updateProgress(
952 (n+1)/mods.length, "Building Interface " + (n+1) +
953 " of " + mods.length +
954 (mod.name ? (' - ' + mod.name) : '')
959 if (typeof(mod) == 'function') {
962 } else if (typeof(mod.region) == 'undefined') {
963 Roo.log("Module does not have region defined, skipping");
966 } else if (mod.parent.layout && !mod.module.disabled) {
967 // honour permname setings..
968 if (mod.permname && mod.permname.length) {
969 if (Pman.hasPerm(mod.permname, 'S')) {
970 mod.module.add(mod.parent.layout, mod.region);
973 mod.module.add(mod.parent.layout, mod.region);
979 if (n >= mods.length) {
985 progressRun.defer(10, Pman);
987 progressRun.defer(1, Pman);
993 invertColor : function(c)
997 for(var i = 0; i < 3; i++){
998 ca[i] = parseInt(c.charAt((i*2)+1) + c.charAt((i*2)+2), 16);
1003 Roo.each(ca, function(hi) {
1004 var h = parseInt(255-hi).toString(16);