X-Git-Url: http://git.ithinksw.org/extjs.git/blobdiff_plain/ee06f37b0f6f6d94cd05a6ffae556660f7c4a2bc..c930e9176a5a85509c5b0230e2bff5c22a591432:/src/direct/JsonProvider.js?ds=sidebyside diff --git a/src/direct/JsonProvider.js b/src/direct/JsonProvider.js new file mode 100644 index 00000000..5a370646 --- /dev/null +++ b/src/direct/JsonProvider.js @@ -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 + */ +/** + * @class Ext.direct.JsonProvider + * @extends Ext.direct.Provider + */ +Ext.direct.JsonProvider = Ext.extend(Ext.direct.Provider, { + parseResponse: function(xhr){ + if(!Ext.isEmpty(xhr.responseText)){ + if(typeof xhr.responseText == 'object'){ + return xhr.responseText; + } + return Ext.decode(xhr.responseText); + } + return null; + }, + + getEvents: function(xhr){ + var data = null; + try{ + data = this.parseResponse(xhr); + }catch(e){ + var event = new Ext.Direct.ExceptionEvent({ + data: e, + xhr: xhr, + code: Ext.Direct.exceptions.PARSE, + message: 'Error parsing json response: \n\n ' + data + }) + return [event]; + } + var events = []; + if(Ext.isArray(data)){ + for(var i = 0, len = data.length; i < len; i++){ + events.push(Ext.Direct.createEvent(data[i])); + } + }else{ + events.push(Ext.Direct.createEvent(data)); + } + return events; + } +}); \ No newline at end of file