4 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
5 <title>The source code</title>
6 <link href="../prettify/prettify.css" type="text/css" rel="stylesheet" />
7 <script type="text/javascript" src="../prettify/prettify.js"></script>
8 <style type="text/css">
9 .highlight { display: block; background-color: #ddd; }
11 <script type="text/javascript">
12 function highlight() {
13 document.getElementById(location.hash.replace(/#/, "")).className = "highlight";
17 <body onload="prettyPrint(); highlight();">
18 <pre class="prettyprint lang-js"><span id='Ext-data-Operation-method-constructor'><span id='Ext-data-Operation'>/**
19 </span></span> * @author Ed Spencer
20 * @class Ext.data.Operation
23 * <p>Represents a single read or write operation performed by a {@link Ext.data.proxy.Proxy Proxy}.
24 * Operation objects are used to enable communication between Stores and Proxies. Application
25 * developers should rarely need to interact with Operation objects directly.</p>
27 * <p>Several Operations can be batched together in a {@link Ext.data.Batch batch}.</p>
30 * @param {Object} config Optional config object
32 Ext.define('Ext.data.Operation', {
33 <span id='Ext-data-Operation-cfg-synchronous'> /**
34 </span> * @cfg {Boolean} synchronous True if this Operation is to be executed synchronously (defaults to true). This
35 * property is inspected by a {@link Ext.data.Batch Batch} to see if a series of Operations can be executed in
40 <span id='Ext-data-Operation-cfg-action'> /**
41 </span> * @cfg {String} action The action being performed by this Operation. Should be one of 'create', 'read', 'update' or 'destroy'
45 <span id='Ext-data-Operation-cfg-filters'> /**
46 </span> * @cfg {Array} filters Optional array of filter objects. Only applies to 'read' actions.
50 <span id='Ext-data-Operation-cfg-sorters'> /**
51 </span> * @cfg {Array} sorters Optional array of sorter objects. Only applies to 'read' actions.
55 <span id='Ext-data-Operation-cfg-group'> /**
56 </span> * @cfg {Object} group Optional grouping configuration. Only applies to 'read' actions where grouping is desired.
60 <span id='Ext-data-Operation-cfg-start'> /**
61 </span> * @cfg {Number} start The start index (offset), used in paging when running a 'read' action.
65 <span id='Ext-data-Operation-cfg-limit'> /**
66 </span> * @cfg {Number} limit The number of records to load. Used on 'read' actions when paging is being used.
70 <span id='Ext-data-Operation-cfg-batch'> /**
71 </span> * @cfg {Ext.data.Batch} batch The batch that this Operation is a part of (optional)
75 <span id='Ext-data-Operation-property-started'> /**
76 </span> * Read-only property tracking the start status of this Operation. Use {@link #isStarted}.
83 <span id='Ext-data-Operation-property-running'> /**
84 </span> * Read-only property tracking the run status of this Operation. Use {@link #isRunning}.
91 <span id='Ext-data-Operation-property-complete'> /**
92 </span> * Read-only property tracking the completion status of this Operation. Use {@link #isComplete}.
99 <span id='Ext-data-Operation-property-success'> /**
100 </span> * Read-only property tracking whether the Operation was successful or not. This starts as undefined and is set to true
101 * or false by the Proxy that is executing the Operation. It is also set to false by {@link #setException}. Use
102 * {@link #wasSuccessful} to query success status.
109 <span id='Ext-data-Operation-property-exception'> /**
110 </span> * Read-only property tracking the exception status of this Operation. Use {@link #hasException} and see {@link #getError}.
111 * @property exception
117 <span id='Ext-data-Operation-property-error'> /**
118 </span> * The error object passed when {@link #setException} was called. This could be any object or primitive.
125 constructor: function(config) {
126 Ext.apply(this, config || {});
129 <span id='Ext-data-Operation-method-setStarted'> /**
130 </span> * Marks the Operation as started
132 setStarted: function() {
137 <span id='Ext-data-Operation-method-setCompleted'> /**
138 </span> * Marks the Operation as completed
140 setCompleted: function() {
141 this.complete = true;
142 this.running = false;
145 <span id='Ext-data-Operation-method-setSuccessful'> /**
146 </span> * Marks the Operation as successful
148 setSuccessful: function() {
152 <span id='Ext-data-Operation-method-setException'> /**
153 </span> * Marks the Operation as having experienced an exception. Can be supplied with an option error message/object.
154 * @param {Mixed} error Optional error string/object
156 setException: function(error) {
157 this.exception = true;
158 this.success = false;
159 this.running = false;
163 <span id='Ext-data-Operation-method-hasException'> /**
164 </span> * Returns true if this Operation encountered an exception (see also {@link #getError})
165 * @return {Boolean} True if there was an exception
167 hasException: function() {
168 return this.exception === true;
171 <span id='Ext-data-Operation-method-getError'> /**
172 </span> * Returns the error string or object that was set using {@link #setException}
173 * @return {Mixed} The error object
175 getError: function() {
179 <span id='Ext-data-Operation-method-getRecords'> /**
180 </span> * Returns an array of Ext.data.Model instances as set by the Proxy.
181 * @return {Array} Any loaded Records
183 getRecords: function() {
184 var resultSet = this.getResultSet();
186 return (resultSet === undefined ? this.records : resultSet.records);
189 <span id='Ext-data-Operation-method-getResultSet'> /**
190 </span> * Returns the ResultSet object (if set by the Proxy). This object will contain the {@link Ext.data.Model model} instances
191 * as well as meta data such as number of instances fetched, number available etc
192 * @return {Ext.data.ResultSet} The ResultSet object
194 getResultSet: function() {
195 return this.resultSet;
198 <span id='Ext-data-Operation-method-isStarted'> /**
199 </span> * Returns true if the Operation has been started. Note that the Operation may have started AND completed,
200 * see {@link #isRunning} to test if the Operation is currently running.
201 * @return {Boolean} True if the Operation has started
203 isStarted: function() {
204 return this.started === true;
207 <span id='Ext-data-Operation-method-isRunning'> /**
208 </span> * Returns true if the Operation has been started but has not yet completed.
209 * @return {Boolean} True if the Operation is currently running
211 isRunning: function() {
212 return this.running === true;
215 <span id='Ext-data-Operation-method-isComplete'> /**
216 </span> * Returns true if the Operation has been completed
217 * @return {Boolean} True if the Operation is complete
219 isComplete: function() {
220 return this.complete === true;
223 <span id='Ext-data-Operation-method-wasSuccessful'> /**
224 </span> * Returns true if the Operation has completed and was successful
225 * @return {Boolean} True if successful
227 wasSuccessful: function() {
228 return this.isComplete() && this.success === true;
231 <span id='Ext-data-Operation-method-setBatch'> /**
233 * Associates this Operation with a Batch
234 * @param {Ext.data.Batch} batch The batch
236 setBatch: function(batch) {
240 <span id='Ext-data-Operation-method-allowWrite'> /**
241 </span> * Checks whether this operation should cause writing to occur.
242 * @return {Boolean} Whether the operation should cause a write to occur.
244 allowWrite: function() {
245 return this.action != 'read';