X-Git-Url: http://git.roojs.org/?p=Pman.Core;a=blobdiff_plain;f=Pman.Request.js;h=b4db0f0783dd2c3c096a2fea9cc96d53ec154817;hp=38a35ef6bc883eb240f5c0a4c9480f82badc2e0f;hb=refs%2Fheads%2Fwip_edward_T5851_download_old_offer_sheet;hpb=257ddb97d208a0083b4531605c08590c944b1901 diff --git a/Pman.Request.js b/Pman.Request.js index 38a35ef6..b4db0f07 100644 --- a/Pman.Request.js +++ b/Pman.Request.js @@ -12,10 +12,7 @@ var t = new Pman.Request({ Roo.log(res.data); Roo.log(res.total); .... - }, - failure : function () { - - } + } }); @@ -27,19 +24,31 @@ var t = new Pman.Request({ * @cfg {Object/String/Function} params (Optional) An object containing properties which are used as parameters to the * request, a url encoded string or a function to call to get either. * @cfg {Function} success called with ( JSON decoded data of the data.. ) +* @cfg {Function} success called with ( JSON decoded data of the data.. ) +* @cfg {Boolean} showFailureDialog (true|false) default true */ Pman.Request = function(config){ Pman.Request.superclass.constructor.call(this, config); + + if (this.mask) { + this.maskEl = this.maskEl || Roo.get(document.body); + Roo.get(this.maskEl).mask(this.mask); + + } this.request(config); + } Roo.extend(Pman.Request, Roo.data.Connection, { + // private + showFailureDialog : true, processResponse : function(response) { + // convert the Roo Connection response into JSON data. - var res = ''; + var res; try { res = Roo.decode(response.responseText); // oops... @@ -51,28 +60,35 @@ Roo.extend(Pman.Request, Roo.data.Connection, { } } catch(e) { - res = { success : false, errorMsg : response.responseText, errors : true }; + res = { success : false, errorMsg : response.responseText || Roo.encode(response), errors : true }; + } + //Roo.log(response.responseText); + if (!res.success && !res.errorMsg) { + res.errorMsg = Roo.encode(response); } return res; }, - handleResponse : function(response){ - this.transId = false; - var options = response.argument.options; - response.argument = options ? options.argument : null; - this.fireEvent("requestcomplete", this, response, options); - + handleResponse : function(response) + { + this.transId = false; + var options = response.argument.options; + response.argument = options ? options.argument : null; + this.fireEvent("requestcomplete", this, response, options); + + if (this.mask && this.maskEl) { + Roo.get(this.maskEl).unmask(true); + } var res = this.processResponse(response); if (!res.success) { // error! if (options.failure) { // failure is handled... - do not show error.. - if (true === Roo.callback(options.failure, options.scope, [res, options])) { - return; - } + Roo.callback(options.failure, options.scope, [res, options]); + return; } Roo.MessageBox.hide(); // hide any existing messages.. - Roo.MessageBox.alert("Error", res.errorMsg ? res.errorMsg : "Error Sending"); + Roo.MessageBox.alert("Error", res && res.errorMsg ? res.errorMsg : "Error Sending data"); return; } Roo.callback(options.success, options.scope, [res, options]); @@ -83,11 +99,24 @@ Roo.extend(Pman.Request, Roo.data.Connection, { var options = response.argument.options; response.argument = options ? options.argument : null; this.fireEvent("requestexception", this, response, options, e); - Roo.callback(options.failure, options.scope, [response, options]); - Roo.callback(options.callback, options.scope, [options, false, response]); - if (!options.failure) { - Roo.MessageBox.hide(); // hide any existing messages.. - Roo.MessageBox.alert("Error", res.errorMsg ? res.errorMsg : "Error Sending"); + var res = Roo.callback(options.failure, options.scope, [response, options]); + if (this.mask && this.maskEl) { + Roo.get(this.maskEl).unmask(true); + } + if(!this.showFailureDialog){ + return; + } + if (res !== true) { + var decode = this.processResponse(response); + Roo.log(decode); + + if (Roo.MessageBox.isVisible()) { + alert(decode && decode.errorMsg ? decode.errorMsg : "Error Sending data - return true from failure to remove message"); + return; + } + + Roo.MessageBox.alert("Error", decode && decode.errorMsg ? decode.errorMsg : "Error Sending data"); + } } -}); \ No newline at end of file +});