public/javascripts/erp_app/utility.js in erp_app-3.1.2 vs public/javascripts/erp_app/utility.js in erp_app-3.1.3

- old
+ new

@@ -1,17 +1,17 @@ Ext.ns("Compass.ErpApp.Utility"); //handle session timeout Compass.ErpApp.Utility.SessionTimeout = { - enabled:false, - redirectTo:null, - warnInMilliseconds:null, - warnTimer:null, - redirectInMilliseconds:null, - redirectTimer:null, + enabled: false, + redirectTo: null, + warnInMilliseconds: null, + warnTimer: null, + redirectInMilliseconds: null, + redirectTimer: null, - setForceRedirectTimer:function (action) { + setForceRedirectTimer: function (action) { switch (action) { case 'start': var self = this; this.redirectTimer = window.setTimeout(function () { window.location = self.redirectTo; @@ -20,26 +20,24 @@ case 'stop': clearTimeout(this.redirectTimer); break; } }, - setWarnTimer:function (action) { + setWarnTimer: function (action) { switch (action) { case 'start': var self = this; this.warnTimer = window.setTimeout(function () { - Ext.MessageBox.confirm('Confirm', 'Your session is about to expire due to inactivity. Do you wish to continue this session?', function(btn){ - if(btn == 'no'){ + Ext.MessageBox.confirm('Confirm', 'Your session is about to expire due to inactivity. Do you wish to continue this session?', function (btn) { + if (btn == 'no') { window.location = self.redirectTo; } - else - if(btn == 'yes') - { + else if (btn == 'yes') { Ext.Ajax.request({ - method:'POST', - url:'/session/keep_alive', - success: function( result, request ){ + method: 'POST', + url: '/session/keep_alive', + success: function (result, request) { self.reset(); } }); } }); @@ -48,11 +46,11 @@ case 'stop': clearTimeout(this.warnTimer); break; } }, - setupSessionTimeout:function (warnInMilliseconds, redirectInMilliseconds, redirectTo) { + setupSessionTimeout: function (warnInMilliseconds, redirectInMilliseconds, redirectTo) { var self = this; Ext.Ajax.addListener('requestcomplete', this.reset, this); this.enabled = true; this.redirectTo = redirectTo; @@ -60,11 +58,11 @@ this.redirectInMilliseconds = redirectInMilliseconds; this.setForceRedirectTimer('start'); this.setWarnTimer('start'); }, - reset:function () { + reset: function () { this.setWarnTimer('stop'); this.setForceRedirectTimer('stop'); this.setWarnTimer('start'); this.setForceRedirectTimer('start'); @@ -256,47 +254,48 @@ num = num.substring(0, num.length - (4 * i + 3)) + ',' + num.substring(num.length - (4 * i + 3)); return (((sign) ? '' : '-') + '$' + num + '.' + cents); }; -Compass.ErpApp.Utility.JsLoader = { - load:function (url, successCallback) { +function OnDemandLoadByAjax(){ + this.load = function (components, callback) { + this.components = components; + this.successCallBack = callback; this.attempts = 0; - this.successCallBack = successCallback; this.scriptsToLoad = []; - if (!Compass.ErpApp.Utility.isArray(url)) { - url = [url]; + if (!Compass.ErpApp.Utility.isArray(this.components)) { + this.components = [this.components]; } - for (var i = 0; i < url.length; i++) { + for (var i = 0; i < this.components.length; i++) { this.scriptsToLoad.push({ - url:url[i], - status:'pending' + url: this.components[i], + status: 'pending' }); } for (var t = 0; t < this.scriptsToLoad.length; t++) { this.loadScript(this.scriptsToLoad[t]); } - }, + }; - allScriptsDone:function () { + this.allScriptsDone = function () { for (var i = 0; i < this.scriptsToLoad.length; i++) { if (this.scriptsToLoad[i].status == 'pending') return false; } return true; - }, + }; - scriptDone:function () { + this.scriptDone = function () { if (this.allScriptsDone()) { this.onSuccess(); } - }, + }; - loadScript:function (scriptToLoad) { + this.loadScript = function (scriptToLoad) { var self = this; var ss = document.getElementsByTagName("script"); for (i = 0; i < ss.length; i++) { if (ss[i].src && ss[i].src.indexOf(scriptToLoad.url) != -1) { scriptToLoad.status = 'success'; @@ -318,19 +317,20 @@ s.onerror = function () { head.removeChild(s); scriptToLoad.status = 'failure'; self.scriptDone(); } - }, + }; - onSuccess:function () { - if(!Ext.isEmpty(this.successCallBack) && this.successCallBack){ + this.onSuccess = function () { + if (!Ext.isEmpty(this.successCallBack) && this.successCallBack) { this.successCallBack(); } - }, - onFailure:function () { - } + }; + + this.onFailure = function () { + }; }; //Javascript Extensions //Array Extensions @@ -421,28 +421,28 @@ String.prototype.upcase = function () { return this.toUpperCase(); }; -String.prototype.camelize = function() { - var parts = this.replace(/_/,'-').split('-'), len = parts.length; +String.prototype.camelize = function () { + var parts = this.replace(/_/, '-').split('-'), len = parts.length; if (len == 1) return parts[0]; var camelized = this.charAt(0) == '-' - ? parts[0].charAt(0).toUpperCase() + parts[0].substring(1) - : parts[0]; + ? parts[0].charAt(0).toUpperCase() + parts[0].substring(1) + : parts[0]; for (var i = 1; i < len; i++) - camelized += parts[i].charAt(0).toUpperCase() + parts[i].substring(1); + camelized += parts[i].charAt(0).toUpperCase() + parts[i].substring(1); return camelized; }; -String.prototype.titleize = function() { - var parts = this.replace(/_/,'-').split('-'), len = parts.length, titleized = ''; - for (var i = 0; i < len; i++){ - if (i > 0) titleized += ' '; - titleized += parts[i].charAt(0).toUpperCase() + parts[i].substring(1); +String.prototype.titleize = function () { + var parts = this.replace(/_/, '-').split('-'), len = parts.length, titleized = ''; + for (var i = 0; i < len; i++) { + if (i > 0) titleized += ' '; + titleized += parts[i].charAt(0).toUpperCase() + parts[i].substring(1); } return titleized; };