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'>/**
19 </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 Ext.define('Ext.data.Batch', {
31 observable: 'Ext.util.Observable'
34 <span id='Ext-data-Batch-property-autoStart'> /**
35 </span> * True to immediately start processing the batch as soon as it is constructed (defaults to false)
41 <span id='Ext-data-Batch-property-current'> /**
42 </span> * The index of the current operation being executed
48 <span id='Ext-data-Batch-property-total'> /**
49 </span> * The total number of operations in this batch. Read only
55 <span id='Ext-data-Batch-property-isRunning'> /**
56 </span> * True if the batch is currently running
62 <span id='Ext-data-Batch-property-isComplete'> /**
63 </span> * True if this batch has been executed completely
64 * @property isComplete
69 <span id='Ext-data-Batch-property-hasException'> /**
70 </span> * True if this batch has encountered an exception. This is cleared at the start of each operation
71 * @property hasException
76 <span id='Ext-data-Batch-property-pauseOnException'> /**
77 </span> * True to automatically pause the execution of the batch if any operation encounters an exception (defaults to true)
78 * @property pauseOnException
81 pauseOnException: true,
83 <span id='Ext-data-Batch-method-constructor'> /**
84 </span> * Creates new Batch object.
85 * @param {Object} config (optional) Config object
87 constructor: function(config) {
91 <span id='Ext-data-Batch-event-complete'> /**
92 </span> * @event complete
93 * Fired when all operations of this batch have been completed
94 * @param {Ext.data.Batch} batch The batch object
95 * @param {Object} operation The last operation that was executed
99 <span id='Ext-data-Batch-event-exception'> /**
100 </span> * @event exception
101 * Fired when a operation encountered an exception
102 * @param {Ext.data.Batch} batch The batch object
103 * @param {Object} operation The operation that encountered the exception
107 <span id='Ext-data-Batch-event-operationcomplete'> /**
108 </span> * @event operationcomplete
109 * Fired when each operation of the batch completes
110 * @param {Ext.data.Batch} batch The batch object
111 * @param {Object} operation The operation that just completed
116 me.mixins.observable.constructor.call(me, config);
118 <span id='Ext-data-Batch-property-operations'> /**
119 </span> * Ordered array of operations that will be executed by this batch
120 * @property operations
126 <span id='Ext-data-Batch-method-add'> /**
127 </span> * Adds a new operation to this batch
128 * @param {Object} operation The {@link Ext.data.Operation Operation} object
130 add: function(operation) {
133 operation.setBatch(this);
135 this.operations.push(operation);
138 <span id='Ext-data-Batch-method-start'> /**
139 </span> * Kicks off the execution of the batch, continuing from the next operation if the previous
140 * operation encountered an exception, or if execution was paused
143 this.hasException = false;
144 this.isRunning = true;
146 this.runNextOperation();
149 <span id='Ext-data-Batch-method-runNextOperation'> /**
151 * Runs the next operation, relative to this.current.
153 runNextOperation: function() {
154 this.runOperation(this.current + 1);
157 <span id='Ext-data-Batch-method-pause'> /**
158 </span> * Pauses execution of the batch, but does not cancel the current operation
161 this.isRunning = false;
164 <span id='Ext-data-Batch-method-runOperation'> /**
165 </span> * Executes a operation by its numeric index
166 * @param {Number} index The operation index to run
168 runOperation: function(index) {
170 operations = me.operations,
171 operation = operations[index],
174 if (operation === undefined) {
175 me.isRunning = false;
176 me.isComplete = true;
177 me.fireEvent('complete', me, operations[operations.length - 1]);
181 onProxyReturn = function(operation) {
182 var hasException = operation.hasException();
185 me.hasException = true;
186 me.fireEvent('exception', me, operation);
188 me.fireEvent('operationcomplete', me, operation);
191 if (hasException && me.pauseOnException) {
194 operation.setCompleted();
195 me.runNextOperation();
199 operation.setStarted();
201 me.proxy[operation.action](operation, onProxyReturn, me);