3 * @class Ext.data.Batch
5 * <p>Provides a mechanism to run one or more {@link Ext.data.Operation operations} in a given order. Fires the 'operationcomplete' event
6 * after the completion of each Operation, and the 'complete' event when all Operations have been successfully executed. Fires an 'exception'
7 * event if any of the Operations encounter an exception.</p>
9 * <p>Usually these are only used internally by {@link Ext.data.proxy.Proxy} classes</p>
12 * @param {Object} config Optional config object
14 Ext.define('Ext.data.Batch', {
16 observable: 'Ext.util.Observable'
20 * True to immediately start processing the batch as soon as it is constructed (defaults to false)
27 * The index of the current operation being executed
34 * The total number of operations in this batch. Read only
41 * True if the batch is currently running
48 * True if this batch has been executed completely
49 * @property isComplete
55 * True if this batch has encountered an exception. This is cleared at the start of each operation
56 * @property hasException
62 * True to automatically pause the execution of the batch if any operation encounters an exception (defaults to true)
63 * @property pauseOnException
66 pauseOnException: true,
68 constructor: function(config) {
74 * Fired when all operations of this batch have been completed
75 * @param {Ext.data.Batch} batch The batch object
76 * @param {Object} operation The last operation that was executed
82 * Fired when a operation encountered an exception
83 * @param {Ext.data.Batch} batch The batch object
84 * @param {Object} operation The operation that encountered the exception
89 * @event operationcomplete
90 * Fired when each operation of the batch completes
91 * @param {Ext.data.Batch} batch The batch object
92 * @param {Object} operation The operation that just completed
97 me.mixins.observable.constructor.call(me, config);
100 * Ordered array of operations that will be executed by this batch
101 * @property operations
108 * Adds a new operation to this batch
109 * @param {Object} operation The {@link Ext.data.Operation Operation} object
111 add: function(operation) {
114 operation.setBatch(this);
116 this.operations.push(operation);
120 * Kicks off the execution of the batch, continuing from the next operation if the previous
121 * operation encountered an exception, or if execution was paused
124 this.hasException = false;
125 this.isRunning = true;
127 this.runNextOperation();
132 * Runs the next operation, relative to this.current.
134 runNextOperation: function() {
135 this.runOperation(this.current + 1);
139 * Pauses execution of the batch, but does not cancel the current operation
142 this.isRunning = false;
146 * Executes a operation by its numeric index
147 * @param {Number} index The operation index to run
149 runOperation: function(index) {
151 operations = me.operations,
152 operation = operations[index],
155 if (operation === undefined) {
156 me.isRunning = false;
157 me.isComplete = true;
158 me.fireEvent('complete', me, operations[operations.length - 1]);
162 onProxyReturn = function(operation) {
163 var hasException = operation.hasException();
166 me.hasException = true;
167 me.fireEvent('exception', me, operation);
169 me.fireEvent('operationcomplete', me, operation);
172 if (hasException && me.pauseOnException) {
175 operation.setCompleted();
176 me.runNextOperation();
180 operation.setStarted();
182 me.proxy[operation.action](operation, onProxyReturn, me);