Pman.Request.js
[Pman.Core] / Pman.Request.js
index e91c513..4cb2ebd 100644 (file)
@@ -8,12 +8,11 @@
 var t = new Pman.Request({
     url: baseURL + '/Images/Download/0/myfile.jpg',
     params: { .... },
-    success : function(data) {
-        
-    },
-    failure : function () {
-         
-    }
+    success : function(res) {
+        Roo.log(res.data);
+        Roo.log(res.total);
+        ....
+    } 
 });
 
 </code></pre>
@@ -22,9 +21,10 @@ var t = new Pman.Request({
 * @param {Object} cfg   Configuration object.
 * @cfg {String} url     Location to download from.
 * @cfg {String} method     GET or POST (default GET), POST will create a form, and post that into the hidden frame.
-* @cfg  {Object/String/Function} (Optional) An object containing properties which are used as parameters to the
+* @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.. )
 */
 
 Pman.Request = function(config){
@@ -34,8 +34,9 @@ Pman.Request = function(config){
 }
 
 Roo.extend(Pman.Request, Roo.data.Connection, {
-    
+    // private
     processResponse : function(response) {
+        // convert the Roo Connection response into JSON data.
         
         var res = '';
         try {
@@ -49,7 +50,11 @@ 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;
     },
@@ -81,10 +86,13 @@ 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) {
-            
+        var res = Roo.callback(options.failure, options.scope, [response, options]);
+        
+        if (res !== true) {
+            var decode = this.processResponse(response);
+                
+            Roo.MessageBox.hide(); // hide any existing messages..
+            Roo.MessageBox.alert("Error", "Error Sending" + decode.errorMsg);
         }
     }
 });
\ No newline at end of file