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-Batch-method-constructor'><span id='Ext-data-Batch'>/**
19 </span></span> * @author Ed Spencer
20 * @class Ext.data.Batch
22 * <p>Provides a mechanism to run one or more {@link Ext.data.Operation operations} in a given order. Fires the 'operationcomplete' event
23 * after the completion of each Operation, and the 'complete' event when all Operations have been successfully executed. Fires an 'exception'
24 * event if any of the Operations encounter an exception.</p>
26 * <p>Usually these are only used internally by {@link Ext.data.proxy.Proxy} classes</p>
29 * @param {Object} config Optional config object
31 Ext.define('Ext.data.Batch', {
33 observable: 'Ext.util.Observable'
36 <span id='Ext-data-Batch-property-autoStart'> /**
37 </span> * True to immediately start processing the batch as soon as it is constructed (defaults to false)
43 <span id='Ext-data-Batch-property-current'> /**
44 </span> * The index of the current operation being executed
50 <span id='Ext-data-Batch-property-total'> /**
51 </span> * The total number of operations in this batch. Read only
57 <span id='Ext-data-Batch-property-isRunning'> /**
58 </span> * True if the batch is currently running
64 <span id='Ext-data-Batch-property-isComplete'> /**
65 </span> * True if this batch has been executed completely
66 * @property isComplete
71 <span id='Ext-data-Batch-property-hasException'> /**
72 </span> * True if this batch has encountered an exception. This is cleared at the start of each operation
73 * @property hasException
78 <span id='Ext-data-Batch-property-pauseOnException'> /**
79 </span> * True to automatically pause the execution of the batch if any operation encounters an exception (defaults to true)
80 * @property pauseOnException
83 pauseOnException: true,
85 constructor: function(config) {
89 <span id='Ext-data-Batch-event-complete'> /**
90 </span> * @event complete
91 * Fired when all operations of this batch have been completed
92 * @param {Ext.data.Batch} batch The batch object
93 * @param {Object} operation The last operation that was executed
97 <span id='Ext-data-Batch-event-exception'> /**
98 </span> * @event exception
99 * Fired when a operation encountered an exception
100 * @param {Ext.data.Batch} batch The batch object
101 * @param {Object} operation The operation that encountered the exception
105 <span id='Ext-data-Batch-event-operationcomplete'> /**
106 </span> * @event operationcomplete
107 * Fired when each operation of the batch completes
108 * @param {Ext.data.Batch} batch The batch object
109 * @param {Object} operation The operation that just completed
114 me.mixins.observable.constructor.call(me, config);
116 <span id='Ext-data-Batch-property-operations'> /**
117 </span> * Ordered array of operations that will be executed by this batch
118 * @property operations
124 <span id='Ext-data-Batch-method-add'> /**
125 </span> * Adds a new operation to this batch
126 * @param {Object} operation The {@link Ext.data.Operation Operation} object
128 add: function(operation) {
131 operation.setBatch(this);
133 this.operations.push(operation);
136 <span id='Ext-data-Batch-method-start'> /**
137 </span> * Kicks off the execution of the batch, continuing from the next operation if the previous
138 * operation encountered an exception, or if execution was paused
141 this.hasException = false;
142 this.isRunning = true;
144 this.runNextOperation();
147 <span id='Ext-data-Batch-method-runNextOperation'> /**
149 * Runs the next operation, relative to this.current.
151 runNextOperation: function() {
152 this.runOperation(this.current + 1);
155 <span id='Ext-data-Batch-method-pause'> /**
156 </span> * Pauses execution of the batch, but does not cancel the current operation
159 this.isRunning = false;
162 <span id='Ext-data-Batch-method-runOperation'> /**
163 </span> * Executes a operation by its numeric index
164 * @param {Number} index The operation index to run
166 runOperation: function(index) {
168 operations = me.operations,
169 operation = operations[index],
172 if (operation === undefined) {
173 me.isRunning = false;
174 me.isComplete = true;
175 me.fireEvent('complete', me, operations[operations.length - 1]);
179 onProxyReturn = function(operation) {
180 var hasException = operation.hasException();
183 me.hasException = true;
184 me.fireEvent('exception', me, operation);
186 me.fireEvent('operationcomplete', me, operation);
189 if (hasException && me.pauseOnException) {
192 operation.setCompleted();
193 me.runNextOperation();
197 operation.setStarted();
199 me.proxy[operation.action](operation, onProxyReturn, me);