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.. )
30 Pman.Request = function(config){
32 Pman.Request.superclass.constructor.call(this, config);
35 this.maskEl = this.maskEl || Roo.get(document.body);
36 Roo.get(this.maskEl).mask(this.mask);
43 Roo.extend(Pman.Request, Roo.data.Connection, {
45 processResponse : function(response) {
46 // convert the Roo Connection response into JSON data.
50 res = Roo.decode(response.responseText);
52 if (typeof(res) != 'object') {
53 res = { success : false, errorMsg : res, errors : true };
55 if (typeof(res.success) == 'undefined') {
60 res = { success : false, errorMsg : response.responseText || Roo.encode(response), errors : true };
62 //Roo.log(response.responseText);
63 if (!res.success && !res.errorMsg) {
64 res.errorMsg = Roo.encode(response);
69 handleResponse : function(response)
72 var options = response.argument.options;
73 response.argument = options ? options.argument : null;
74 this.fireEvent("requestcomplete", this, response, options);
76 if (this.mask && this.maskEl) {
77 Roo.get(this.maskEl).unmask();
79 var res = this.processResponse(response);
81 if (!res.success) { // error!
82 if (options.failure) {
83 // failure is handled... - do not show error..
84 Roo.callback(options.failure, options.scope, [res, options]);
87 Roo.MessageBox.hide(); // hide any existing messages..
88 Roo.MessageBox.alert("Error", res && res.errorMsg ? res.errorMsg : "Error Sending data");
91 Roo.callback(options.success, options.scope, [res, options]);
94 handleFailure : function(response, e){
96 var options = response.argument.options;
97 response.argument = options ? options.argument : null;
98 this.fireEvent("requestexception", this, response, options, e);
99 var res = Roo.callback(options.failure, options.scope, [response, options]);
100 if (this.mask && this.maskEl) {
101 Roo.get(this.maskEl).unmask();
104 var decode = this.processResponse(response);
106 if (Roo.MessageBox.isVisible()) {
107 alert(decode && decode.errorMsg ? decode.errorMsg : "Error Sending data");
110 Roo.MessageBox.alert("Error", decode && decode.errorMsg ? decode.errorMsg : "Error Sending data");