3 This file is part of Ext JS 4
5 Copyright (c) 2011 Sencha Inc
7 Contact: http://www.sencha.com/contact
9 GNU General Public License Usage
10 This file may be used under the terms of the GNU General Public License version 3.0 as published by the Free Software Foundation and appearing in the file LICENSE included in the packaging of this file. Please review the following information to ensure the GNU General Public License version 3.0 requirements will be met: http://www.gnu.org/copyleft/gpl.html.
12 If you are unsure which license is appropriate for your use, please contact the sales department at http://www.sencha.com/contact.
17 * @class Ext.data.Operation
20 * <p>Represents a single read or write operation performed by a {@link Ext.data.proxy.Proxy Proxy}.
21 * Operation objects are used to enable communication between Stores and Proxies. Application
22 * developers should rarely need to interact with Operation objects directly.</p>
24 * <p>Several Operations can be batched together in a {@link Ext.data.Batch batch}.</p>
27 Ext.define('Ext.data.Operation', {
29 * @cfg {Boolean} synchronous True if this Operation is to be executed synchronously (defaults to true). This
30 * property is inspected by a {@link Ext.data.Batch Batch} to see if a series of Operations can be executed in
36 * @cfg {String} action The action being performed by this Operation. Should be one of 'create', 'read', 'update' or 'destroy'
41 * @cfg {Array} filters Optional array of filter objects. Only applies to 'read' actions.
46 * @cfg {Array} sorters Optional array of sorter objects. Only applies to 'read' actions.
51 * @cfg {Object} group Optional grouping configuration. Only applies to 'read' actions where grouping is desired.
56 * @cfg {Number} start The start index (offset), used in paging when running a 'read' action.
61 * @cfg {Number} limit The number of records to load. Used on 'read' actions when paging is being used.
66 * @cfg {Ext.data.Batch} batch The batch that this Operation is a part of (optional)
71 * Read-only property tracking the start status of this Operation. Use {@link #isStarted}.
79 * Read-only property tracking the run status of this Operation. Use {@link #isRunning}.
87 * Read-only property tracking the completion status of this Operation. Use {@link #isComplete}.
95 * Read-only property tracking whether the Operation was successful or not. This starts as undefined and is set to true
96 * or false by the Proxy that is executing the Operation. It is also set to false by {@link #setException}. Use
97 * {@link #wasSuccessful} to query success status.
105 * Read-only property tracking the exception status of this Operation. Use {@link #hasException} and see {@link #getError}.
106 * @property exception
113 * The error object passed when {@link #setException} was called. This could be any object or primitive.
121 * Creates new Operation object.
122 * @param {Object} config (optional) Config object.
124 constructor: function(config) {
125 Ext.apply(this, config || {});
129 * Marks the Operation as started
131 setStarted: function() {
137 * Marks the Operation as completed
139 setCompleted: function() {
140 this.complete = true;
141 this.running = false;
145 * Marks the Operation as successful
147 setSuccessful: function() {
152 * Marks the Operation as having experienced an exception. Can be supplied with an option error message/object.
153 * @param {Mixed} error Optional error string/object
155 setException: function(error) {
156 this.exception = true;
157 this.success = false;
158 this.running = false;
163 * Returns true if this Operation encountered an exception (see also {@link #getError})
164 * @return {Boolean} True if there was an exception
166 hasException: function() {
167 return this.exception === true;
171 * Returns the error string or object that was set using {@link #setException}
172 * @return {Mixed} The error object
174 getError: function() {
179 * Returns an array of Ext.data.Model instances as set by the Proxy.
180 * @return {Array} Any loaded Records
182 getRecords: function() {
183 var resultSet = this.getResultSet();
185 return (resultSet === undefined ? this.records : resultSet.records);
189 * Returns the ResultSet object (if set by the Proxy). This object will contain the {@link Ext.data.Model model} instances
190 * as well as meta data such as number of instances fetched, number available etc
191 * @return {Ext.data.ResultSet} The ResultSet object
193 getResultSet: function() {
194 return this.resultSet;
198 * Returns true if the Operation has been started. Note that the Operation may have started AND completed,
199 * see {@link #isRunning} to test if the Operation is currently running.
200 * @return {Boolean} True if the Operation has started
202 isStarted: function() {
203 return this.started === true;
207 * Returns true if the Operation has been started but has not yet completed.
208 * @return {Boolean} True if the Operation is currently running
210 isRunning: function() {
211 return this.running === true;
215 * Returns true if the Operation has been completed
216 * @return {Boolean} True if the Operation is complete
218 isComplete: function() {
219 return this.complete === true;
223 * Returns true if the Operation has completed and was successful
224 * @return {Boolean} True if successful
226 wasSuccessful: function() {
227 return this.isComplete() && this.success === true;
232 * Associates this Operation with a Batch
233 * @param {Ext.data.Batch} batch The batch
235 setBatch: function(batch) {
240 * Checks whether this operation should cause writing to occur.
241 * @return {Boolean} Whether the operation should cause a write to occur.
243 allowWrite: function() {
244 return this.action != 'read';