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.

295 lines
12 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.Api"></div>/**
  16. * @class Ext.data.Api
  17. * @extends Object
  18. * Ext.data.Api is a singleton designed to manage the data API including methods
  19. * for validating a developer's DataProxy API. Defines variables for CRUD actions
  20. * create, read, update and destroy in addition to a mapping of RESTful HTTP methods
  21. * GET, POST, PUT and DELETE to CRUD actions.
  22. * @singleton
  23. */
  24. Ext.data.Api = (function() {
  25. // private validActions. validActions is essentially an inverted hash of Ext.data.Api.actions, where value becomes the key.
  26. // Some methods in this singleton (e.g.: getActions, getVerb) will loop through actions with the code <code>for (var verb in this.actions)</code>
  27. // For efficiency, some methods will first check this hash for a match. Those methods which do acces validActions will cache their result here.
  28. // We cannot pre-define this hash since the developer may over-ride the actions at runtime.
  29. var validActions = {};
  30. return {
  31. <div id="prop-Ext.data.Api-actions"></div>/**
  32. * Defined actions corresponding to remote actions:
  33. * <pre><code>
  34. actions: {
  35. create : 'create', // Text representing the remote-action to create records on server.
  36. read : 'read', // Text representing the remote-action to read/load data from server.
  37. update : 'update', // Text representing the remote-action to update records on server.
  38. destroy : 'destroy' // Text representing the remote-action to destroy records on server.
  39. }
  40. * </code></pre>
  41. * @property actions
  42. * @type Object
  43. */
  44. actions : {
  45. create : 'create',
  46. read : 'read',
  47. update : 'update',
  48. destroy : 'destroy'
  49. },
  50. <div id="prop-Ext.data.Api-restActions"></div>/**
  51. * Defined {CRUD action}:{HTTP method} pairs to associate HTTP methods with the
  52. * corresponding actions for {@link Ext.data.DataProxy#restful RESTful proxies}.
  53. * Defaults to:
  54. * <pre><code>
  55. restActions : {
  56. create : 'POST',
  57. read : 'GET',
  58. update : 'PUT',
  59. destroy : 'DELETE'
  60. },
  61. * </code></pre>
  62. */
  63. restActions : {
  64. create : 'POST',
  65. read : 'GET',
  66. update : 'PUT',
  67. destroy : 'DELETE'
  68. },
  69. <div id="method-Ext.data.Api-isAction"></div>/**
  70. * Returns true if supplied action-name is a valid API action defined in <code>{@link #actions}</code> constants
  71. * @param {String} action Action to test for availability.
  72. * @return {Boolean}
  73. */
  74. isAction : function(action) {
  75. return (Ext.data.Api.actions[action]) ? true : false;
  76. },
  77. <div id="method-Ext.data.Api-getVerb"></div>/**
  78. * Returns the actual CRUD action KEY "create", "read", "update" or "destroy" from the supplied action-name. This method is used internally and shouldn't generally
  79. * need to be used directly. The key/value pair of Ext.data.Api.actions will often be identical but this is not necessarily true. A developer can override this naming
  80. * convention if desired. However, the framework internally calls methods based upon the KEY so a way of retreiving the the words "create", "read", "update" and "destroy" is
  81. * required. This method will cache discovered KEYS into the private validActions hash.
  82. * @param {String} name The runtime name of the action.
  83. * @return {String||null} returns the action-key, or verb of the user-action or null if invalid.
  84. * @nodoc
  85. */
  86. getVerb : function(name) {
  87. if (validActions[name]) {
  88. return validActions[name]; // <-- found in cache. return immediately.
  89. }
  90. for (var verb in this.actions) {
  91. if (this.actions[verb] === name) {
  92. validActions[name] = verb;
  93. break;
  94. }
  95. }
  96. return (validActions[name] !== undefined) ? validActions[name] : null;
  97. },
  98. <div id="method-Ext.data.Api-isValid"></div>/**
  99. * Returns true if the supplied API is valid; that is, check that all keys match defined actions
  100. * otherwise returns an array of mistakes.
  101. * @return {String[]|true}
  102. */
  103. isValid : function(api){
  104. var invalid = [];
  105. var crud = this.actions; // <-- cache a copy of the actions.
  106. for (var action in api) {
  107. if (!(action in crud)) {
  108. invalid.push(action);
  109. }
  110. }
  111. return (!invalid.length) ? true : invalid;
  112. },
  113. <div id="method-Ext.data.Api-hasUniqueUrl"></div>/**
  114. * Returns true if the supplied verb upon the supplied proxy points to a unique url in that none of the other api-actions
  115. * point to the same url. The question is important for deciding whether to insert the "xaction" HTTP parameter within an
  116. * Ajax request. This method is used internally and shouldn't generally need to be called directly.
  117. * @param {Ext.data.DataProxy} proxy
  118. * @param {String} verb
  119. * @return {Boolean}
  120. */
  121. hasUniqueUrl : function(proxy, verb) {
  122. var url = (proxy.api[verb]) ? proxy.api[verb].url : null;
  123. var unique = true;
  124. for (var action in proxy.api) {
  125. if ((unique = (action === verb) ? true : (proxy.api[action].url != url) ? true : false) === false) {
  126. break;
  127. }
  128. }
  129. return unique;
  130. },
  131. <div id="method-Ext.data.Api-prepare"></div>/**
  132. * This method is used internally by <tt>{@link Ext.data.DataProxy DataProxy}</tt> and should not generally need to be used directly.
  133. * Each action of a DataProxy api can be initially defined as either a String or an Object. When specified as an object,
  134. * one can explicitly define the HTTP method (GET|POST) to use for each CRUD action. This method will prepare the supplied API, setting
  135. * each action to the Object form. If your API-actions do not explicitly define the HTTP method, the "method" configuration-parameter will
  136. * be used. If the method configuration parameter is not specified, POST will be used.
  137. <pre><code>
  138. new Ext.data.HttpProxy({
  139. method: "POST", // <-- default HTTP method when not specified.
  140. api: {
  141. create: 'create.php',
  142. load: 'read.php',
  143. save: 'save.php',
  144. destroy: 'destroy.php'
  145. }
  146. });
  147. // Alternatively, one can use the object-form to specify the API
  148. new Ext.data.HttpProxy({
  149. api: {
  150. load: {url: 'read.php', method: 'GET'},
  151. create: 'create.php',
  152. destroy: 'destroy.php',
  153. save: 'update.php'
  154. }
  155. });
  156. </code></pre>
  157. *
  158. * @param {Ext.data.DataProxy} proxy
  159. */
  160. prepare : function(proxy) {
  161. if (!proxy.api) {
  162. proxy.api = {}; // <-- No api? create a blank one.
  163. }
  164. for (var verb in this.actions) {
  165. var action = this.actions[verb];
  166. proxy.api[action] = proxy.api[action] || proxy.url || proxy.directFn;
  167. if (typeof(proxy.api[action]) == 'string') {
  168. proxy.api[action] = {
  169. url: proxy.api[action],
  170. method: (proxy.restful === true) ? Ext.data.Api.restActions[action] : undefined
  171. };
  172. }
  173. }
  174. },
  175. <div id="method-Ext.data.Api-restify"></div>/**
  176. * Prepares a supplied Proxy to be RESTful. Sets the HTTP method for each api-action to be one of
  177. * GET, POST, PUT, DELETE according to the defined {@link #restActions}.
  178. * @param {Ext.data.DataProxy} proxy
  179. */
  180. restify : function(proxy) {
  181. proxy.restful = true;
  182. for (var verb in this.restActions) {
  183. proxy.api[this.actions[verb]].method ||
  184. (proxy.api[this.actions[verb]].method = this.restActions[verb]);
  185. }
  186. // TODO: perhaps move this interceptor elsewhere? like into DataProxy, perhaps? Placed here
  187. // to satisfy initial 3.0 final release of REST features.
  188. proxy.onWrite = proxy.onWrite.createInterceptor(function(action, o, response, rs) {
  189. var reader = o.reader;
  190. var res = new Ext.data.Response({
  191. action: action,
  192. raw: response
  193. });
  194. switch (response.status) {
  195. case 200: // standard 200 response, send control back to HttpProxy#onWrite by returning true from this intercepted #onWrite
  196. return true;
  197. break;
  198. case 201: // entity created but no response returned
  199. if (Ext.isEmpty(res.raw.responseText)) {
  200. res.success = true;
  201. } else {
  202. //if the response contains data, treat it like a 200
  203. return true;
  204. }
  205. break;
  206. case 204: // no-content. Create a fake response.
  207. res.success = true;
  208. res.data = null;
  209. break;
  210. default:
  211. return true;
  212. break;
  213. }
  214. if (res.success === true) {
  215. this.fireEvent("write", this, action, res.data, res, rs, o.request.arg);
  216. } else {
  217. this.fireEvent('exception', this, 'remote', action, o, res, rs);
  218. }
  219. o.request.callback.call(o.request.scope, res.data, res, res.success);
  220. return false; // <-- false to prevent intercepted function from running.
  221. }, proxy);
  222. }
  223. };
  224. })();
  225. <div id="method-Ext.data.Api-Response"></div>/**
  226. * Ext.data.Response
  227. * Experimental. Do not use directly.
  228. */
  229. Ext.data.Response = function(params, response) {
  230. Ext.apply(this, params, {
  231. raw: response
  232. });
  233. };
  234. Ext.data.Response.prototype = {
  235. message : null,
  236. success : false,
  237. status : null,
  238. root : null,
  239. raw : null,
  240. getMessage : function() {
  241. return this.message;
  242. },
  243. getSuccess : function() {
  244. return this.success;
  245. },
  246. getStatus : function() {
  247. return this.status;
  248. },
  249. getRoot : function() {
  250. return this.root;
  251. },
  252. getRawResponse : function() {
  253. return this.raw;
  254. }
  255. };
  256. <div id="cls-Ext.data.Api.Error"></div>/**
  257. * @class Ext.data.Api.Error
  258. * @extends Ext.Error
  259. * Error class for Ext.data.Api errors
  260. */
  261. Ext.data.Api.Error = Ext.extend(Ext.Error, {
  262. constructor : function(message, arg) {
  263. this.arg = arg;
  264. Ext.Error.call(this, message);
  265. },
  266. name: 'Ext.data.Api'
  267. });
  268. Ext.apply(Ext.data.Api.Error.prototype, {
  269. lang: {
  270. 'action-url-undefined': 'No fallback url defined for this action. When defining a DataProxy api, please be sure to define an url for each CRUD action in Ext.data.Api.actions or define a default url in addition to your api-configuration.',
  271. 'invalid': 'received an invalid API-configuration. Please ensure your proxy API-configuration contains only the actions defined in Ext.data.Api.actions',
  272. 'invalid-url': 'Invalid url. Please review your proxy configuration.',
  273. 'execute': 'Attempted to execute an unknown action. Valid API actions are defined in Ext.data.Api.actions"'
  274. }
  275. });
  276. </pre>
  277. </body>
  278. </html>