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.

1987 lines
83 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.Store"></div>/**
  16. * @class Ext.data.Store
  17. * @extends Ext.util.Observable
  18. * <p>The Store class encapsulates a client side cache of {@link Ext.data.Record Record}
  19. * objects which provide input data for Components such as the {@link Ext.grid.GridPanel GridPanel},
  20. * the {@link Ext.form.ComboBox ComboBox}, or the {@link Ext.DataView DataView}.</p>
  21. * <p><u>Retrieving Data</u></p>
  22. * <p>A Store object may access a data object using:<div class="mdetail-params"><ul>
  23. * <li>{@link #proxy configured implementation} of {@link Ext.data.DataProxy DataProxy}</li>
  24. * <li>{@link #data} to automatically pass in data</li>
  25. * <li>{@link #loadData} to manually pass in data</li>
  26. * </ul></div></p>
  27. * <p><u>Reading Data</u></p>
  28. * <p>A Store object has no inherent knowledge of the format of the data object (it could be
  29. * an Array, XML, or JSON). A Store object uses an appropriate {@link #reader configured implementation}
  30. * of a {@link Ext.data.DataReader DataReader} to create {@link Ext.data.Record Record} instances from the data
  31. * object.</p>
  32. * <p><u>Store Types</u></p>
  33. * <p>There are several implementations of Store available which are customized for use with
  34. * a specific DataReader implementation. Here is an example using an ArrayStore which implicitly
  35. * creates a reader commensurate to an Array data object.</p>
  36. * <pre><code>
  37. var myStore = new Ext.data.ArrayStore({
  38. fields: ['fullname', 'first'],
  39. idIndex: 0 // id for each record will be the first element
  40. });
  41. * </code></pre>
  42. * <p>For custom implementations create a basic {@link Ext.data.Store} configured as needed:</p>
  43. * <pre><code>
  44. // create a {@link Ext.data.Record Record} constructor:
  45. var rt = Ext.data.Record.create([
  46. {name: 'fullname'},
  47. {name: 'first'}
  48. ]);
  49. var myStore = new Ext.data.Store({
  50. // explicitly create reader
  51. reader: new Ext.data.ArrayReader(
  52. {
  53. idIndex: 0 // id for each record will be the first element
  54. },
  55. rt // recordType
  56. )
  57. });
  58. * </code></pre>
  59. * <p>Load some data into store (note the data object is an array which corresponds to the reader):</p>
  60. * <pre><code>
  61. var myData = [
  62. [1, 'Fred Flintstone', 'Fred'], // note that id for the record is the first element
  63. [2, 'Barney Rubble', 'Barney']
  64. ];
  65. myStore.loadData(myData);
  66. * </code></pre>
  67. * <p>Records are cached and made available through accessor functions. An example of adding
  68. * a record to the store:</p>
  69. * <pre><code>
  70. var defaultData = {
  71. fullname: 'Full Name',
  72. first: 'First Name'
  73. };
  74. var recId = 100; // provide unique id for the record
  75. var r = new myStore.recordType(defaultData, ++recId); // create new record
  76. myStore.{@link #insert}(0, r); // insert a new record into the store (also see {@link #add})
  77. * </code></pre>
  78. * <p><u>Writing Data</u></p>
  79. * <p>And <b>new in Ext version 3</b>, use the new {@link Ext.data.DataWriter DataWriter} to create an automated, <a href="http://extjs.com/deploy/dev/examples/writer/writer.html">Writable Store</a>
  80. * along with <a href="http://extjs.com/deploy/dev/examples/restful/restful.html">RESTful features.</a>
  81. * @constructor
  82. * Creates a new Store.
  83. * @param {Object} config A config object containing the objects needed for the Store to access data,
  84. * and read the data into Records.
  85. * @xtype store
  86. */
  87. Ext.data.Store = Ext.extend(Ext.util.Observable, {
  88. <div id="cfg-Ext.data.Store-storeId"></div>/**
  89. * @cfg {String} storeId If passed, the id to use to register with the <b>{@link Ext.StoreMgr StoreMgr}</b>.
  90. * <p><b>Note</b>: if a (deprecated) <tt>{@link #id}</tt> is specified it will supersede the <tt>storeId</tt>
  91. * assignment.</p>
  92. */
  93. <div id="cfg-Ext.data.Store-url"></div>/**
  94. * @cfg {String} url If a <tt>{@link #proxy}</tt> is not specified the <tt>url</tt> will be used to
  95. * implicitly configure a {@link Ext.data.HttpProxy HttpProxy} if an <tt>url</tt> is specified.
  96. * Typically this option, or the <code>{@link #data}</code> option will be specified.
  97. */
  98. <div id="cfg-Ext.data.Store-autoLoad"></div>/**
  99. * @cfg {Boolean/Object} autoLoad If <tt>{@link #data}</tt> is not specified, and if <tt>autoLoad</tt>
  100. * is <tt>true</tt> or an <tt>Object</tt>, this store's {@link #load} method is automatically called
  101. * after creation. If the value of <tt>autoLoad</tt> is an <tt>Object</tt>, this <tt>Object</tt> will
  102. * be passed to the store's {@link #load} method.
  103. */
  104. <div id="cfg-Ext.data.Store-proxy"></div>/**
  105. * @cfg {Ext.data.DataProxy} proxy The {@link Ext.data.DataProxy DataProxy} object which provides
  106. * access to a data object. See <code>{@link #url}</code>.
  107. */
  108. <div id="cfg-Ext.data.Store-data"></div>/**
  109. * @cfg {Array} data An inline data object readable by the <code>{@link #reader}</code>.
  110. * Typically this option, or the <code>{@link #url}</code> option will be specified.
  111. */
  112. <div id="cfg-Ext.data.Store-reader"></div>/**
  113. * @cfg {Ext.data.DataReader} reader The {@link Ext.data.DataReader Reader} object which processes the
  114. * data object and returns an Array of {@link Ext.data.Record} objects which are cached keyed by their
  115. * <b><tt>{@link Ext.data.Record#id id}</tt></b> property.
  116. */
  117. <div id="cfg-Ext.data.Store-writer"></div>/**
  118. * @cfg {Ext.data.DataWriter} writer
  119. * <p>The {@link Ext.data.DataWriter Writer} object which processes a record object for being written
  120. * to the server-side database.</p>
  121. * <br><p>When a writer is installed into a Store the {@link #add}, {@link #remove}, and {@link #update}
  122. * events on the store are monitored in order to remotely {@link #createRecords create records},
  123. * {@link #destroyRecord destroy records}, or {@link #updateRecord update records}.</p>
  124. * <br><p>The proxy for this store will relay any {@link #writexception} events to this store.</p>
  125. * <br><p>Sample implementation:
  126. * <pre><code>
  127. var writer = new {@link Ext.data.JsonWriter}({
  128. encode: true,
  129. writeAllFields: true // write all fields, not just those that changed
  130. });
  131. // Typical Store collecting the Proxy, Reader and Writer together.
  132. var store = new Ext.data.Store({
  133. storeId: 'user',
  134. root: 'records',
  135. proxy: proxy,
  136. reader: reader,
  137. writer: writer, // <-- plug a DataWriter into the store just as you would a Reader
  138. paramsAsHash: true,
  139. autoSave: false // <-- false to delay executing create, update, destroy requests
  140. // until specifically told to do so.
  141. });
  142. * </code></pre></p>
  143. */
  144. writer : undefined,
  145. <div id="cfg-Ext.data.Store-baseParams"></div>/**
  146. * @cfg {Object} baseParams
  147. * <p>An object containing properties which are to be sent as parameters
  148. * for <i>every</i> HTTP request.</p>
  149. * <p>Parameters are encoded as standard HTTP parameters using {@link Ext#urlEncode}.</p>
  150. * <p><b>Note</b>: <code>baseParams</code> may be superseded by any <code>params</code>
  151. * specified in a <code>{@link #load}</code> request, see <code>{@link #load}</code>
  152. * for more details.</p>
  153. * This property may be modified after creation using the <code>{@link #setBaseParam}</code>
  154. * method.
  155. * @property
  156. */
  157. <div id="cfg-Ext.data.Store-sortInfo"></div>/**
  158. * @cfg {Object} sortInfo A config object to specify the sort order in the request of a Store's
  159. * {@link #load} operation. Note that for local sorting, the <tt>direction</tt> property is
  160. * case-sensitive. See also {@link #remoteSort} and {@link #paramNames}.
  161. * For example:<pre><code>
  162. sortInfo: {
  163. field: 'fieldName',
  164. direction: 'ASC' // or 'DESC' (case sensitive for local sorting)
  165. }
  166. </code></pre>
  167. */
  168. <div id="cfg-Ext.data.Store-remoteSort"></div>/**
  169. * @cfg {boolean} remoteSort <tt>true</tt> if sorting is to be handled by requesting the <tt>{@link #proxy Proxy}</tt>
  170. * to provide a refreshed version of the data object in sorted order, as opposed to sorting the Record cache
  171. * in place (defaults to <tt>false</tt>).
  172. * <p>If <tt>remoteSort</tt> is <tt>true</tt>, then clicking on a {@link Ext.grid.Column Grid Column}'s
  173. * {@link Ext.grid.Column#header header} causes the current page to be requested from the server appending
  174. * the following two parameters to the <b><tt>{@link #load params}</tt></b>:<div class="mdetail-params"><ul>
  175. * <li><b><tt>sort</tt></b> : String<p class="sub-desc">The <tt>name</tt> (as specified in the Record's
  176. * {@link Ext.data.Field Field definition}) of the field to sort on.</p></li>
  177. * <li><b><tt>dir</tt></b> : String<p class="sub-desc">The direction of the sort, 'ASC' or 'DESC' (case-sensitive).</p></li>
  178. * </ul></div></p>
  179. */
  180. remoteSort : false,
  181. <div id="cfg-Ext.data.Store-autoDestroy"></div>/**
  182. * @cfg {Boolean} autoDestroy <tt>true</tt> to destroy the store when the component the store is bound
  183. * to is destroyed (defaults to <tt>false</tt>).
  184. * <p><b>Note</b>: this should be set to true when using stores that are bound to only 1 component.</p>
  185. */
  186. autoDestroy : false,
  187. <div id="cfg-Ext.data.Store-pruneModifiedRecords"></div>/**
  188. * @cfg {Boolean} pruneModifiedRecords <tt>true</tt> to clear all modified record information each time
  189. * the store is loaded or when a record is removed (defaults to <tt>false</tt>). See {@link #getModifiedRecords}
  190. * for the accessor method to retrieve the modified records.
  191. */
  192. pruneModifiedRecords : false,
  193. <div id="prop-Ext.data.Store-lastOptions"></div>/**
  194. * Contains the last options object used as the parameter to the {@link #load} method. See {@link #load}
  195. * for the details of what this may contain. This may be useful for accessing any params which were used
  196. * to load the current Record cache.
  197. * @property
  198. */
  199. lastOptions : null,
  200. <div id="cfg-Ext.data.Store-autoSave"></div>/**
  201. * @cfg {Boolean} autoSave
  202. * <p>Defaults to <tt>true</tt> causing the store to automatically {@link #save} records to
  203. * the server when a record is modified (ie: becomes 'dirty'). Specify <tt>false</tt> to manually call {@link #save}
  204. * to send all modifiedRecords to the server.</p>
  205. * <br><p><b>Note</b>: each CRUD action will be sent as a separate request.</p>
  206. */
  207. autoSave : true,
  208. <div id="cfg-Ext.data.Store-batch"></div>/**
  209. * @cfg {Boolean} batch
  210. * <p>Defaults to <tt>true</tt> (unless <code>{@link #restful}:true</code>). Multiple
  211. * requests for each CRUD action (CREATE, READ, UPDATE and DESTROY) will be combined
  212. * and sent as one transaction. Only applies when <code>{@link #autoSave}</code> is set
  213. * to <tt>false</tt>.</p>
  214. * <br><p>If Store is RESTful, the DataProxy is also RESTful, and a unique transaction is
  215. * generated for each record.</p>
  216. */
  217. batch : true,
  218. <div id="cfg-Ext.data.Store-restful"></div>/**
  219. * @cfg {Boolean} restful
  220. * Defaults to <tt>false</tt>. Set to <tt>true</tt> to have the Store and the set
  221. * Proxy operate in a RESTful manner. The store will automatically generate GET, POST,
  222. * PUT and DELETE requests to the server. The HTTP method used for any given CRUD
  223. * action is described in {@link Ext.data.Api#restActions}. For additional information
  224. * see {@link Ext.data.DataProxy#restful}.
  225. * <p><b>Note</b>: if <code>{@link #restful}:true</code> <code>batch</code> will
  226. * internally be set to <tt>false</tt>.</p>
  227. */
  228. restful: false,
  229. <div id="cfg-Ext.data.Store-paramNames"></div>/**
  230. * @cfg {Object} paramNames
  231. * <p>An object containing properties which specify the names of the paging and
  232. * sorting parameters passed to remote servers when loading blocks of data. By default, this
  233. * object takes the following form:</p><pre><code>
  234. {
  235. start : 'start', // The parameter name which specifies the start row
  236. limit : 'limit', // The parameter name which specifies number of rows to return
  237. sort : 'sort', // The parameter name which specifies the column to sort on
  238. dir : 'dir' // The parameter name which specifies the sort direction
  239. }
  240. </code></pre>
  241. * <p>The server must produce the requested data block upon receipt of these parameter names.
  242. * If different parameter names are required, this property can be overriden using a configuration
  243. * property.</p>
  244. * <p>A {@link Ext.PagingToolbar PagingToolbar} bound to this Store uses this property to determine
  245. * the parameter names to use in its {@link #load requests}.
  246. */
  247. paramNames : undefined,
  248. <div id="cfg-Ext.data.Store-defaultParamNames"></div>/**
  249. * @cfg {Object} defaultParamNames
  250. * Provides the default values for the {@link #paramNames} property. To globally modify the parameters
  251. * for all stores, this object should be changed on the store prototype.
  252. */
  253. defaultParamNames : {
  254. start : 'start',
  255. limit : 'limit',
  256. sort : 'sort',
  257. dir : 'dir'
  258. },
  259. isDestroyed: false,
  260. hasMultiSort: false,
  261. // private
  262. batchKey : '_ext_batch_',
  263. constructor : function(config){
  264. <div id="prop-Ext.data.Store-multiSort"></div>/**
  265. * @property multiSort
  266. * @type Boolean
  267. * True if this store is currently sorted by more than one field/direction combination.
  268. */
  269. <div id="prop-Ext.data.Store-isDestroyed"></div>/**
  270. * @property isDestroyed
  271. * @type Boolean
  272. * True if the store has been destroyed already. Read only
  273. */
  274. this.data = new Ext.util.MixedCollection(false);
  275. this.data.getKey = function(o){
  276. return o.id;
  277. };
  278. // temporary removed-records cache
  279. this.removed = [];
  280. if(config && config.data){
  281. this.inlineData = config.data;
  282. delete config.data;
  283. }
  284. Ext.apply(this, config);
  285. <div id="prop-Ext.data.Store-baseParams"></div>/**
  286. * See the <code>{@link #baseParams corresponding configuration option}</code>
  287. * for a description of this property.
  288. * To modify this property see <code>{@link #setBaseParam}</code>.
  289. * @property
  290. */
  291. this.baseParams = Ext.isObject(this.baseParams) ? this.baseParams : {};
  292. this.paramNames = Ext.applyIf(this.paramNames || {}, this.defaultParamNames);
  293. if((this.url || this.api) && !this.proxy){
  294. this.proxy = new Ext.data.HttpProxy({url: this.url, api: this.api});
  295. }
  296. // If Store is RESTful, so too is the DataProxy
  297. if (this.restful === true && this.proxy) {
  298. // When operating RESTfully, a unique transaction is generated for each record.
  299. // TODO might want to allow implemention of faux REST where batch is possible using RESTful routes only.
  300. this.batch = false;
  301. Ext.data.Api.restify(this.proxy);
  302. }
  303. if(this.reader){ // reader passed
  304. if(!this.recordType){
  305. this.recordType = this.reader.recordType;
  306. }
  307. if(this.reader.onMetaChange){
  308. this.reader.onMetaChange = this.reader.onMetaChange.createSequence(this.onMetaChange, this);
  309. }
  310. if (this.writer) { // writer passed
  311. if (this.writer instanceof(Ext.data.DataWriter) === false) { // <-- config-object instead of instance.
  312. this.writer = this.buildWriter(this.writer);
  313. }
  314. this.writer.meta = this.reader.meta;
  315. this.pruneModifiedRecords = true;
  316. }
  317. }
  318. <div id="prop-Ext.data.Store-recordType"></div>/**
  319. * The {@link Ext.data.Record Record} constructor as supplied to (or created by) the
  320. * {@link Ext.data.DataReader Reader}. Read-only.
  321. * <p>If the Reader was constructed by passing in an Array of {@link Ext.data.Field} definition objects,
  322. * instead of a Record constructor, it will implicitly create a Record constructor from that Array (see
  323. * {@link Ext.data.Record}.{@link Ext.data.Record#create create} for additional details).</p>
  324. * <p>This property may be used to create new Records of the type held in this Store, for example:</p><pre><code>
  325. // create the data store
  326. var store = new Ext.data.ArrayStore({
  327. autoDestroy: true,
  328. fields: [
  329. {name: 'company'},
  330. {name: 'price', type: 'float'},
  331. {name: 'change', type: 'float'},
  332. {name: 'pctChange', type: 'float'},
  333. {name: 'lastChange', type: 'date', dateFormat: 'n/j h:ia'}
  334. ]
  335. });
  336. store.loadData(myData);
  337. // create the Grid
  338. var grid = new Ext.grid.EditorGridPanel({
  339. store: store,
  340. colModel: new Ext.grid.ColumnModel({
  341. columns: [
  342. {id:'company', header: 'Company', width: 160, dataIndex: 'company'},
  343. {header: 'Price', renderer: 'usMoney', dataIndex: 'price'},
  344. {header: 'Change', renderer: change, dataIndex: 'change'},
  345. {header: '% Change', renderer: pctChange, dataIndex: 'pctChange'},
  346. {header: 'Last Updated', width: 85,
  347. renderer: Ext.util.Format.dateRenderer('m/d/Y'),
  348. dataIndex: 'lastChange'}
  349. ],
  350. defaults: {
  351. sortable: true,
  352. width: 75
  353. }
  354. }),
  355. autoExpandColumn: 'company', // match the id specified in the column model
  356. height:350,
  357. width:600,
  358. title:'Array Grid',
  359. tbar: [{
  360. text: 'Add Record',
  361. handler : function(){
  362. var defaultData = {
  363. change: 0,
  364. company: 'New Company',
  365. lastChange: (new Date()).clearTime(),
  366. pctChange: 0,
  367. price: 10
  368. };
  369. var recId = 3; // provide unique id
  370. var p = new store.recordType(defaultData, recId); // create new record
  371. grid.stopEditing();
  372. store.{@link #insert}(0, p); // insert a new record into the store (also see {@link #add})
  373. grid.startEditing(0, 0);
  374. }
  375. }]
  376. });
  377. * </code></pre>
  378. * @property recordType
  379. * @type Function
  380. */
  381. if(this.recordType){
  382. <div id="prop-Ext.data.Store-fields"></div>/**
  383. * A {@link Ext.util.MixedCollection MixedCollection} containing the defined {@link Ext.data.Field Field}s
  384. * for the {@link Ext.data.Record Records} stored in this Store. Read-only.
  385. * @property fields
  386. * @type Ext.util.MixedCollection
  387. */
  388. this.fields = this.recordType.prototype.fields;
  389. }
  390. this.modified = [];
  391. this.addEvents(
  392. <div id="event-Ext.data.Store-datachanged"></div>/**
  393. * @event datachanged
  394. * Fires when the data cache has changed in a bulk manner (e.g., it has been sorted, filtered, etc.) and a
  395. * widget that is using this Store as a Record cache should refresh its view.
  396. * @param {Store} this
  397. */
  398. 'datachanged',
  399. <div id="event-Ext.data.Store-metachange"></div>/**
  400. * @event metachange
  401. * Fires when this store's reader provides new metadata (fields). This is currently only supported for JsonReaders.
  402. * @param {Store} this
  403. * @param {Object} meta The JSON metadata
  404. */
  405. 'metachange',
  406. <div id="event-Ext.data.Store-add"></div>/**
  407. * @event add
  408. * Fires when Records have been {@link #add}ed to the Store
  409. * @param {Store} this
  410. * @param {Ext.data.Record[]} records The array of Records added
  411. * @param {Number} index The index at which the record(s) were added
  412. */
  413. 'add',
  414. <div id="event-Ext.data.Store-remove"></div>/**
  415. * @event remove
  416. * Fires when a Record has been {@link #remove}d from the Store
  417. * @param {Store} this
  418. * @param {Ext.data.Record} record The Record that was removed
  419. * @param {Number} index The index at which the record was removed
  420. */
  421. 'remove',
  422. <div id="event-Ext.data.Store-update"></div>/**
  423. * @event update
  424. * Fires when a Record has been updated
  425. * @param {Store} this
  426. * @param {Ext.data.Record} record The Record that was updated
  427. * @param {String} operation The update operation being performed. Value may be one of:
  428. * <pre><code>
  429. Ext.data.Record.EDIT
  430. Ext.data.Record.REJECT
  431. Ext.data.Record.COMMIT
  432. * </code></pre>
  433. */
  434. 'update',
  435. <div id="event-Ext.data.Store-clear"></div>/**
  436. * @event clear
  437. * Fires when the data cache has been cleared.
  438. * @param {Store} this
  439. * @param {Record[]} records The records that were cleared.
  440. */
  441. 'clear',
  442. <div id="event-Ext.data.Store-exception"></div>/**
  443. * @event exception
  444. * <p>Fires if an exception occurs in the Proxy during a remote request.
  445. * This event is relayed through the corresponding {@link Ext.data.DataProxy}.
  446. * See {@link Ext.data.DataProxy}.{@link Ext.data.DataProxy#exception exception}
  447. * for additional details.
  448. * @param {misc} misc See {@link Ext.data.DataProxy}.{@link Ext.data.DataProxy#exception exception}
  449. * for description.
  450. */
  451. 'exception',
  452. <div id="event-Ext.data.Store-beforeload"></div>/**
  453. * @event beforeload
  454. * Fires before a request is made for a new data object. If the beforeload handler returns
  455. * <tt>false</tt> the {@link #load} action will be canceled.
  456. * @param {Store} this
  457. * @param {Object} options The loading options that were specified (see {@link #load} for details)
  458. */
  459. 'beforeload',
  460. <div id="event-Ext.data.Store-load"></div>/**
  461. * @event load
  462. * Fires after a new set of Records has been loaded.
  463. * @param {Store} this
  464. * @param {Ext.data.Record[]} records The Records that were loaded
  465. * @param {Object} options The loading options that were specified (see {@link #load} for details)
  466. */
  467. 'load',
  468. <div id="event-Ext.data.Store-loadexception"></div>/**
  469. * @event loadexception
  470. * <p>This event is <b>deprecated</b> in favor of the catch-all <b><code>{@link #exception}</code></b>
  471. * event instead.</p>
  472. * <p>This event is relayed through the corresponding {@link Ext.data.DataProxy}.
  473. * See {@link Ext.data.DataProxy}.{@link Ext.data.DataProxy#loadexception loadexception}
  474. * for additional details.
  475. * @param {misc} misc See {@link Ext.data.DataProxy}.{@link Ext.data.DataProxy#loadexception loadexception}
  476. * for description.
  477. */
  478. 'loadexception',
  479. <div id="event-Ext.data.Store-beforewrite"></div>/**
  480. * @event beforewrite
  481. * @param {Ext.data.Store} store
  482. * @param {String} action [Ext.data.Api.actions.create|update|destroy]
  483. * @param {Record/Record[]} rs The Record(s) being written.
  484. * @param {Object} options The loading options that were specified. Edit <code>options.params</code> to add Http parameters to the request. (see {@link #save} for details)
  485. * @param {Object} arg The callback's arg object passed to the {@link #request} function
  486. */
  487. 'beforewrite',
  488. <div id="event-Ext.data.Store-write"></div>/**
  489. * @event write
  490. * Fires if the server returns 200 after an Ext.data.Api.actions CRUD action.
  491. * Success of the action is determined in the <code>result['successProperty']</code>property (<b>NOTE</b> for RESTful stores,
  492. * a simple 20x response is sufficient for the actions "destroy" and "update". The "create" action should should return 200 along with a database pk).
  493. * @param {Ext.data.Store} store
  494. * @param {String} action [Ext.data.Api.actions.create|update|destroy]
  495. * @param {Object} result The 'data' picked-out out of the response for convenience.
  496. * @param {Ext.Direct.Transaction} res
  497. * @param {Record/Record[]} rs Store's records, the subject(s) of the write-action
  498. */
  499. 'write',
  500. <div id="event-Ext.data.Store-beforesave"></div>/**
  501. * @event beforesave
  502. * Fires before a save action is called. A save encompasses destroying records, updating records and creating records.
  503. * @param {Ext.data.Store} store
  504. * @param {Object} data An object containing the data that is to be saved. The object will contain a key for each appropriate action,
  505. * with an array of records for each action.
  506. */
  507. 'beforesave',
  508. <div id="event-Ext.data.Store-save"></div>/**
  509. * @event save
  510. * Fires after a save is completed. A save encompasses destroying records, updating records and creating records.
  511. * @param {Ext.data.Store} store
  512. * @param {Number} batch The identifier for the batch that was saved.
  513. * @param {Object} data An object containing the data that is to be saved. The object will contain a key for each appropriate action,
  514. * with an array of records for each action.
  515. */
  516. 'save'
  517. );
  518. if(this.proxy){
  519. // TODO remove deprecated loadexception with ext-3.0.1
  520. this.relayEvents(this.proxy, ['loadexception', 'exception']);
  521. }
  522. // With a writer set for the Store, we want to listen to add/remove events to remotely create/destroy records.
  523. if (this.writer) {
  524. this.on({
  525. scope: this,
  526. add: this.createRecords,
  527. remove: this.destroyRecord,
  528. update: this.updateRecord,
  529. clear: this.onClear
  530. });
  531. }
  532. this.sortToggle = {};
  533. if(this.sortField){
  534. this.setDefaultSort(this.sortField, this.sortDir);
  535. }else if(this.sortInfo){
  536. this.setDefaultSort(this.sortInfo.field, this.sortInfo.direction);
  537. }
  538. Ext.data.Store.superclass.constructor.call(this);
  539. if(this.id){
  540. this.storeId = this.id;
  541. delete this.id;
  542. }
  543. if(this.storeId){
  544. Ext.StoreMgr.register(this);
  545. }
  546. if(this.inlineData){
  547. this.loadData(this.inlineData);
  548. delete this.inlineData;
  549. }else if(this.autoLoad){
  550. this.load.defer(10, this, [
  551. typeof this.autoLoad == 'object' ?
  552. this.autoLoad : undefined]);
  553. }
  554. // used internally to uniquely identify a batch
  555. this.batchCounter = 0;
  556. this.batches = {};
  557. },
  558. /**
  559. * builds a DataWriter instance when Store constructor is provided with a writer config-object instead of an instace.
  560. * @param {Object} config Writer configuration
  561. * @return {Ext.data.DataWriter}
  562. * @private
  563. */
  564. buildWriter : function(config) {
  565. var klass = undefined,
  566. type = (config.format || 'json').toLowerCase();
  567. switch (type) {
  568. case 'json':
  569. klass = Ext.data.JsonWriter;
  570. break;
  571. case 'xml':
  572. klass = Ext.data.XmlWriter;
  573. break;
  574. default:
  575. klass = Ext.data.JsonWriter;
  576. }
  577. return new klass(config);
  578. },
  579. <div id="method-Ext.data.Store-destroy"></div>/**
  580. * Destroys the store.
  581. */
  582. destroy : function(){
  583. if(!this.isDestroyed){
  584. if(this.storeId){
  585. Ext.StoreMgr.unregister(this);
  586. }
  587. this.clearData();
  588. this.data = null;
  589. Ext.destroy(this.proxy);
  590. this.reader = this.writer = null;
  591. this.purgeListeners();
  592. this.isDestroyed = true;
  593. }
  594. },
  595. <div id="method-Ext.data.Store-add"></div>/**
  596. * Add Records to the Store and fires the {@link #add} event. To add Records
  597. * to the store from a remote source use <code>{@link #load}({add:true})</code>.
  598. * See also <code>{@link #recordType}</code> and <code>{@link #insert}</code>.
  599. * @param {Ext.data.Record[]} records An Array of Ext.data.Record objects
  600. * to add to the cache. See {@link #recordType}.
  601. */
  602. add : function(records) {
  603. var i, len, record, index;
  604. records = [].concat(records);
  605. if (records.length < 1) {
  606. return;
  607. }
  608. for (i = 0, len = records.length; i < len; i++) {
  609. record = records[i];
  610. record.join(this);
  611. if (record.dirty || record.phantom) {
  612. this.modified.push(record);
  613. }
  614. }
  615. index = this.data.length;
  616. this.data.addAll(records);
  617. if (this.snapshot) {
  618. this.snapshot.addAll(records);
  619. }
  620. this.fireEvent('add', this, records, index);
  621. },
  622. <div id="method-Ext.data.Store-addSorted"></div>/**
  623. * (Local sort only) Inserts the passed Record into the Store at the index where it
  624. * should go based on the current sort information.
  625. * @param {Ext.data.Record} record
  626. */
  627. addSorted : function(record){
  628. var index = this.findInsertIndex(record);
  629. this.insert(index, record);
  630. },
  631. /**
  632. * @private
  633. * Update a record within the store with a new reference
  634. */
  635. doUpdate : function(rec){
  636. this.data.replace(rec.id, rec);
  637. if(this.snapshot){
  638. this.snapshot.replace(rec.id, rec);
  639. }
  640. this.fireEvent('update', this, rec, Ext.data.Record.COMMIT);
  641. },
  642. <div id="method-Ext.data.Store-remove"></div>/**
  643. * Remove Records from the Store and fires the {@link #remove} event.
  644. * @param {Ext.data.Record/Ext.data.Record[]} record The record object or array of records to remove from the cache.
  645. */
  646. remove : function(record){
  647. if(Ext.isArray(record)){
  648. Ext.each(record, function(r){
  649. this.remove(r);
  650. }, this);
  651. return;
  652. }
  653. var index = this.data.indexOf(record);
  654. if(index > -1){
  655. record.join(null);
  656. this.data.removeAt(index);
  657. }
  658. if(this.pruneModifiedRecords){
  659. this.modified.remove(record);
  660. }
  661. if(this.snapshot){
  662. this.snapshot.remove(record);
  663. }
  664. if(index > -1){
  665. this.fireEvent('remove', this, record, index);
  666. }
  667. },
  668. <div id="method-Ext.data.Store-removeAt"></div>/**
  669. * Remove a Record from the Store at the specified index. Fires the {@link #remove} event.
  670. * @param {Number} index The index of the record to remove.
  671. */
  672. removeAt : function(index){
  673. this.remove(this.getAt(index));
  674. },
  675. <div id="method-Ext.data.Store-removeAll"></div>/**
  676. * Remove all Records from the Store and fires the {@link #clear} event.
  677. * @param {Boolean} silent [false] Defaults to <tt>false</tt>. Set <tt>true</tt> to not fire clear event.
  678. */
  679. removeAll : function(silent){
  680. var items = [];
  681. this.each(function(rec){
  682. items.push(rec);
  683. });
  684. this.clearData();
  685. if(this.snapshot){
  686. this.snapshot.clear();
  687. }
  688. if(this.pruneModifiedRecords){
  689. this.modified = [];
  690. }
  691. if (silent !== true) { // <-- prevents write-actions when we just want to clear a store.
  692. this.fireEvent('clear', this, items);
  693. }
  694. },
  695. // private
  696. onClear: function(store, records){
  697. Ext.each(records, function(rec, index){
  698. this.destroyRecord(this, rec, index);
  699. }, this);
  700. },
  701. <div id="method-Ext.data.Store-insert"></div>/**
  702. * Inserts Records into the Store at the given index and fires the {@link #add} event.
  703. * See also <code>{@link #add}</code> and <code>{@link #addSorted}</code>.
  704. * @param {Number} index The start index at which to insert the passed Records.
  705. * @param {Ext.data.Record[]} records An Array of Ext.data.Record objects to add to the cache.
  706. */
  707. insert : function(index, records) {
  708. var i, len, record;
  709. records = [].concat(records);
  710. for (i = 0, len = records.length; i < len; i++) {
  711. record = records[i];
  712. this.data.insert(index + i, record);
  713. record.join(this);
  714. if (record.dirty || record.phantom) {
  715. this.modified.push(record);
  716. }
  717. }
  718. if (this.snapshot) {
  719. this.snapshot.addAll(records);
  720. }
  721. this.fireEvent('add', this, records, index);
  722. },
  723. <div id="method-Ext.data.Store-indexOf"></div>/**
  724. * Get the index within the cache of the passed Record.
  725. * @param {Ext.data.Record} record The Ext.data.Record object to find.
  726. * @return {Number} The index of the passed Record. Returns -1 if not found.
  727. */
  728. indexOf : function(record){
  729. return this.data.indexOf(record);
  730. },
  731. <div id="method-Ext.data.Store-indexOfId"></div>/**
  732. * Get the index within the cache of the Record with the passed id.
  733. * @param {String} id The id of the Record to find.
  734. * @return {Number} The index of the Record. Returns -1 if not found.
  735. */
  736. indexOfId : function(id){
  737. return this.data.indexOfKey(id);
  738. },
  739. <div id="method-Ext.data.Store-getById"></div>/**
  740. * Get the Record with the specified id.
  741. * @param {String} id The id of the Record to find.
  742. * @return {Ext.data.Record} The Record with the passed id. Returns undefined if not found.
  743. */
  744. getById : function(id){
  745. return (this.snapshot || this.data).key(id);
  746. },
  747. <div id="method-Ext.data.Store-getAt"></div>/**
  748. * Get the Record at the specified index.
  749. * @param {Number} index The index of the Record to find.
  750. * @return {Ext.data.Record} The Record at the passed index. Returns undefined if not found.
  751. */
  752. getAt : function(index){
  753. return this.data.itemAt(index);
  754. },
  755. <div id="method-Ext.data.Store-getRange"></div>/**
  756. * Returns a range of Records between specified indices.
  757. * @param {Number} startIndex (optional) The starting index (defaults to 0)
  758. * @param {Number} endIndex (optional) The ending index (defaults to the last Record in the Store)
  759. * @return {Ext.data.Record[]} An array of Records
  760. */
  761. getRange : function(start, end){
  762. return this.data.getRange(start, end);
  763. },
  764. // private
  765. storeOptions : function(o){
  766. o = Ext.apply({}, o);
  767. delete o.callback;
  768. delete o.scope;
  769. this.lastOptions = o;
  770. },
  771. // private
  772. clearData: function(){
  773. this.data.each(function(rec) {
  774. rec.join(null);
  775. });
  776. this.data.clear();
  777. },
  778. <div id="method-Ext.data.Store-load"></div>/**
  779. * <p>Loads the Record cache from the configured <tt>{@link #proxy}</tt> using the configured <tt>{@link #reader}</tt>.</p>
  780. * <br><p>Notes:</p><div class="mdetail-params"><ul>
  781. * <li><b><u>Important</u></b>: loading is asynchronous! This call will return before the new data has been
  782. * loaded. To perform any post-processing where information from the load call is required, specify
  783. * the <tt>callback</tt> function to be called, or use a {@link Ext.util.Observable#listeners a 'load' event handler}.</li>
  784. * <li>If using {@link Ext.PagingToolbar remote paging}, the first load call must specify the <tt>start</tt> and <tt>limit</tt>
  785. * properties in the <code>options.params</code> property to establish the initial position within the
  786. * dataset, and the number of Records to cache on each read from the Proxy.</li>
  787. * <li>If using {@link #remoteSort remote sorting}, the configured <code>{@link #sortInfo}</code>
  788. * will be automatically included with the posted parameters according to the specified
  789. * <code>{@link #paramNames}</code>.</li>
  790. * </ul></div>
  791. * @param {Object} options An object containing properties which control loading options:<ul>
  792. * <li><b><tt>params</tt></b> :Object<div class="sub-desc"><p>An object containing properties to pass as HTTP
  793. * parameters to a remote data source. <b>Note</b>: <code>params</code> will override any
  794. * <code>{@link #baseParams}</code> of the same name.</p>
  795. * <p>Parameters are encoded as standard HTTP parameters using {@link Ext#urlEncode}.</p></div></li>
  796. * <li><b>callback</b> : Function<div class="sub-desc"><p>A function to be called after the Records
  797. * have been loaded. The callback is called after the load event is fired, and is passed the following arguments:<ul>
  798. * <li>r : Ext.data.Record[] An Array of Records loaded.</li>
  799. * <li>options : Options object from the load call.</li>
  800. * <li>success : Boolean success indicator.</li></ul></p></div></li>
  801. * <li><b>scope</b> : Object<div class="sub-desc"><p>Scope with which to call the callback (defaults
  802. * to the Store object)</p></div></li>
  803. * <li><b>add</b> : Boolean<div class="sub-desc"><p>Indicator to append loaded records rather than
  804. * replace the current cache. <b>Note</b>: see note for <tt>{@link #loadData}</tt></p></div></li>
  805. * </ul>
  806. * @return {Boolean} If the <i>developer</i> provided <tt>{@link #beforeload}</tt> event handler returns
  807. * <tt>false</tt>, the load call will abort and will return <tt>false</tt>; otherwise will return <tt>true</tt>.
  808. */
  809. load : function(options) {
  810. options = Ext.apply({}, options);
  811. this.storeOptions(options);
  812. if(this.sortInfo && this.remoteSort){
  813. var pn = this.paramNames;
  814. options.params = Ext.apply({}, options.params);
  815. options.params[pn.sort] = this.sortInfo.field;
  816. options.params[pn.dir] = this.sortInfo.direction;
  817. }
  818. try {
  819. return this.execute('read', null, options); // <-- null represents rs. No rs for load actions.
  820. } catch(e) {
  821. this.handleException(e);
  822. return false;
  823. }
  824. },
  825. /**
  826. * updateRecord Should not be used directly. This method will be called automatically if a Writer is set.
  827. * Listens to 'update' event.
  828. * @param {Object} store
  829. * @param {Object} record
  830. * @param {Object} action
  831. * @private
  832. */
  833. updateRecord : function(store, record, action) {
  834. if (action == Ext.data.Record.EDIT && this.autoSave === true && (!record.phantom || (record.phantom && record.isValid()))) {
  835. this.save();
  836. }
  837. },
  838. /**
  839. * @private
  840. * Should not be used directly. Store#add will call this automatically if a Writer is set
  841. * @param {Object} store
  842. * @param {Object} records
  843. * @param {Object} index
  844. */
  845. createRecords : function(store, records, index) {
  846. var modified = this.modified,
  847. length = records.length,
  848. record, i;
  849. for (i = 0; i < length; i++) {
  850. record = records[i];
  851. if (record.phantom && record.isValid()) {
  852. record.markDirty(); // <-- Mark new records dirty (Ed: why?)
  853. if (modified.indexOf(record) == -1) {
  854. modified.push(record);
  855. }
  856. }
  857. }
  858. if (this.autoSave === true) {
  859. this.save();
  860. }
  861. },
  862. /**
  863. * Destroys a Record. Should not be used directly. It's called by Store#remove if a Writer is set.
  864. * @param {Store} store this
  865. * @param {Ext.data.Record} record
  866. * @param {Number} index
  867. * @private
  868. */
  869. destroyRecord : function(store, record, index) {
  870. if (this.modified.indexOf(record) != -1) { // <-- handled already if @cfg pruneModifiedRecords == true
  871. this.modified.remove(record);
  872. }
  873. if (!record.phantom) {
  874. this.removed.push(record);
  875. // since the record has already been removed from the store but the server request has not yet been executed,
  876. // must keep track of the last known index this record existed. If a server error occurs, the record can be
  877. // put back into the store. @see Store#createCallback where the record is returned when response status === false
  878. record.lastIndex = index;
  879. if (this.autoSave === true) {
  880. this.save();
  881. }
  882. }
  883. },
  884. /**
  885. * This method should generally not be used directly. This method is called internally
  886. * by {@link #load}, or if a Writer is set will be called automatically when {@link #add},
  887. * {@link #remove}, or {@link #update} events fire.
  888. * @param {String} action Action name ('read', 'create', 'update', or 'destroy')
  889. * @param {Record/Record[]} rs
  890. * @param {Object} options
  891. * @throws Error
  892. * @private
  893. */
  894. execute : function(action, rs, options, /* private */ batch) {
  895. // blow up if action not Ext.data.CREATE, READ, UPDATE, DESTROY
  896. if (!Ext.data.Api.isAction(action)) {
  897. throw new Ext.data.Api.Error('execute', action);
  898. }
  899. // make sure options has a fresh, new params hash
  900. options = Ext.applyIf(options||{}, {
  901. params: {}
  902. });
  903. if(batch !== undefined){
  904. this.addToBatch(batch);
  905. }
  906. // have to separate before-events since load has a different signature than create,destroy and save events since load does not
  907. // include the rs (record resultset) parameter. Capture return values from the beforeaction into doRequest flag.
  908. var doRequest = true;
  909. if (action === 'read') {
  910. doRequest = this.fireEvent('beforeload', this, options);
  911. Ext.applyIf(options.params, this.baseParams);
  912. }
  913. else {
  914. // if Writer is configured as listful, force single-record rs to be [{}] instead of {}
  915. // TODO Move listful rendering into DataWriter where the @cfg is defined. Should be easy now.
  916. if (this.writer.listful === true && this.restful !== true) {
  917. rs = (Ext.isArray(rs)) ? rs : [rs];
  918. }
  919. // if rs has just a single record, shift it off so that Writer writes data as '{}' rather than '[{}]'
  920. else if (Ext.isArray(rs) && rs.length == 1) {
  921. rs = rs.shift();
  922. }
  923. // Write the action to options.params
  924. if ((doRequest = this.fireEvent('beforewrite', this, action, rs, options)) !== false) {
  925. this.writer.apply(options.params, this.baseParams, action, rs);
  926. }
  927. }
  928. if (doRequest !== false) {
  929. // Send request to proxy.
  930. if (this.writer && this.proxy.url && !this.proxy.restful && !Ext.data.Api.hasUniqueUrl(this.proxy, action)) {
  931. options.params.xaction = action; // <-- really old, probaby unecessary.
  932. }
  933. // Note: Up until this point we've been dealing with 'action' as a key from Ext.data.Api.actions.
  934. // We'll flip it now and send the value into DataProxy#request, since it's the value which maps to
  935. // the user's configured DataProxy#api
  936. // TODO Refactor all Proxies to accept an instance of Ext.data.Request (not yet defined) instead of this looooooong list
  937. // of params. This method is an artifact from Ext2.
  938. this.proxy.request(Ext.data.Api.actions[action], rs, options.params, this.reader, this.createCallback(action, rs, batch), this, options);
  939. }
  940. return doRequest;
  941. },
  942. <div id="method-Ext.data.Store-save"></div>/**
  943. * Saves all pending changes to the store. If the commensurate Ext.data.Api.actions action is not configured, then
  944. * the configured <code>{@link #url}</code> will be used.
  945. * <pre>
  946. * change url
  947. * --------------- --------------------
  948. * removed records Ext.data.Api.actions.destroy
  949. * phantom records Ext.data.Api.actions.create
  950. * {@link #getModifiedRecords modified records} Ext.data.Api.actions.update
  951. * </pre>
  952. * @TODO: Create extensions of Error class and send associated Record with thrown exceptions.
  953. * e.g.: Ext.data.DataReader.Error or Ext.data.Error or Ext.data.DataProxy.Error, etc.
  954. * @return {Number} batch Returns a number to uniquely identify the "batch" of saves occurring. -1 will be returned
  955. * if there are no items to save or the save was cancelled.
  956. */
  957. save : function() {
  958. if (!this.writer) {
  959. throw new Ext.data.Store.Error('writer-undefined');
  960. }
  961. var queue = [],
  962. len,
  963. trans,
  964. batch,
  965. data = {},
  966. i;
  967. // DESTROY: First check for removed records. Records in this.removed are guaranteed non-phantoms. @see Store#remove
  968. if(this.removed.length){
  969. queue.push(['destroy', this.removed]);
  970. }
  971. // Check for modified records. Use a copy so Store#rejectChanges will work if server returns error.
  972. var rs = [].concat(this.getModifiedRecords());
  973. if(rs.length){
  974. // CREATE: Next check for phantoms within rs. splice-off and execute create.
  975. var phantoms = [];
  976. for(i = rs.length-1; i >= 0; i--){
  977. if(rs[i].phantom === true){
  978. var rec = rs.splice(i, 1).shift();
  979. if(rec.isValid()){
  980. phantoms.push(rec);
  981. }
  982. }else if(!rs[i].isValid()){ // <-- while we're here, splice-off any !isValid real records
  983. rs.splice(i,1);
  984. }
  985. }
  986. // If we have valid phantoms, create them...
  987. if(phantoms.length){
  988. queue.push(['create', phantoms]);
  989. }
  990. // UPDATE: And finally, if we're still here after splicing-off phantoms and !isValid real records, update the rest...
  991. if(rs.length){
  992. queue.push(['update', rs]);
  993. }
  994. }
  995. len = queue.length;
  996. if(len){
  997. batch = ++this.batchCounter;
  998. for(i = 0; i < len; ++i){
  999. trans = queue[i];
  1000. data[trans[0]] = trans[1];
  1001. }
  1002. if(this.fireEvent('beforesave', this, data) !== false){
  1003. for(i = 0; i < len; ++i){
  1004. trans = queue[i];
  1005. this.doTransaction(trans[0], trans[1], batch);
  1006. }
  1007. return batch;
  1008. }
  1009. }
  1010. return -1;
  1011. },
  1012. // private. Simply wraps call to Store#execute in try/catch. Defers to Store#handleException on error. Loops if batch: false
  1013. doTransaction : function(action, rs, batch) {
  1014. function transaction(records) {
  1015. try{
  1016. this.execute(action, records, undefined, batch);
  1017. }catch (e){
  1018. this.handleException(e);
  1019. }
  1020. }
  1021. if(this.batch === false){
  1022. for(var i = 0, len = rs.length; i < len; i++){
  1023. transaction.call(this, rs[i]);
  1024. }
  1025. }else{
  1026. transaction.call(this, rs);
  1027. }
  1028. },
  1029. // private
  1030. addToBatch : function(batch){
  1031. var b = this.batches,
  1032. key = this.batchKey + batch,
  1033. o = b[key];
  1034. if(!o){
  1035. b[key] = o = {
  1036. id: batch,
  1037. count: 0,
  1038. data: {}
  1039. };
  1040. }
  1041. ++o.count;
  1042. },
  1043. removeFromBatch : function(batch, action, data){
  1044. var b = this.batches,
  1045. key = this.batchKey + batch,
  1046. o = b[key],
  1047. arr;
  1048. if(o){
  1049. arr = o.data[action] || [];
  1050. o.data[action] = arr.concat(data);
  1051. if(o.count === 1){
  1052. data = o.data;
  1053. delete b[key];
  1054. this.fireEvent('save', this, batch, data);
  1055. }else{
  1056. --o.count;
  1057. }
  1058. }
  1059. },
  1060. // @private callback-handler for remote CRUD actions
  1061. // Do not override -- override loadRecords, onCreateRecords, onDestroyRecords and onUpdateRecords instead.
  1062. createCallback : function(action, rs, batch) {
  1063. var actions = Ext.data.Api.actions;
  1064. return (action == 'read') ? this.loadRecords : function(data, response, success) {
  1065. // calls: onCreateRecords | onUpdateRecords | onDestroyRecords
  1066. this['on' + Ext.util.Format.capitalize(action) + 'Records'](success, rs, [].concat(data));
  1067. // If success === false here, exception will have been called in DataProxy
  1068. if (success === true) {
  1069. this.fireEvent('write', this, action, data, response, rs);
  1070. }
  1071. this.removeFromBatch(batch, action, data);
  1072. };
  1073. },
  1074. // Clears records from modified array after an exception event.
  1075. // NOTE: records are left marked dirty. Do we want to commit them even though they were not updated/realized?
  1076. // TODO remove this method?
  1077. clearModified : function(rs) {
  1078. if (Ext.isArray(rs)) {
  1079. for (var n=rs.length-1;n>=0;n--) {
  1080. this.modified.splice(this.modified.indexOf(rs[n]), 1);
  1081. }
  1082. } else {
  1083. this.modified.splice(this.modified.indexOf(rs), 1);
  1084. }
  1085. },
  1086. // remap record ids in MixedCollection after records have been realized. @see Store#onCreateRecords, @see DataReader#realize
  1087. reMap : function(record) {
  1088. if (Ext.isArray(record)) {
  1089. for (var i = 0, len = record.length; i < len; i++) {
  1090. this.reMap(record[i]);
  1091. }
  1092. } else {
  1093. delete this.data.map[record._phid];
  1094. this.data.map[record.id] = record;
  1095. var index = this.data.keys.indexOf(record._phid);
  1096. this.data.keys.splice(index, 1, record.id);
  1097. delete record._phid;
  1098. }
  1099. },
  1100. // @protected onCreateRecord proxy callback for create action
  1101. onCreateRecords : function(success, rs, data) {
  1102. if (success === true) {
  1103. try {
  1104. this.reader.realize(rs, data);
  1105. this.reMap(rs);
  1106. }
  1107. catch (e) {
  1108. this.handleException(e);
  1109. if (Ext.isArray(rs)) {
  1110. // Recurse to run back into the try {}. DataReader#realize splices-off the rs until empty.
  1111. this.onCreateRecords(success, rs, data);
  1112. }
  1113. }
  1114. }
  1115. },
  1116. // @protected, onUpdateRecords proxy callback for update action
  1117. onUpdateRecords : function(success, rs, data) {
  1118. if (success === true) {
  1119. try {
  1120. this.reader.update(rs, data);
  1121. } catch (e) {
  1122. this.handleException(e);
  1123. if (Ext.isArray(rs)) {
  1124. // Recurse to run back into the try {}. DataReader#update splices-off the rs until empty.
  1125. this.onUpdateRecords(success, rs, data);
  1126. }
  1127. }
  1128. }
  1129. },
  1130. // @protected onDestroyRecords proxy callback for destroy action
  1131. onDestroyRecords : function(success, rs, data) {
  1132. // splice each rec out of this.removed
  1133. rs = (rs instanceof Ext.data.Record) ? [rs] : [].concat(rs);
  1134. for (var i=0,len=rs.length;i<len;i++) {
  1135. this.removed.splice(this.removed.indexOf(rs[i]), 1);
  1136. }
  1137. if (success === false) {
  1138. // put records back into store if remote destroy fails.
  1139. // @TODO: Might want to let developer decide.
  1140. for (i=rs.length-1;i>=0;i--) {
  1141. this.insert(rs[i].lastIndex, rs[i]); // <-- lastIndex set in Store#destroyRecord
  1142. }
  1143. }
  1144. },
  1145. // protected handleException. Possibly temporary until Ext framework has an exception-handler.
  1146. handleException : function(e) {
  1147. // @see core/Error.js
  1148. Ext.handleError(e);
  1149. },
  1150. <div id="method-Ext.data.Store-reload"></div>/**
  1151. * <p>Reloads the Record cache from the configured Proxy using the configured
  1152. * {@link Ext.data.Reader Reader} and the options from the last load operation
  1153. * performed.</p>
  1154. * <p><b>Note</b>: see the Important note in {@link #load}.</p>
  1155. * @param {Object} options <p>(optional) An <tt>Object</tt> containing
  1156. * {@link #load loading options} which may override the {@link #lastOptions options}
  1157. * used in the last {@link #load} operation. See {@link #load} for details
  1158. * (defaults to <tt>null</tt>, in which case the {@link #lastOptions} are
  1159. * used).</p>
  1160. * <br><p>To add new params to the existing params:</p><pre><code>
  1161. lastOptions = myStore.lastOptions;
  1162. Ext.apply(lastOptions.params, {
  1163. myNewParam: true
  1164. });
  1165. myStore.reload(lastOptions);
  1166. * </code></pre>
  1167. */
  1168. reload : function(options){
  1169. this.load(Ext.applyIf(options||{}, this.lastOptions));
  1170. },
  1171. // private
  1172. // Called as a callback by the Reader during a load operation.
  1173. loadRecords : function(o, options, success){
  1174. var i, len;
  1175. if (this.isDestroyed === true) {
  1176. return;
  1177. }
  1178. if(!o || success === false){
  1179. if(success !== false){
  1180. this.fireEvent('load', this, [], options);
  1181. }
  1182. if(options.callback){
  1183. options.callback.call(options.scope || this, [], options, false, o);
  1184. }
  1185. return;
  1186. }
  1187. var r = o.records, t = o.totalRecords || r.length;
  1188. if(!options || options.add !== true){
  1189. if(this.pruneModifiedRecords){
  1190. this.modified = [];
  1191. }
  1192. for(i = 0, len = r.length; i < len; i++){
  1193. r[i].join(this);
  1194. }
  1195. if(this.snapshot){
  1196. this.data = this.snapshot;
  1197. delete this.snapshot;
  1198. }
  1199. this.clearData();
  1200. this.data.addAll(r);
  1201. this.totalLength = t;
  1202. this.applySort();
  1203. this.fireEvent('datachanged', this);
  1204. }else{
  1205. var toAdd = [],
  1206. rec,
  1207. cnt = 0;
  1208. for(i = 0, len = r.length; i < len; ++i){
  1209. rec = r[i];
  1210. if(this.indexOfId(rec.id) > -1){
  1211. this.doUpdate(rec);
  1212. }else{
  1213. toAdd.push(rec);
  1214. ++cnt;
  1215. }
  1216. }
  1217. this.totalLength = Math.max(t, this.data.length + cnt);
  1218. this.add(toAdd);
  1219. }
  1220. this.fireEvent('load', this, r, options);
  1221. if(options.callback){
  1222. options.callback.call(options.scope || this, r, options, true);
  1223. }
  1224. },
  1225. <div id="method-Ext.data.Store-loadData"></div>/**
  1226. * Loads data from a passed data block and fires the {@link #load} event. A {@link Ext.data.Reader Reader}
  1227. * which understands the format of the data must have been configured in the constructor.
  1228. * @param {Object} data The data block from which to read the Records. The format of the data expected
  1229. * is dependent on the type of {@link Ext.data.Reader Reader} that is configured and should correspond to
  1230. * that {@link Ext.data.Reader Reader}'s <tt>{@link Ext.data.Reader#readRecords}</tt> parameter.
  1231. * @param {Boolean} append (Optional) <tt>true</tt> to append the new Records rather the default to replace
  1232. * the existing cache.
  1233. * <b>Note</b>: that Records in a Store are keyed by their {@link Ext.data.Record#id id}, so added Records
  1234. * with ids which are already present in the Store will <i>replace</i> existing Records. Only Records with
  1235. * new, unique ids will be added.
  1236. */
  1237. loadData : function(o, append){
  1238. var r = this.reader.readRecords(o);
  1239. this.loadRecords(r, {add: append}, true);
  1240. },
  1241. <div id="method-Ext.data.Store-getCount"></div>/**
  1242. * Gets the number of cached records.
  1243. * <p>If using paging, this may not be the total size of the dataset. If the data object
  1244. * used by the Reader contains the dataset size, then the {@link #getTotalCount} function returns
  1245. * the dataset size. <b>Note</b>: see the Important note in {@link #load}.</p>
  1246. * @return {Number} The number of Records in the Store's cache.
  1247. */
  1248. getCount : function(){
  1249. return this.data.length || 0;
  1250. },
  1251. <div id="method-Ext.data.Store-getTotalCount"></div>/**
  1252. * Gets the total number of records in the dataset as returned by the server.
  1253. * <p>If using paging, for this to be accurate, the data object used by the {@link #reader Reader}
  1254. * must contain the dataset size. For remote data sources, the value for this property
  1255. * (<tt>totalProperty</tt> for {@link Ext.data.JsonReader JsonReader},
  1256. * <tt>totalRecords</tt> for {@link Ext.data.XmlReader XmlReader}) shall be returned by a query on the server.
  1257. * <b>Note</b>: see the Important note in {@link #load}.</p>
  1258. * @return {Number} The number of Records as specified in the data object passed to the Reader
  1259. * by the Proxy.
  1260. * <p><b>Note</b>: this value is not updated when changing the contents of the Store locally.</p>
  1261. */
  1262. getTotalCount : function(){
  1263. return this.totalLength || 0;
  1264. },
  1265. <div id="method-Ext.data.Store-getSortState"></div>/**
  1266. * Returns an object describing the current sort state of this Store.
  1267. * @return {Object} The sort state of the Store. An object with two properties:<ul>
  1268. * <li><b>field : String<p class="sub-desc">The name of the field by which the Records are sorted.</p></li>
  1269. * <li><b>direction : String<p class="sub-desc">The sort order, 'ASC' or 'DESC' (case-sensitive).</p></li>
  1270. * </ul>
  1271. * See <tt>{@link #sortInfo}</tt> for additional details.
  1272. */
  1273. getSortState : function(){
  1274. return this.sortInfo;
  1275. },
  1276. /**
  1277. * @private
  1278. * Invokes sortData if we have sortInfo to sort on and are not sorting remotely
  1279. */
  1280. applySort : function(){
  1281. if ((this.sortInfo || this.multiSortInfo) && !this.remoteSort) {
  1282. this.sortData();
  1283. }
  1284. },
  1285. /**
  1286. * @private
  1287. * Performs the actual sorting of data. This checks to see if we currently have a multi sort or not. It applies
  1288. * each sorter field/direction pair in turn by building an OR'ed master sorting function and running it against
  1289. * the full dataset
  1290. */
  1291. sortData : function() {
  1292. var sortInfo = this.hasMultiSort ? this.multiSortInfo : this.sortInfo,
  1293. direction = sortInfo.direction || "ASC",
  1294. sorters = sortInfo.sorters,
  1295. sortFns = [];
  1296. //if we just have a single sorter, pretend it's the first in an array
  1297. if (!this.hasMultiSort) {
  1298. sorters = [{direction: direction, field: sortInfo.field}];
  1299. }
  1300. //create a sorter function for each sorter field/direction combo
  1301. for (var i=0, j = sorters.length; i < j; i++) {
  1302. sortFns.push(this.createSortFunction(sorters[i].field, sorters[i].direction));
  1303. }
  1304. if (sortFns.length == 0) {
  1305. return;
  1306. }
  1307. //the direction modifier is multiplied with the result of the sorting functions to provide overall sort direction
  1308. //(as opposed to direction per field)
  1309. var directionModifier = direction.toUpperCase() == "DESC" ? -1 : 1;
  1310. //create a function which ORs each sorter together to enable multi-sort
  1311. var fn = function(r1, r2) {
  1312. var result = sortFns[0].call(this, r1, r2);
  1313. //if we have more than one sorter, OR any additional sorter functions together
  1314. if (sortFns.length > 1) {
  1315. for (var i=1, j = sortFns.length; i < j; i++) {
  1316. result = result || sortFns[i].call(this, r1, r2);
  1317. }
  1318. }
  1319. return directionModifier * result;
  1320. };
  1321. //sort the data
  1322. this.data.sort(direction, fn);
  1323. if (this.snapshot && this.snapshot != this.data) {
  1324. this.snapshot.sort(direction, fn);
  1325. }
  1326. },
  1327. /**
  1328. * @private
  1329. * Creates and returns a function which sorts an array by the given field and direction
  1330. * @param {String} field The field to create the sorter for
  1331. * @param {String} direction The direction to sort by (defaults to "ASC")
  1332. * @return {Function} A function which sorts by the field/direction combination provided
  1333. */
  1334. createSortFunction: function(field, direction) {
  1335. direction = direction || "ASC";
  1336. var directionModifier = direction.toUpperCase() == "DESC" ? -1 : 1;
  1337. var sortType = this.fields.get(field).sortType;
  1338. //create a comparison function. Takes 2 records, returns 1 if record 1 is greater,
  1339. //-1 if record 2 is greater or 0 if they are equal
  1340. return function(r1, r2) {
  1341. var v1 = sortType(r1.data[field]),
  1342. v2 = sortType(r2.data[field]);
  1343. return directionModifier * (v1 > v2 ? 1 : (v1 < v2 ? -1 : 0));
  1344. };
  1345. },
  1346. <div id="method-Ext.data.Store-setDefaultSort"></div>/**
  1347. * Sets the default sort column and order to be used by the next {@link #load} operation.
  1348. * @param {String} fieldName The name of the field to sort by.
  1349. * @param {String} dir (optional) The sort order, 'ASC' or 'DESC' (case-sensitive, defaults to <tt>'ASC'</tt>)
  1350. */
  1351. setDefaultSort : function(field, dir) {
  1352. dir = dir ? dir.toUpperCase() : 'ASC';
  1353. this.sortInfo = {field: field, direction: dir};
  1354. this.sortToggle[field] = dir;
  1355. },
  1356. <div id="method-Ext.data.Store-sort"></div>/**
  1357. * Sort the Records.
  1358. * If remote sorting is used, the sort is performed on the server, and the cache is reloaded. If local
  1359. * sorting is used, the cache is sorted internally. See also {@link #remoteSort} and {@link #paramNames}.
  1360. * This function accepts two call signatures - pass in a field name as the first argument to sort on a single
  1361. * field, or pass in an array of sort configuration objects to sort by multiple fields.
  1362. * Single sort example:
  1363. * store.sort('name', 'ASC');
  1364. * Multi sort example:
  1365. * store.sort([
  1366. * {
  1367. * field : 'name',
  1368. * direction: 'ASC'
  1369. * },
  1370. * {
  1371. * field : 'salary',
  1372. * direction: 'DESC'
  1373. * }
  1374. * ], 'ASC');
  1375. * In this second form, the sort configs are applied in order, with later sorters sorting within earlier sorters' results.
  1376. * For example, if two records with the same name are present they will also be sorted by salary if given the sort configs
  1377. * above. Any number of sort configs can be added.
  1378. * @param {String/Array} fieldName The name of the field to sort by, or an array of ordered sort configs
  1379. * @param {String} dir (optional) The sort order, 'ASC' or 'DESC' (case-sensitive, defaults to <tt>'ASC'</tt>)
  1380. */
  1381. sort : function(fieldName, dir) {
  1382. if (Ext.isArray(arguments[0])) {
  1383. return this.multiSort.call(this, fieldName, dir);
  1384. } else {
  1385. return this.singleSort(fieldName, dir);
  1386. }
  1387. },
  1388. <div id="method-Ext.data.Store-singleSort"></div>/**
  1389. * Sorts the store contents by a single field and direction. This is called internally by {@link sort} and would
  1390. * not usually be called manually
  1391. * @param {String} fieldName The name of the field to sort by.
  1392. * @param {String} dir (optional) The sort order, 'ASC' or 'DESC' (case-sensitive, defaults to <tt>'ASC'</tt>)
  1393. */
  1394. singleSort: function(fieldName, dir) {
  1395. var field = this.fields.get(fieldName);
  1396. if (!field) {
  1397. return false;
  1398. }
  1399. var name = field.name,
  1400. sortInfo = this.sortInfo || null,
  1401. sortToggle = this.sortToggle ? this.sortToggle[name] : null;
  1402. if (!dir) {
  1403. if (sortInfo && sortInfo.field == name) { // toggle sort dir
  1404. dir = (this.sortToggle[name] || 'ASC').toggle('ASC', 'DESC');
  1405. } else {
  1406. dir = field.sortDir;
  1407. }
  1408. }
  1409. this.sortToggle[name] = dir;
  1410. this.sortInfo = {field: name, direction: dir};
  1411. this.hasMultiSort = false;
  1412. if (this.remoteSort) {
  1413. if (!this.load(this.lastOptions)) {
  1414. if (sortToggle) {
  1415. this.sortToggle[name] = sortToggle;
  1416. }
  1417. if (sortInfo) {
  1418. this.sortInfo = sortInfo;
  1419. }
  1420. }
  1421. } else {
  1422. this.applySort();
  1423. this.fireEvent('datachanged', this);
  1424. }
  1425. return true;
  1426. },
  1427. <div id="method-Ext.data.Store-multiSort"></div>/**
  1428. * Sorts the contents of this store by multiple field/direction sorters. This is called internally by {@link sort}
  1429. * and would not usually be called manually.
  1430. * Multi sorting only currently applies to local datasets - multiple sort data is not currently sent to a proxy
  1431. * if remoteSort is used.
  1432. * @param {Array} sorters Array of sorter objects (field and direction)
  1433. * @param {String} direction Overall direction to sort the ordered results by (defaults to "ASC")
  1434. */
  1435. multiSort: function(sorters, direction) {
  1436. this.hasMultiSort = true;
  1437. direction = direction || "ASC";
  1438. //toggle sort direction
  1439. if (this.multiSortInfo && direction == this.multiSortInfo.direction) {
  1440. direction = direction.toggle("ASC", "DESC");
  1441. }
  1442. <div id="prop-Ext.data.Store-multiSortInfo"></div>/**
  1443. * Object containing overall sort direction and an ordered array of sorter configs used when sorting on multiple fields
  1444. * @property multiSortInfo
  1445. * @type Object
  1446. */
  1447. this.multiSortInfo = {
  1448. sorters : sorters,
  1449. direction: direction
  1450. };
  1451. if (this.remoteSort) {
  1452. this.singleSort(sorters[0].field, sorters[0].direction);
  1453. } else {
  1454. this.applySort();
  1455. this.fireEvent('datachanged', this);
  1456. }
  1457. },
  1458. <div id="method-Ext.data.Store-each"></div>/**
  1459. * Calls the specified function for each of the {@link Ext.data.Record Records} in the cache.
  1460. * @param {Function} fn The function to call. The {@link Ext.data.Record Record} is passed as the first parameter.
  1461. * Returning <tt>false</tt> aborts and exits the iteration.
  1462. * @param {Object} scope (optional) The scope (<code>this</code> reference) in which the function is executed.
  1463. * Defaults to the current {@link Ext.data.Record Record} in the iteration.
  1464. */
  1465. each : function(fn, scope){
  1466. this.data.each(fn, scope);
  1467. },
  1468. <div id="method-Ext.data.Store-getModifiedRecords"></div>/**
  1469. * Gets all {@link Ext.data.Record records} modified since the last commit. Modified records are
  1470. * persisted across load operations (e.g., during paging). <b>Note</b>: deleted records are not
  1471. * included. See also <tt>{@link #pruneModifiedRecords}</tt> and
  1472. * {@link Ext.data.Record}<tt>{@link Ext.data.Record#markDirty markDirty}.</tt>.
  1473. * @return {Ext.data.Record[]} An array of {@link Ext.data.Record Records} containing outstanding
  1474. * modifications. To obtain modified fields within a modified record see
  1475. *{@link Ext.data.Record}<tt>{@link Ext.data.Record#modified modified}.</tt>.
  1476. */
  1477. getModifiedRecords : function(){
  1478. return this.modified;
  1479. },
  1480. <div id="method-Ext.data.Store-sum"></div>/**
  1481. * Sums the value of <tt>property</tt> for each {@link Ext.data.Record record} between <tt>start</tt>
  1482. * and <tt>end</tt> and returns the result.
  1483. * @param {String} property A field in each record
  1484. * @param {Number} start (optional) The record index to start at (defaults to <tt>0</tt>)
  1485. * @param {Number} end (optional) The last record index to include (defaults to length - 1)
  1486. * @return {Number} The sum
  1487. */
  1488. sum : function(property, start, end){
  1489. var rs = this.data.items, v = 0;
  1490. start = start || 0;
  1491. end = (end || end === 0) ? end : rs.length-1;
  1492. for(var i = start; i <= end; i++){
  1493. v += (rs[i].data[property] || 0);
  1494. }
  1495. return v;
  1496. },
  1497. /**
  1498. * @private
  1499. * Returns a filter function used to test a the given property's value. Defers most of the work to
  1500. * Ext.util.MixedCollection's createValueMatcher function
  1501. * @param {String} property The property to create the filter function for
  1502. * @param {String/RegExp} value The string/regex to compare the property value to
  1503. * @param {Boolean} anyMatch True if we don't care if the filter value is not the full value (defaults to false)
  1504. * @param {Boolean} caseSensitive True to create a case-sensitive regex (defaults to false)
  1505. * @param {Boolean} exactMatch True to force exact match (^ and $ characters added to the regex). Defaults to false. Ignored if anyMatch is true.
  1506. */
  1507. createFilterFn : function(property, value, anyMatch, caseSensitive, exactMatch){
  1508. if(Ext.isEmpty(value, false)){
  1509. return false;
  1510. }
  1511. value = this.data.createValueMatcher(value, anyMatch, caseSensitive, exactMatch);
  1512. return function(r) {
  1513. return value.test(r.data[property]);
  1514. };
  1515. },
  1516. /**
  1517. * @private
  1518. * Given an array of filter functions (each with optional scope), constructs and returns a single function that returns
  1519. * the result of all of the filters ANDed together
  1520. * @param {Array} filters The array of filter objects (each object should contain an 'fn' and optional scope)
  1521. * @return {Function} The multiple filter function
  1522. */
  1523. createMultipleFilterFn: function(filters) {
  1524. return function(record) {
  1525. var isMatch = true;
  1526. for (var i=0, j = filters.length; i < j; i++) {
  1527. var filter = filters[i],
  1528. fn = filter.fn,
  1529. scope = filter.scope;
  1530. isMatch = isMatch && fn.call(scope, record);
  1531. }
  1532. return isMatch;
  1533. };
  1534. },
  1535. <div id="method-Ext.data.Store-filter"></div>/**
  1536. * Filter the {@link Ext.data.Record records} by a specified property. Alternatively, pass an array of filter
  1537. * options to filter by more than one property.
  1538. * Single filter example:
  1539. * store.filter('name', 'Ed', true, true); //finds all records containing the substring 'Ed'
  1540. * Multiple filter example:
  1541. * <pre><code>
  1542. * store.filter([
  1543. * {
  1544. * property : 'name',
  1545. * value : 'Ed',
  1546. * anyMatch : true, //optional, defaults to true
  1547. * caseSensitive: true //optional, defaults to true
  1548. * },
  1549. *
  1550. * //filter functions can also be passed
  1551. * {
  1552. * fn : function(record) {
  1553. * return record.get('age') == 24
  1554. * },
  1555. * scope: this
  1556. * }
  1557. * ]);
  1558. * </code></pre>
  1559. * @param {String|Array} field A field on your records, or an array containing multiple filter options
  1560. * @param {String/RegExp} value Either a string that the field should begin with, or a RegExp to test
  1561. * against the field.
  1562. * @param {Boolean} anyMatch (optional) <tt>true</tt> to match any part not just the beginning
  1563. * @param {Boolean} caseSensitive (optional) <tt>true</tt> for case sensitive comparison
  1564. * @param {Boolean} exactMatch True to force exact match (^ and $ characters added to the regex). Defaults to false. Ignored if anyMatch is true.
  1565. */
  1566. filter : function(property, value, anyMatch, caseSensitive, exactMatch){
  1567. var fn;
  1568. //we can accept an array of filter objects, or a single filter object - normalize them here
  1569. if (Ext.isObject(property)) {
  1570. property = [property];
  1571. }
  1572. if (Ext.isArray(property)) {
  1573. var filters = [];
  1574. //normalize the filters passed into an array of filter functions
  1575. for (var i=0, j = property.length; i < j; i++) {
  1576. var filter = property[i],
  1577. func = filter.fn,
  1578. scope = filter.scope || this;
  1579. //if we weren't given a filter function, construct one now
  1580. if (!Ext.isFunction(func)) {
  1581. func = this.createFilterFn(filter.property, filter.value, filter.anyMatch, filter.caseSensitive, filter.exactMatch);
  1582. }
  1583. filters.push({fn: func, scope: scope});
  1584. }
  1585. fn = this.createMultipleFilterFn(filters);
  1586. } else {
  1587. //classic single property filter
  1588. fn = this.createFilterFn(property, value, anyMatch, caseSensitive, exactMatch);
  1589. }
  1590. return fn ? this.filterBy(fn) : this.clearFilter();
  1591. },
  1592. <div id="method-Ext.data.Store-filterBy"></div>/**
  1593. * Filter by a function. The specified function will be called for each
  1594. * Record in this Store. If the function returns <tt>true</tt> the Record is included,
  1595. * otherwise it is filtered out.
  1596. * @param {Function} fn The function to be called. It will be passed the following parameters:<ul>
  1597. * <li><b>record</b> : Ext.data.Record<p class="sub-desc">The {@link Ext.data.Record record}
  1598. * to test for filtering. Access field values using {@link Ext.data.Record#get}.</p></li>
  1599. * <li><b>id</b> : Object<p class="sub-desc">The ID of the Record passed.</p></li>
  1600. * </ul>
  1601. * @param {Object} scope (optional) The scope (<code>this</code> reference) in which the function is executed. Defaults to this Store.
  1602. */
  1603. filterBy : function(fn, scope){
  1604. this.snapshot = this.snapshot || this.data;
  1605. this.data = this.queryBy(fn, scope || this);
  1606. this.fireEvent('datachanged', this);
  1607. },
  1608. <div id="method-Ext.data.Store-clearFilter"></div>/**
  1609. * Revert to a view of the Record cache with no filtering applied.
  1610. * @param {Boolean} suppressEvent If <tt>true</tt> the filter is cleared silently without firing the
  1611. * {@link #datachanged} event.
  1612. */
  1613. clearFilter : function(suppressEvent){
  1614. if(this.isFiltered()){
  1615. this.data = this.snapshot;
  1616. delete this.snapshot;
  1617. if(suppressEvent !== true){
  1618. this.fireEvent('datachanged', this);
  1619. }
  1620. }
  1621. },
  1622. <div id="method-Ext.data.Store-isFiltered"></div>/**
  1623. * Returns true if this store is currently filtered
  1624. * @return {Boolean}
  1625. */
  1626. isFiltered : function(){
  1627. return !!this.snapshot && this.snapshot != this.data;
  1628. },
  1629. <div id="method-Ext.data.Store-query"></div>/**
  1630. * Query the records by a specified property.
  1631. * @param {String} field A field on your records
  1632. * @param {String/RegExp} value Either a string that the field
  1633. * should begin with, or a RegExp to test against the field.
  1634. * @param {Boolean} anyMatch (optional) True to match any part not just the beginning
  1635. * @param {Boolean} caseSensitive (optional) True for case sensitive comparison
  1636. * @return {MixedCollection} Returns an Ext.util.MixedCollection of the matched records
  1637. */
  1638. query : function(property, value, anyMatch, caseSensitive){
  1639. var fn = this.createFilterFn(property, value, anyMatch, caseSensitive);
  1640. return fn ? this.queryBy(fn) : this.data.clone();
  1641. },
  1642. <div id="method-Ext.data.Store-queryBy"></div>/**
  1643. * Query the cached records in this Store using a filtering function. The specified function
  1644. * will be called with each record in this Store. If the function returns <tt>true</tt> the record is
  1645. * included in the results.
  1646. * @param {Function} fn The function to be called. It will be passed the following parameters:<ul>
  1647. * <li><b>record</b> : Ext.data.Record<p class="sub-desc">The {@link Ext.data.Record record}
  1648. * to test for filtering. Access field values using {@link Ext.data.Record#get}.</p></li>
  1649. * <li><b>id</b> : Object<p class="sub-desc">The ID of the Record passed.</p></li>
  1650. * </ul>
  1651. * @param {Object} scope (optional) The scope (<code>this</code> reference) in which the function is executed. Defaults to this Store.
  1652. * @return {MixedCollection} Returns an Ext.util.MixedCollection of the matched records
  1653. **/
  1654. queryBy : function(fn, scope){
  1655. var data = this.snapshot || this.data;
  1656. return data.filterBy(fn, scope||this);
  1657. },
  1658. <div id="method-Ext.data.Store-find"></div>/**
  1659. * Finds the index of the first matching Record in this store by a specific field value.
  1660. * @param {String} fieldName The name of the Record field to test.
  1661. * @param {String/RegExp} value Either a string that the field value
  1662. * should begin with, or a RegExp to test against the field.
  1663. * @param {Number} startIndex (optional) The index to start searching at
  1664. * @param {Boolean} anyMatch (optional) True to match any part of the string, not just the beginning
  1665. * @param {Boolean} caseSensitive (optional) True for case sensitive comparison
  1666. * @return {Number} The matched index or -1
  1667. */
  1668. find : function(property, value, start, anyMatch, caseSensitive){
  1669. var fn = this.createFilterFn(property, value, anyMatch, caseSensitive);
  1670. return fn ? this.data.findIndexBy(fn, null, start) : -1;
  1671. },
  1672. <div id="method-Ext.data.Store-findExact"></div>/**
  1673. * Finds the index of the first matching Record in this store by a specific field value.
  1674. * @param {String} fieldName The name of the Record field to test.
  1675. * @param {Mixed} value The value to match the field against.
  1676. * @param {Number} startIndex (optional) The index to start searching at
  1677. * @return {Number} The matched index or -1
  1678. */
  1679. findExact: function(property, value, start){
  1680. return this.data.findIndexBy(function(rec){
  1681. return rec.get(property) === value;
  1682. }, this, start);
  1683. },
  1684. <div id="method-Ext.data.Store-findBy"></div>/**
  1685. * Find the index of the first matching Record in this Store by a function.
  1686. * If the function returns <tt>true</tt> it is considered a match.
  1687. * @param {Function} fn The function to be called. It will be passed the following parameters:<ul>
  1688. * <li><b>record</b> : Ext.data.Record<p class="sub-desc">The {@link Ext.data.Record record}
  1689. * to test for filtering. Access field values using {@link Ext.data.Record#get}.</p></li>
  1690. * <li><b>id</b> : Object<p class="sub-desc">The ID of the Record passed.</p></li>
  1691. * </ul>
  1692. * @param {Object} scope (optional) The scope (<code>this</code> reference) in which the function is executed. Defaults to this Store.
  1693. * @param {Number} startIndex (optional) The index to start searching at
  1694. * @return {Number} The matched index or -1
  1695. */
  1696. findBy : function(fn, scope, start){
  1697. return this.data.findIndexBy(fn, scope, start);
  1698. },
  1699. <div id="method-Ext.data.Store-collect"></div>/**
  1700. * Collects unique values for a particular dataIndex from this store.
  1701. * @param {String} dataIndex The property to collect
  1702. * @param {Boolean} allowNull (optional) Pass true to allow null, undefined or empty string values
  1703. * @param {Boolean} bypassFilter (optional) Pass true to collect from all records, even ones which are filtered
  1704. * @return {Array} An array of the unique values
  1705. **/
  1706. collect : function(dataIndex, allowNull, bypassFilter){
  1707. var d = (bypassFilter === true && this.snapshot) ?
  1708. this.snapshot.items : this.data.items;
  1709. var v, sv, r = [], l = {};
  1710. for(var i = 0, len = d.length; i < len; i++){
  1711. v = d[i].data[dataIndex];
  1712. sv = String(v);
  1713. if((allowNull || !Ext.isEmpty(v)) && !l[sv]){
  1714. l[sv] = true;
  1715. r[r.length] = v;
  1716. }
  1717. }
  1718. return r;
  1719. },
  1720. // private
  1721. afterEdit : function(record){
  1722. if(this.modified.indexOf(record) == -1){
  1723. this.modified.push(record);
  1724. }
  1725. this.fireEvent('update', this, record, Ext.data.Record.EDIT);
  1726. },
  1727. // private
  1728. afterReject : function(record){
  1729. this.modified.remove(record);
  1730. this.fireEvent('update', this, record, Ext.data.Record.REJECT);
  1731. },
  1732. // private
  1733. afterCommit : function(record){
  1734. this.modified.remove(record);
  1735. this.fireEvent('update', this, record, Ext.data.Record.COMMIT);
  1736. },
  1737. <div id="method-Ext.data.Store-commitChanges"></div>/**
  1738. * Commit all Records with {@link #getModifiedRecords outstanding changes}. To handle updates for changes,
  1739. * subscribe to the Store's {@link #update update event}, and perform updating when the third parameter is
  1740. * Ext.data.Record.COMMIT.
  1741. */
  1742. commitChanges : function(){
  1743. var modified = this.modified.slice(0),
  1744. length = modified.length,
  1745. i;
  1746. for (i = 0; i < length; i++){
  1747. modified[i].commit();
  1748. }
  1749. this.modified = [];
  1750. this.removed = [];
  1751. },
  1752. <div id="method-Ext.data.Store-rejectChanges"></div>/**
  1753. * {@link Ext.data.Record#reject Reject} outstanding changes on all {@link #getModifiedRecords modified records}.
  1754. */
  1755. rejectChanges : function() {
  1756. var modified = this.modified.slice(0),
  1757. removed = this.removed.slice(0).reverse(),
  1758. mLength = modified.length,
  1759. rLength = removed.length,
  1760. i;
  1761. for (i = 0; i < mLength; i++) {
  1762. modified[i].reject();
  1763. }
  1764. for (i = 0; i < rLength; i++) {
  1765. this.insert(removed[i].lastIndex || 0, removed[i]);
  1766. removed[i].reject();
  1767. }
  1768. this.modified = [];
  1769. this.removed = [];
  1770. },
  1771. // private
  1772. onMetaChange : function(meta){
  1773. this.recordType = this.reader.recordType;
  1774. this.fields = this.recordType.prototype.fields;
  1775. delete this.snapshot;
  1776. if(this.reader.meta.sortInfo){
  1777. this.sortInfo = this.reader.meta.sortInfo;
  1778. }else if(this.sortInfo && !this.fields.get(this.sortInfo.field)){
  1779. delete this.sortInfo;
  1780. }
  1781. if(this.writer){
  1782. this.writer.meta = this.reader.meta;
  1783. }
  1784. this.modified = [];
  1785. this.fireEvent('metachange', this, this.reader.meta);
  1786. },
  1787. // private
  1788. findInsertIndex : function(record){
  1789. this.suspendEvents();
  1790. var data = this.data.clone();
  1791. this.data.add(record);
  1792. this.applySort();
  1793. var index = this.data.indexOf(record);
  1794. this.data = data;
  1795. this.resumeEvents();
  1796. return index;
  1797. },
  1798. <div id="method-Ext.data.Store-setBaseParam"></div>/**
  1799. * Set the value for a property name in this store's {@link #baseParams}. Usage:</p><pre><code>
  1800. myStore.setBaseParam('foo', {bar:3});
  1801. </code></pre>
  1802. * @param {String} name Name of the property to assign
  1803. * @param {Mixed} value Value to assign the <tt>name</tt>d property
  1804. **/
  1805. setBaseParam : function (name, value){
  1806. this.baseParams = this.baseParams || {};
  1807. this.baseParams[name] = value;
  1808. }
  1809. });
  1810. Ext.reg('store', Ext.data.Store);
  1811. <div id="cls-Ext.data.Store.Error"></div>/**
  1812. * @class Ext.data.Store.Error
  1813. * @extends Ext.Error
  1814. * Store Error extension.
  1815. * @param {String} name
  1816. */
  1817. Ext.data.Store.Error = Ext.extend(Ext.Error, {
  1818. name: 'Ext.data.Store'
  1819. });
  1820. Ext.apply(Ext.data.Store.Error.prototype, {
  1821. lang: {
  1822. 'writer-undefined' : 'Attempted to execute a write-action without a DataWriter installed.'
  1823. }
  1824. });
  1825. </pre>
  1826. </body>
  1827. </html>