1 <!DOCTYPE html><html><head><title>Sencha Documentation Project</title><link rel="stylesheet" href="../reset.css" type="text/css"><link rel="stylesheet" href="../prettify.css" type="text/css"><link rel="stylesheet" href="../prettify_sa.css" type="text/css"><script type="text/javascript" src="../prettify.js"></script></head><body onload="prettyPrint()"><pre class="prettyprint"><pre><span id='Ext-data.Batch-method-constructor'><span id='Ext-data.Batch'>/**
2 </span></span> * @author Ed Spencer
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'
19 <span id='Ext-data.Batch-property-autoStart'> /**
20 </span> * True to immediately start processing the batch as soon as it is constructed (defaults to false)
26 <span id='Ext-data.Batch-property-current'> /**
27 </span> * The index of the current operation being executed
33 <span id='Ext-data.Batch-property-total'> /**
34 </span> * The total number of operations in this batch. Read only
40 <span id='Ext-data.Batch-property-isRunning'> /**
41 </span> * True if the batch is currently running
47 <span id='Ext-data.Batch-property-isComplete'> /**
48 </span> * True if this batch has been executed completely
49 * @property isComplete
54 <span id='Ext-data.Batch-property-hasException'> /**
55 </span> * True if this batch has encountered an exception. This is cleared at the start of each operation
56 * @property hasException
61 <span id='Ext-data.Batch-property-pauseOnException'> /**
62 </span> * 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) {
72 <span id='Ext-data.Batch-event-complete'> /**
73 </span> * @event complete
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
80 <span id='Ext-data.Batch-event-exception'> /**
81 </span> * @event exception
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
88 <span id='Ext-data.Batch-event-operationcomplete'> /**
89 </span> * @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);
99 <span id='Ext-data.Batch-property-operations'> /**
100 </span> * Ordered array of operations that will be executed by this batch
101 * @property operations
107 <span id='Ext-data.Batch-method-add'> /**
108 </span> * 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);
119 <span id='Ext-data.Batch-method-start'> /**
120 </span> * 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();
130 <span id='Ext-data.Batch-method-runNextOperation'> /**
132 * Runs the next operation, relative to this.current.
134 runNextOperation: function() {
135 this.runOperation(this.current + 1);
138 <span id='Ext-data.Batch-method-pause'> /**
139 </span> * Pauses execution of the batch, but does not cancel the current operation
142 this.isRunning = false;
145 <span id='Ext-data.Batch-method-runOperation'> /**
146 </span> * 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);
185 });</pre></pre></body></html>