Upgrade to ExtJS 3.0.0 - Released 07/06/2009
[extjs.git] / src / direct / JsonProvider.js
diff --git a/src/direct/JsonProvider.js b/src/direct/JsonProvider.js
new file mode 100644 (file)
index 0000000..5a37064
--- /dev/null
@@ -0,0 +1,45 @@
+/*!
+ * Ext JS Library 3.0.0
+ * Copyright(c) 2006-2009 Ext JS, LLC
+ * licensing@extjs.com
+ * http://www.extjs.com/license
+ */
+/**\r
+ * @class Ext.direct.JsonProvider\r
+ * @extends Ext.direct.Provider\r
+ */\r
+Ext.direct.JsonProvider = Ext.extend(Ext.direct.Provider, {\r
+    parseResponse: function(xhr){\r
+        if(!Ext.isEmpty(xhr.responseText)){\r
+            if(typeof xhr.responseText == 'object'){\r
+                return xhr.responseText;\r
+            }\r
+            return Ext.decode(xhr.responseText);\r
+        }\r
+        return null;\r
+    },\r
+\r
+    getEvents: function(xhr){\r
+        var data = null;\r
+        try{\r
+            data = this.parseResponse(xhr);\r
+        }catch(e){\r
+            var event = new Ext.Direct.ExceptionEvent({\r
+                data: e,\r
+                xhr: xhr,\r
+                code: Ext.Direct.exceptions.PARSE,\r
+                message: 'Error parsing json response: \n\n ' + data\r
+            })\r
+            return [event];\r
+        }\r
+        var events = [];\r
+        if(Ext.isArray(data)){\r
+            for(var i = 0, len = data.length; i < len; i++){\r
+                events.push(Ext.Direct.createEvent(data[i]));\r
+            }\r
+        }else{\r
+            events.push(Ext.Direct.createEvent(data));\r
+        }\r
+        return events;\r
+    }\r
+});
\ No newline at end of file