3 * @class Ext.data.Operation
6 * <p>Represents a single read or write operation performed by a {@link Ext.data.proxy.Proxy Proxy}.
7 * Operation objects are used to enable communication between Stores and Proxies. Application
8 * developers should rarely need to interact with Operation objects directly.</p>
10 * <p>Several Operations can be batched together in a {@link Ext.data.Batch batch}.</p>
13 * @param {Object} config Optional config object
15 Ext.define('Ext.data.Operation', {
17 * @cfg {Boolean} synchronous True if this Operation is to be executed synchronously (defaults to true). This
18 * property is inspected by a {@link Ext.data.Batch Batch} to see if a series of Operations can be executed in
24 * @cfg {String} action The action being performed by this Operation. Should be one of 'create', 'read', 'update' or 'destroy'
29 * @cfg {Array} filters Optional array of filter objects. Only applies to 'read' actions.
34 * @cfg {Array} sorters Optional array of sorter objects. Only applies to 'read' actions.
39 * @cfg {Object} group Optional grouping configuration. Only applies to 'read' actions where grouping is desired.
44 * @cfg {Number} start The start index (offset), used in paging when running a 'read' action.
49 * @cfg {Number} limit The number of records to load. Used on 'read' actions when paging is being used.
54 * @cfg {Ext.data.Batch} batch The batch that this Operation is a part of (optional)
59 * Read-only property tracking the start status of this Operation. Use {@link #isStarted}.
67 * Read-only property tracking the run status of this Operation. Use {@link #isRunning}.
75 * Read-only property tracking the completion status of this Operation. Use {@link #isComplete}.
83 * Read-only property tracking whether the Operation was successful or not. This starts as undefined and is set to true
84 * or false by the Proxy that is executing the Operation. It is also set to false by {@link #setException}. Use
85 * {@link #wasSuccessful} to query success status.
93 * Read-only property tracking the exception status of this Operation. Use {@link #hasException} and see {@link #getError}.
101 * The error object passed when {@link #setException} was called. This could be any object or primitive.
108 constructor: function(config) {
109 Ext.apply(this, config || {});
113 * Marks the Operation as started
115 setStarted: function() {
121 * Marks the Operation as completed
123 setCompleted: function() {
124 this.complete = true;
125 this.running = false;
129 * Marks the Operation as successful
131 setSuccessful: function() {
136 * Marks the Operation as having experienced an exception. Can be supplied with an option error message/object.
137 * @param {Mixed} error Optional error string/object
139 setException: function(error) {
140 this.exception = true;
141 this.success = false;
142 this.running = false;
147 * Returns true if this Operation encountered an exception (see also {@link #getError})
148 * @return {Boolean} True if there was an exception
150 hasException: function() {
151 return this.exception === true;
155 * Returns the error string or object that was set using {@link #setException}
156 * @return {Mixed} The error object
158 getError: function() {
163 * Returns an array of Ext.data.Model instances as set by the Proxy.
164 * @return {Array} Any loaded Records
166 getRecords: function() {
167 var resultSet = this.getResultSet();
169 return (resultSet === undefined ? this.records : resultSet.records);
173 * Returns the ResultSet object (if set by the Proxy). This object will contain the {@link Ext.data.Model model} instances
174 * as well as meta data such as number of instances fetched, number available etc
175 * @return {Ext.data.ResultSet} The ResultSet object
177 getResultSet: function() {
178 return this.resultSet;
182 * Returns true if the Operation has been started. Note that the Operation may have started AND completed,
183 * see {@link #isRunning} to test if the Operation is currently running.
184 * @return {Boolean} True if the Operation has started
186 isStarted: function() {
187 return this.started === true;
191 * Returns true if the Operation has been started but has not yet completed.
192 * @return {Boolean} True if the Operation is currently running
194 isRunning: function() {
195 return this.running === true;
199 * Returns true if the Operation has been completed
200 * @return {Boolean} True if the Operation is complete
202 isComplete: function() {
203 return this.complete === true;
207 * Returns true if the Operation has completed and was successful
208 * @return {Boolean} True if successful
210 wasSuccessful: function() {
211 return this.isComplete() && this.success === true;
216 * Associates this Operation with a Batch
217 * @param {Ext.data.Batch} batch The batch
219 setBatch: function(batch) {
224 * Checks whether this operation should cause writing to occur.
225 * @return {Boolean} Whether the operation should cause a write to occur.
227 allowWrite: function() {
228 return this.action != 'read';