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'>/**
19 </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 Ext.define('Ext.data.Operation', {
31 <span id='Ext-data-Operation-cfg-synchronous'> /**
32 </span> * @cfg {Boolean} synchronous True if this Operation is to be executed synchronously (defaults to true). This
33 * property is inspected by a {@link Ext.data.Batch Batch} to see if a series of Operations can be executed in
38 <span id='Ext-data-Operation-cfg-action'> /**
39 </span> * @cfg {String} action The action being performed by this Operation. Should be one of 'create', 'read', 'update' or 'destroy'
43 <span id='Ext-data-Operation-cfg-filters'> /**
44 </span> * @cfg {Array} filters Optional array of filter objects. Only applies to 'read' actions.
48 <span id='Ext-data-Operation-cfg-sorters'> /**
49 </span> * @cfg {Array} sorters Optional array of sorter objects. Only applies to 'read' actions.
53 <span id='Ext-data-Operation-cfg-group'> /**
54 </span> * @cfg {Object} group Optional grouping configuration. Only applies to 'read' actions where grouping is desired.
58 <span id='Ext-data-Operation-cfg-start'> /**
59 </span> * @cfg {Number} start The start index (offset), used in paging when running a 'read' action.
63 <span id='Ext-data-Operation-cfg-limit'> /**
64 </span> * @cfg {Number} limit The number of records to load. Used on 'read' actions when paging is being used.
68 <span id='Ext-data-Operation-cfg-batch'> /**
69 </span> * @cfg {Ext.data.Batch} batch The batch that this Operation is a part of (optional)
73 <span id='Ext-data-Operation-property-started'> /**
74 </span> * Read-only property tracking the start status of this Operation. Use {@link #isStarted}.
81 <span id='Ext-data-Operation-property-running'> /**
82 </span> * Read-only property tracking the run status of this Operation. Use {@link #isRunning}.
89 <span id='Ext-data-Operation-property-complete'> /**
90 </span> * Read-only property tracking the completion status of this Operation. Use {@link #isComplete}.
97 <span id='Ext-data-Operation-property-success'> /**
98 </span> * Read-only property tracking whether the Operation was successful or not. This starts as undefined and is set to true
99 * or false by the Proxy that is executing the Operation. It is also set to false by {@link #setException}. Use
100 * {@link #wasSuccessful} to query success status.
107 <span id='Ext-data-Operation-property-exception'> /**
108 </span> * Read-only property tracking the exception status of this Operation. Use {@link #hasException} and see {@link #getError}.
109 * @property exception
115 <span id='Ext-data-Operation-property-error'> /**
116 </span> * The error object passed when {@link #setException} was called. This could be any object or primitive.
123 <span id='Ext-data-Operation-method-constructor'> /**
124 </span> * Creates new Operation object.
125 * @param {Object} config (optional) Config object.
127 constructor: function(config) {
128 Ext.apply(this, config || {});
131 <span id='Ext-data-Operation-method-setStarted'> /**
132 </span> * Marks the Operation as started
134 setStarted: function() {
139 <span id='Ext-data-Operation-method-setCompleted'> /**
140 </span> * Marks the Operation as completed
142 setCompleted: function() {
143 this.complete = true;
144 this.running = false;
147 <span id='Ext-data-Operation-method-setSuccessful'> /**
148 </span> * Marks the Operation as successful
150 setSuccessful: function() {
154 <span id='Ext-data-Operation-method-setException'> /**
155 </span> * Marks the Operation as having experienced an exception. Can be supplied with an option error message/object.
156 * @param {Mixed} error Optional error string/object
158 setException: function(error) {
159 this.exception = true;
160 this.success = false;
161 this.running = false;
165 <span id='Ext-data-Operation-method-hasException'> /**
166 </span> * Returns true if this Operation encountered an exception (see also {@link #getError})
167 * @return {Boolean} True if there was an exception
169 hasException: function() {
170 return this.exception === true;
173 <span id='Ext-data-Operation-method-getError'> /**
174 </span> * Returns the error string or object that was set using {@link #setException}
175 * @return {Mixed} The error object
177 getError: function() {
181 <span id='Ext-data-Operation-method-getRecords'> /**
182 </span> * Returns an array of Ext.data.Model instances as set by the Proxy.
183 * @return {Array} Any loaded Records
185 getRecords: function() {
186 var resultSet = this.getResultSet();
188 return (resultSet === undefined ? this.records : resultSet.records);
191 <span id='Ext-data-Operation-method-getResultSet'> /**
192 </span> * Returns the ResultSet object (if set by the Proxy). This object will contain the {@link Ext.data.Model model} instances
193 * as well as meta data such as number of instances fetched, number available etc
194 * @return {Ext.data.ResultSet} The ResultSet object
196 getResultSet: function() {
197 return this.resultSet;
200 <span id='Ext-data-Operation-method-isStarted'> /**
201 </span> * Returns true if the Operation has been started. Note that the Operation may have started AND completed,
202 * see {@link #isRunning} to test if the Operation is currently running.
203 * @return {Boolean} True if the Operation has started
205 isStarted: function() {
206 return this.started === true;
209 <span id='Ext-data-Operation-method-isRunning'> /**
210 </span> * Returns true if the Operation has been started but has not yet completed.
211 * @return {Boolean} True if the Operation is currently running
213 isRunning: function() {
214 return this.running === true;
217 <span id='Ext-data-Operation-method-isComplete'> /**
218 </span> * Returns true if the Operation has been completed
219 * @return {Boolean} True if the Operation is complete
221 isComplete: function() {
222 return this.complete === true;
225 <span id='Ext-data-Operation-method-wasSuccessful'> /**
226 </span> * Returns true if the Operation has completed and was successful
227 * @return {Boolean} True if successful
229 wasSuccessful: function() {
230 return this.isComplete() && this.success === true;
233 <span id='Ext-data-Operation-method-setBatch'> /**
235 * Associates this Operation with a Batch
236 * @param {Ext.data.Batch} batch The batch
238 setBatch: function(batch) {
242 <span id='Ext-data-Operation-method-allowWrite'> /**
243 </span> * Checks whether this operation should cause writing to occur.
244 * @return {Boolean} Whether the operation should cause a write to occur.
246 allowWrite: function() {
247 return this.action != 'read';