Web Interface For Lite Argus Control modules
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

521 lines
25 KiB

​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. <html>
  2. <head>
  3. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  4. <title>The source code</title>
  5. <link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />
  6. <script type="text/javascript" src="../resources/prettify/prettify.js"></script>
  7. </head>
  8. <body onload="prettyPrint();">
  9. <pre class="prettyprint lang-js">/*!
  10. * Ext JS Library 3.3.1
  11. * Copyright(c) 2006-2010 Sencha Inc.
  12. * licensing@sencha.com
  13. * http://www.sencha.com/license
  14. */
  15. <div id="cls-Ext.data.DataProxy"></div>/**
  16. * @class Ext.data.DataProxy
  17. * @extends Ext.util.Observable
  18. * <p>Abstract base class for implementations which provide retrieval of unformatted data objects.
  19. * This class is intended to be extended and should not be created directly. For existing implementations,
  20. * see {@link Ext.data.DirectProxy}, {@link Ext.data.HttpProxy}, {@link Ext.data.ScriptTagProxy} and
  21. * {@link Ext.data.MemoryProxy}.</p>
  22. * <p>DataProxy implementations are usually used in conjunction with an implementation of {@link Ext.data.DataReader}
  23. * (of the appropriate type which knows how to parse the data object) to provide a block of
  24. * {@link Ext.data.Records} to an {@link Ext.data.Store}.</p>
  25. * <p>The parameter to a DataProxy constructor may be an {@link Ext.data.Connection} or can also be the
  26. * config object to an {@link Ext.data.Connection}.</p>
  27. * <p>Custom implementations must implement either the <code><b>doRequest</b></code> method (preferred) or the
  28. * <code>load</code> method (deprecated). See
  29. * {@link Ext.data.HttpProxy}.{@link Ext.data.HttpProxy#doRequest doRequest} or
  30. * {@link Ext.data.HttpProxy}.{@link Ext.data.HttpProxy#load load} for additional details.</p>
  31. * <p><b><u>Example 1</u></b></p>
  32. * <pre><code>
  33. proxy: new Ext.data.ScriptTagProxy({
  34. {@link Ext.data.Connection#url url}: 'http://extjs.com/forum/topics-remote.php'
  35. }),
  36. * </code></pre>
  37. * <p><b><u>Example 2</u></b></p>
  38. * <pre><code>
  39. proxy : new Ext.data.HttpProxy({
  40. {@link Ext.data.Connection#method method}: 'GET',
  41. {@link Ext.data.HttpProxy#prettyUrls prettyUrls}: false,
  42. {@link Ext.data.Connection#url url}: 'local/default.php', // see options parameter for {@link Ext.Ajax#request}
  43. {@link #api}: {
  44. // all actions except the following will use above url
  45. create : 'local/new.php',
  46. update : 'local/update.php'
  47. }
  48. }),
  49. * </code></pre>
  50. * <p>And <b>new in Ext version 3</b>, attach centralized event-listeners upon the DataProxy class itself! This is a great place
  51. * to implement a <i>messaging system</i> to centralize your application's user-feedback and error-handling.</p>
  52. * <pre><code>
  53. // Listen to all "beforewrite" event fired by all proxies.
  54. Ext.data.DataProxy.on('beforewrite', function(proxy, action) {
  55. console.log('beforewrite: ', action);
  56. });
  57. // Listen to "write" event fired by all proxies
  58. Ext.data.DataProxy.on('write', function(proxy, action, data, res, rs) {
  59. console.info('write: ', action);
  60. });
  61. // Listen to "exception" event fired by all proxies
  62. Ext.data.DataProxy.on('exception', function(proxy, type, action, exception) {
  63. console.error(type + action + ' exception);
  64. });
  65. * </code></pre>
  66. * <b>Note:</b> These three events are all fired with the signature of the corresponding <i>DataProxy instance</i> event {@link #beforewrite beforewrite}, {@link #write write} and {@link #exception exception}.
  67. */
  68. Ext.data.DataProxy = function(conn){
  69. // make sure we have a config object here to support ux proxies.
  70. // All proxies should now send config into superclass constructor.
  71. conn = conn || {};
  72. // This line caused a bug when people use custom Connection object having its own request method.
  73. // http://extjs.com/forum/showthread.php?t=67194. Have to set DataProxy config
  74. //Ext.applyIf(this, conn);
  75. this.api = conn.api;
  76. this.url = conn.url;
  77. this.restful = conn.restful;
  78. this.listeners = conn.listeners;
  79. // deprecated
  80. this.prettyUrls = conn.prettyUrls;
  81. <div id="cfg-Ext.data.DataProxy-api"></div>/**
  82. * @cfg {Object} api
  83. * Specific urls to call on CRUD action methods "read", "create", "update" and "destroy".
  84. * Defaults to:<pre><code>
  85. api: {
  86. read : undefined,
  87. create : undefined,
  88. update : undefined,
  89. destroy : undefined
  90. }
  91. * </code></pre>
  92. * <p>The url is built based upon the action being executed <tt>[load|create|save|destroy]</tt>
  93. * using the commensurate <tt>{@link #api}</tt> property, or if undefined default to the
  94. * configured {@link Ext.data.Store}.{@link Ext.data.Store#url url}.</p><br>
  95. * <p>For example:</p>
  96. * <pre><code>
  97. api: {
  98. load : '/controller/load',
  99. create : '/controller/new', // Server MUST return idProperty of new record
  100. save : '/controller/update',
  101. destroy : '/controller/destroy_action'
  102. }
  103. // Alternatively, one can use the object-form to specify each API-action
  104. api: {
  105. load: {url: 'read.php', method: 'GET'},
  106. create: 'create.php',
  107. destroy: 'destroy.php',
  108. save: 'update.php'
  109. }
  110. * </code></pre>
  111. * <p>If the specific URL for a given CRUD action is undefined, the CRUD action request
  112. * will be directed to the configured <tt>{@link Ext.data.Connection#url url}</tt>.</p>
  113. * <br><p><b>Note</b>: To modify the URL for an action dynamically the appropriate API
  114. * property should be modified before the action is requested using the corresponding before
  115. * action event. For example to modify the URL associated with the load action:
  116. * <pre><code>
  117. // modify the url for the action
  118. myStore.on({
  119. beforeload: {
  120. fn: function (store, options) {
  121. // use <tt>{@link Ext.data.HttpProxy#setUrl setUrl}</tt> to change the URL for *just* this request.
  122. store.proxy.setUrl('changed1.php');
  123. // set optional second parameter to true to make this URL change
  124. // permanent, applying this URL for all subsequent requests.
  125. store.proxy.setUrl('changed1.php', true);
  126. // Altering the proxy API should be done using the public
  127. // method <tt>{@link Ext.data.DataProxy#setApi setApi}</tt>.
  128. store.proxy.setApi('read', 'changed2.php');
  129. // Or set the entire API with a config-object.
  130. // When using the config-object option, you must redefine the <b>entire</b>
  131. // API -- not just a specific action of it.
  132. store.proxy.setApi({
  133. read : 'changed_read.php',
  134. create : 'changed_create.php',
  135. update : 'changed_update.php',
  136. destroy : 'changed_destroy.php'
  137. });
  138. }
  139. }
  140. });
  141. * </code></pre>
  142. * </p>
  143. */
  144. this.addEvents(
  145. <div id="event-Ext.data.DataProxy-exception"></div>/**
  146. * @event exception
  147. * <p>Fires if an exception occurs in the Proxy during a remote request. This event is relayed
  148. * through a corresponding {@link Ext.data.Store}.{@link Ext.data.Store#exception exception},
  149. * so any Store instance may observe this event.</p>
  150. * <p>In addition to being fired through the DataProxy instance that raised the event, this event is also fired
  151. * through the Ext.data.DataProxy <i>class</i> to allow for centralized processing of exception events from <b>all</b>
  152. * DataProxies by attaching a listener to the Ext.data.DataProxy class itself.</p>
  153. * <p>This event can be fired for one of two reasons:</p>
  154. * <div class="mdetail-params"><ul>
  155. * <li>remote-request <b>failed</b> : <div class="sub-desc">
  156. * The server did not return status === 200.
  157. * </div></li>
  158. * <li>remote-request <b>succeeded</b> : <div class="sub-desc">
  159. * The remote-request succeeded but the reader could not read the response.
  160. * This means the server returned data, but the configured Reader threw an
  161. * error while reading the response. In this case, this event will be
  162. * raised and the caught error will be passed along into this event.
  163. * </div></li>
  164. * </ul></div>
  165. * <br><p>This event fires with two different contexts based upon the 2nd
  166. * parameter <tt>type [remote|response]</tt>. The first four parameters
  167. * are identical between the two contexts -- only the final two parameters
  168. * differ.</p>
  169. * @param {DataProxy} this The proxy that sent the request
  170. * @param {String} type
  171. * <p>The value of this parameter will be either <tt>'response'</tt> or <tt>'remote'</tt>.</p>
  172. * <div class="mdetail-params"><ul>
  173. * <li><b><tt>'response'</tt></b> : <div class="sub-desc">
  174. * <p>An <b>invalid</b> response from the server was returned: either 404,
  175. * 500 or the response meta-data does not match that defined in the DataReader
  176. * (e.g.: root, idProperty, successProperty).</p>
  177. * </div></li>
  178. * <li><b><tt>'remote'</tt></b> : <div class="sub-desc">
  179. * <p>A <b>valid</b> response was returned from the server having
  180. * successProperty === false. This response might contain an error-message
  181. * sent from the server. For example, the user may have failed
  182. * authentication/authorization or a database validation error occurred.</p>
  183. * </div></li>
  184. * </ul></div>
  185. * @param {String} action Name of the action (see {@link Ext.data.Api#actions}.
  186. * @param {Object} options The options for the action that were specified in the {@link #request}.
  187. * @param {Object} response
  188. * <p>The value of this parameter depends on the value of the <code>type</code> parameter:</p>
  189. * <div class="mdetail-params"><ul>
  190. * <li><b><tt>'response'</tt></b> : <div class="sub-desc">
  191. * <p>The raw browser response object (e.g.: XMLHttpRequest)</p>
  192. * </div></li>
  193. * <li><b><tt>'remote'</tt></b> : <div class="sub-desc">
  194. * <p>The decoded response object sent from the server.</p>
  195. * </div></li>
  196. * </ul></div>
  197. * @param {Mixed} arg
  198. * <p>The type and value of this parameter depends on the value of the <code>type</code> parameter:</p>
  199. * <div class="mdetail-params"><ul>
  200. * <li><b><tt>'response'</tt></b> : Error<div class="sub-desc">
  201. * <p>The JavaScript Error object caught if the configured Reader could not read the data.
  202. * If the remote request returns success===false, this parameter will be null.</p>
  203. * </div></li>
  204. * <li><b><tt>'remote'</tt></b> : Record/Record[]<div class="sub-desc">
  205. * <p>This parameter will only exist if the <tt>action</tt> was a <b>write</b> action
  206. * (Ext.data.Api.actions.create|update|destroy).</p>
  207. * </div></li>
  208. * </ul></div>
  209. */
  210. 'exception',
  211. <div id="event-Ext.data.DataProxy-beforeload"></div>/**
  212. * @event beforeload
  213. * Fires before a request to retrieve a data object.
  214. * @param {DataProxy} this The proxy for the request
  215. * @param {Object} params The params object passed to the {@link #request} function
  216. */
  217. 'beforeload',
  218. <div id="event-Ext.data.DataProxy-load"></div>/**
  219. * @event load
  220. * Fires before the load method's callback is called.
  221. * @param {DataProxy} this The proxy for the request
  222. * @param {Object} o The request transaction object
  223. * @param {Object} options The callback's <tt>options</tt> property as passed to the {@link #request} function
  224. */
  225. 'load',
  226. <div id="event-Ext.data.DataProxy-loadexception"></div>/**
  227. * @event loadexception
  228. * <p>This event is <b>deprecated</b>. The signature of the loadexception event
  229. * varies depending on the proxy, use the catch-all {@link #exception} event instead.
  230. * This event will fire in addition to the {@link #exception} event.</p>
  231. * @param {misc} misc See {@link #exception}.
  232. * @deprecated
  233. */
  234. 'loadexception',
  235. <div id="event-Ext.data.DataProxy-beforewrite"></div>/**
  236. * @event beforewrite
  237. * <p>Fires before a request is generated for one of the actions Ext.data.Api.actions.create|update|destroy</p>
  238. * <p>In addition to being fired through the DataProxy instance that raised the event, this event is also fired
  239. * through the Ext.data.DataProxy <i>class</i> to allow for centralized processing of beforewrite events from <b>all</b>
  240. * DataProxies by attaching a listener to the Ext.data.DataProxy class itself.</p>
  241. * @param {DataProxy} this The proxy for the request
  242. * @param {String} action [Ext.data.Api.actions.create|update|destroy]
  243. * @param {Record/Record[]} rs The Record(s) to create|update|destroy.
  244. * @param {Object} params The request <code>params</code> object. Edit <code>params</code> to add parameters to the request.
  245. */
  246. 'beforewrite',
  247. <div id="event-Ext.data.DataProxy-write"></div>/**
  248. * @event write
  249. * <p>Fires before the request-callback is called</p>
  250. * <p>In addition to being fired through the DataProxy instance that raised the event, this event is also fired
  251. * through the Ext.data.DataProxy <i>class</i> to allow for centralized processing of write events from <b>all</b>
  252. * DataProxies by attaching a listener to the Ext.data.DataProxy class itself.</p>
  253. * @param {DataProxy} this The proxy that sent the request
  254. * @param {String} action [Ext.data.Api.actions.create|upate|destroy]
  255. * @param {Object} data The data object extracted from the server-response
  256. * @param {Object} response The decoded response from server
  257. * @param {Record/Record[]} rs The Record(s) from Store
  258. * @param {Object} options The callback's <tt>options</tt> property as passed to the {@link #request} function
  259. */
  260. 'write'
  261. );
  262. Ext.data.DataProxy.superclass.constructor.call(this);
  263. // Prepare the proxy api. Ensures all API-actions are defined with the Object-form.
  264. try {
  265. Ext.data.Api.prepare(this);
  266. } catch (e) {
  267. if (e instanceof Ext.data.Api.Error) {
  268. e.toConsole();
  269. }
  270. }
  271. // relay each proxy's events onto Ext.data.DataProxy class for centralized Proxy-listening
  272. Ext.data.DataProxy.relayEvents(this, ['beforewrite', 'write', 'exception']);
  273. };
  274. Ext.extend(Ext.data.DataProxy, Ext.util.Observable, {
  275. <div id="cfg-Ext.data.DataProxy-restful"></div>/**
  276. * @cfg {Boolean} restful
  277. * <p>Defaults to <tt>false</tt>. Set to <tt>true</tt> to operate in a RESTful manner.</p>
  278. * <br><p> Note: this parameter will automatically be set to <tt>true</tt> if the
  279. * {@link Ext.data.Store} it is plugged into is set to <code>restful: true</code>. If the
  280. * Store is RESTful, there is no need to set this option on the proxy.</p>
  281. * <br><p>RESTful implementations enable the serverside framework to automatically route
  282. * actions sent to one url based upon the HTTP method, for example:
  283. * <pre><code>
  284. store: new Ext.data.Store({
  285. restful: true,
  286. proxy: new Ext.data.HttpProxy({url:'/users'}); // all requests sent to /users
  287. ...
  288. )}
  289. * </code></pre>
  290. * If there is no <code>{@link #api}</code> specified in the configuration of the proxy,
  291. * all requests will be marshalled to a single RESTful url (/users) so the serverside
  292. * framework can inspect the HTTP Method and act accordingly:
  293. * <pre>
  294. <u>Method</u> <u>url</u> <u>action</u>
  295. POST /users create
  296. GET /users read
  297. PUT /users/23 update
  298. DESTROY /users/23 delete
  299. * </pre></p>
  300. * <p>If set to <tt>true</tt>, a {@link Ext.data.Record#phantom non-phantom} record's
  301. * {@link Ext.data.Record#id id} will be appended to the url. Some MVC (e.g., Ruby on Rails,
  302. * Merb and Django) support segment based urls where the segments in the URL follow the
  303. * Model-View-Controller approach:<pre><code>
  304. * someSite.com/controller/action/id
  305. * </code></pre>
  306. * Where the segments in the url are typically:<div class="mdetail-params"><ul>
  307. * <li>The first segment : represents the controller class that should be invoked.</li>
  308. * <li>The second segment : represents the class function, or method, that should be called.</li>
  309. * <li>The third segment : represents the ID (a variable typically passed to the method).</li>
  310. * </ul></div></p>
  311. * <br><p>Refer to <code>{@link Ext.data.DataProxy#api}</code> for additional information.</p>
  312. */
  313. restful: false,
  314. <div id="method-Ext.data.DataProxy-setApi"></div>/**
  315. * <p>Redefines the Proxy's API or a single action of an API. Can be called with two method signatures.</p>
  316. * <p>If called with an object as the only parameter, the object should redefine the <b>entire</b> API, e.g.:</p><pre><code>
  317. proxy.setApi({
  318. read : '/users/read',
  319. create : '/users/create',
  320. update : '/users/update',
  321. destroy : '/users/destroy'
  322. });
  323. </code></pre>
  324. * <p>If called with two parameters, the first parameter should be a string specifying the API action to
  325. * redefine and the second parameter should be the URL (or function if using DirectProxy) to call for that action, e.g.:</p><pre><code>
  326. proxy.setApi(Ext.data.Api.actions.read, '/users/new_load_url');
  327. </code></pre>
  328. * @param {String/Object} api An API specification object, or the name of an action.
  329. * @param {String/Function} url The URL (or function if using DirectProxy) to call for the action.
  330. */
  331. setApi : function() {
  332. if (arguments.length == 1) {
  333. var valid = Ext.data.Api.isValid(arguments[0]);
  334. if (valid === true) {
  335. this.api = arguments[0];
  336. }
  337. else {
  338. throw new Ext.data.Api.Error('invalid', valid);
  339. }
  340. }
  341. else if (arguments.length == 2) {
  342. if (!Ext.data.Api.isAction(arguments[0])) {
  343. throw new Ext.data.Api.Error('invalid', arguments[0]);
  344. }
  345. this.api[arguments[0]] = arguments[1];
  346. }
  347. Ext.data.Api.prepare(this);
  348. },
  349. <div id="method-Ext.data.DataProxy-isApiAction"></div>/**
  350. * Returns true if the specified action is defined as a unique action in the api-config.
  351. * request. If all API-actions are routed to unique urls, the xaction parameter is unecessary. However, if no api is defined
  352. * and all Proxy actions are routed to DataProxy#url, the server-side will require the xaction parameter to perform a switch to
  353. * the corresponding code for CRUD action.
  354. * @param {String [Ext.data.Api.CREATE|READ|UPDATE|DESTROY]} action
  355. * @return {Boolean}
  356. */
  357. isApiAction : function(action) {
  358. return (this.api[action]) ? true : false;
  359. },
  360. <div id="method-Ext.data.DataProxy-request"></div>/**
  361. * All proxy actions are executed through this method. Automatically fires the "before" + action event
  362. * @param {String} action Name of the action
  363. * @param {Ext.data.Record/Ext.data.Record[]/null} rs Will be null when action is 'load'
  364. * @param {Object} params
  365. * @param {Ext.data.DataReader} reader
  366. * @param {Function} callback
  367. * @param {Object} scope The scope (<code>this</code> reference) in which the callback function is executed. Defaults to the Proxy object.
  368. * @param {Object} options Any options specified for the action (e.g. see {@link Ext.data.Store#load}.
  369. */
  370. request : function(action, rs, params, reader, callback, scope, options) {
  371. if (!this.api[action] && !this.load) {
  372. throw new Ext.data.DataProxy.Error('action-undefined', action);
  373. }
  374. params = params || {};
  375. if ((action === Ext.data.Api.actions.read) ? this.fireEvent("beforeload", this, params) : this.fireEvent("beforewrite", this, action, rs, params) !== false) {
  376. this.doRequest.apply(this, arguments);
  377. }
  378. else {
  379. callback.call(scope || this, null, options, false);
  380. }
  381. },
  382. <div id="method-Ext.data.DataProxy-load"></div>/**
  383. * <b>Deprecated</b> load method using old method signature. See {@doRequest} for preferred method.
  384. * @deprecated
  385. * @param {Object} params
  386. * @param {Object} reader
  387. * @param {Object} callback
  388. * @param {Object} scope
  389. * @param {Object} arg
  390. */
  391. load : null,
  392. <div id="cfg-Ext.data.DataProxy-doRequest"></div>/**
  393. * @cfg {Function} doRequest Abstract method that should be implemented in all subclasses. <b>Note:</b> Should only be used by custom-proxy developers.
  394. * (e.g.: {@link Ext.data.HttpProxy#doRequest HttpProxy.doRequest},
  395. * {@link Ext.data.DirectProxy#doRequest DirectProxy.doRequest}).
  396. */
  397. doRequest : function(action, rs, params, reader, callback, scope, options) {
  398. // default implementation of doRequest for backwards compatibility with 2.0 proxies.
  399. // If we're executing here, the action is probably "load".
  400. // Call with the pre-3.0 method signature.
  401. this.load(params, reader, callback, scope, options);
  402. },
  403. <div id="cfg-Ext.data.DataProxy-onRead"></div>/**
  404. * @cfg {Function} onRead Abstract method that should be implemented in all subclasses. <b>Note:</b> Should only be used by custom-proxy developers. Callback for read {@link Ext.data.Api#actions action}.
  405. * @param {String} action Action name as per {@link Ext.data.Api.actions#read}.
  406. * @param {Object} o The request transaction object
  407. * @param {Object} res The server response
  408. * @fires loadexception (deprecated)
  409. * @fires exception
  410. * @fires load
  411. * @protected
  412. */
  413. onRead : Ext.emptyFn,
  414. <div id="cfg-Ext.data.DataProxy-onWrite"></div>/**
  415. * @cfg {Function} onWrite Abstract method that should be implemented in all subclasses. <b>Note:</b> Should only be used by custom-proxy developers. Callback for <i>create, update and destroy</i> {@link Ext.data.Api#actions actions}.
  416. * @param {String} action [Ext.data.Api.actions.create|read|update|destroy]
  417. * @param {Object} trans The request transaction object
  418. * @param {Object} res The server response
  419. * @fires exception
  420. * @fires write
  421. * @protected
  422. */
  423. onWrite : Ext.emptyFn,
  424. /**
  425. * buildUrl
  426. * Sets the appropriate url based upon the action being executed. If restful is true, and only a single record is being acted upon,
  427. * url will be built Rails-style, as in "/controller/action/32". restful will aply iff the supplied record is an
  428. * instance of Ext.data.Record rather than an Array of them.
  429. * @param {String} action The api action being executed [read|create|update|destroy]
  430. * @param {Ext.data.Record/Ext.data.Record[]} record The record or Array of Records being acted upon.
  431. * @return {String} url
  432. * @private
  433. */
  434. buildUrl : function(action, record) {
  435. record = record || null;
  436. // conn.url gets nullified after each request. If it's NOT null here, that means the user must have intervened with a call
  437. // to DataProxy#setUrl or DataProxy#setApi and changed it before the request was executed. If that's the case, use conn.url,
  438. // otherwise, build the url from the api or this.url.
  439. var url = (this.conn && this.conn.url) ? this.conn.url : (this.api[action]) ? this.api[action].url : this.url;
  440. if (!url) {
  441. throw new Ext.data.Api.Error('invalid-url', action);
  442. }
  443. // look for urls having "provides" suffix used in some MVC frameworks like Rails/Merb and others. The provides suffice informs
  444. // the server what data-format the client is dealing with and returns data in the same format (eg: application/json, application/xml, etc)
  445. // e.g.: /users.json, /users.xml, etc.
  446. // with restful routes, we need urls like:
  447. // PUT /users/1.json
  448. // DELETE /users/1.json
  449. var provides = null;
  450. var m = url.match(/(.*)(\.json|\.xml|\.html)$/);
  451. if (m) {
  452. provides = m[2]; // eg ".json"
  453. url = m[1]; // eg: "/users"
  454. }
  455. // prettyUrls is deprectated in favor of restful-config
  456. if ((this.restful === true || this.prettyUrls === true) && record instanceof Ext.data.Record && !record.phantom) {
  457. url += '/' + record.id;
  458. }
  459. return (provides === null) ? url : url + provides;
  460. },
  461. <div id="method-Ext.data.DataProxy-destroy"></div>/**
  462. * Destroys the proxy by purging any event listeners and cancelling any active requests.
  463. */
  464. destroy: function(){
  465. this.purgeListeners();
  466. }
  467. });
  468. // Apply the Observable prototype to the DataProxy class so that proxy instances can relay their
  469. // events to the class. Allows for centralized listening of all proxy instances upon the DataProxy class.
  470. Ext.apply(Ext.data.DataProxy, Ext.util.Observable.prototype);
  471. Ext.util.Observable.call(Ext.data.DataProxy);
  472. <div id="cls-Ext.data.DataProxy.Error"></div>/**
  473. * @class Ext.data.DataProxy.Error
  474. * @extends Ext.Error
  475. * DataProxy Error extension.
  476. * constructor
  477. * @param {String} message Message describing the error.
  478. * @param {Record/Record[]} arg
  479. */
  480. Ext.data.DataProxy.Error = Ext.extend(Ext.Error, {
  481. constructor : function(message, arg) {
  482. this.arg = arg;
  483. Ext.Error.call(this, message);
  484. },
  485. name: 'Ext.data.DataProxy'
  486. });
  487. Ext.apply(Ext.data.DataProxy.Error.prototype, {
  488. lang: {
  489. 'action-undefined': "DataProxy attempted to execute an API-action but found an undefined url / function. Please review your Proxy url/api-configuration.",
  490. 'api-invalid': 'Recieved an invalid API-configuration. Please ensure your proxy API-configuration contains only the actions from Ext.data.Api.actions.'
  491. }
  492. });
  493. </pre>
  494. </body>
  495. </html>