4 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
5 <title>The source code</title>
6 <link href="../prettify/prettify.css" type="text/css" rel="stylesheet" />
7 <script type="text/javascript" src="../prettify/prettify.js"></script>
8 <style type="text/css">
9 .highlight { display: block; background-color: #ddd; }
11 <script type="text/javascript">
12 function highlight() {
13 document.getElementById(location.hash.replace(/#/, "")).className = "highlight";
17 <body onload="prettyPrint(); highlight();">
18 <pre class="prettyprint lang-js"><span id='Ext-direct-JsonProvider'>/**
19 </span> * @class Ext.direct.JsonProvider
20 * @extends Ext.direct.Provider
22 A base provider for communicating using JSON. This is an abstract class
23 and should not be instanced directly.
29 Ext.define('Ext.direct.JsonProvider', {
31 /* Begin Definitions */
33 extend: 'Ext.direct.Provider',
35 alias: 'direct.jsonprovider',
37 uses: ['Ext.direct.ExceptionEvent'],
41 <span id='Ext-direct-JsonProvider-method-parseResponse'> /**
42 </span> * Parse the JSON response
44 * @param {Object} response The XHR response object
45 * @return {Object} The data in the response.
47 parseResponse: function(response){
48 if (!Ext.isEmpty(response.responseText)) {
49 if (Ext.isObject(response.responseText)) {
50 return response.responseText;
52 return Ext.decode(response.responseText);
57 <span id='Ext-direct-JsonProvider-method-createEvents'> /**
58 </span> * Creates a set of events based on the XHR response
60 * @param {Object} response The XHR response
61 * @return {Array} An array of Ext.direct.Event
63 createEvents: function(response){
71 data = this.parseResponse(response);
73 event = Ext.create('Ext.direct.ExceptionEvent', {
76 code: Ext.direct.Manager.self.exceptions.PARSE,
77 message: 'Error parsing json response: \n\n ' + data
82 if (Ext.isArray(data)) {
83 for (len = data.length; i < len; ++i) {
84 events.push(this.createEvent(data[i]));
87 events.push(this.createEvent(data));
92 <span id='Ext-direct-JsonProvider-method-createEvent'> /**
93 </span> * Create an event from a response object
94 * @param {Object} response The XHR response object
95 * @return {Ext.direct.Event} The event
97 createEvent: function(response){
98 return Ext.create('direct.' + response.type, response);