1 //<script type="text/javascript">
4 * Handles generic requests - an extension of Roo.data.Connection that runs the request
5 * on construction. shows error messages, and parses results.
8 var t = new Pman.Request({
9 url: baseURL + '/Images/Download/0/myfile.jpg',
11 success : function(res) {
21 * @param {Object} cfg Configuration object.
22 * @cfg {String} url Location to download from.
23 * @cfg {String} method GET or POST (default GET), POST will create a form, and post that into the hidden frame.
24 * @cfg {Object/String/Function} params (Optional) An object containing properties which are used as parameters to the
25 * request, a url encoded string or a function to call to get either.
26 * @cfg {Function} success called with ( JSON decoded data of the data.. )
27 * @cfg {Function} success called with ( JSON decoded data of the data.. )
28 * @cfg {Boolean} showFailtureDialog (true|false) default true
31 Pman.Request = function(config){
33 Pman.Request.superclass.constructor.call(this, config);
36 this.maskEl = this.maskEl || Roo.get(document.body);
37 Roo.get(this.maskEl).mask(this.mask);
44 Roo.extend(Pman.Request, Roo.data.Connection, {
46 showFailtureDialog : true,
48 processResponse : function(response) {
49 // convert the Roo Connection response into JSON data.
53 res = Roo.decode(response.responseText);
55 if (typeof(res) != 'object') {
56 res = { success : false, errorMsg : res, errors : true };
58 if (typeof(res.success) == 'undefined') {
63 res = { success : false, errorMsg : response.responseText || Roo.encode(response), errors : true };
65 //Roo.log(response.responseText);
66 if (!res.success && !res.errorMsg) {
67 res.errorMsg = Roo.encode(response);
72 handleResponse : function(response)
75 var options = response.argument.options;
76 response.argument = options ? options.argument : null;
77 this.fireEvent("requestcomplete", this, response, options);
79 if (this.mask && this.maskEl) {
80 Roo.get(this.maskEl).unmask(true);
82 var res = this.processResponse(response);
84 if (!res.success) { // error!
85 if (options.failure) {
86 // failure is handled... - do not show error..
87 Roo.callback(options.failure, options.scope, [res, options]);
90 Roo.MessageBox.hide(); // hide any existing messages..
91 Roo.MessageBox.alert("Error", res && res.errorMsg ? res.errorMsg : "Error Sending data");
94 Roo.callback(options.success, options.scope, [res, options]);
97 handleFailure : function(response, e){
99 var options = response.argument.options;
100 response.argument = options ? options.argument : null;
101 this.fireEvent("requestexception", this, response, options, e);
102 var res = Roo.callback(options.failure, options.scope, [response, options]);
103 if (this.mask && this.maskEl) {
104 Roo.get(this.maskEl).unmask(true);
106 if(!this.showFailtureDialog){
110 var decode = this.processResponse(response);
113 if (Roo.MessageBox.isVisible()) {
114 alert(decode && decode.errorMsg ? decode.errorMsg : "Error Sending data - return true from failure to remove message");
118 Roo.MessageBox.alert("Error", decode && decode.errorMsg ? decode.errorMsg : "Error Sending data");