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-ProgressBar-cfg-id'><span id='Ext-ProgressBar-cfg-textEl'><span id='Ext-ProgressBar-cfg-text'><span id='Ext-ProgressBar-cfg-value'><span id='Ext-ProgressBar'>/**
2 </span></span></span></span></span> * @class Ext.ProgressBar
3 * @extends Ext.Component
4 * <p>An updateable progress bar component. The progress bar supports two different modes: manual and automatic.</p>
5 * <p>In manual mode, you are responsible for showing, updating (via {@link #updateProgress}) and clearing the
6 * progress bar as needed from your own code. This method is most appropriate when you want to show progress
7 * throughout an operation that has predictable points of interest at which you can update the control.</p>
8 * <p>In automatic mode, you simply call {@link #wait} and let the progress bar run indefinitely, only clearing it
9 * once the operation is complete. You can optionally have the progress bar wait for a specific amount of time
10 * and then clear itself. Automatic mode is most appropriate for timed operations or asynchronous operations in
11 * which you have no need for indicating intermediate progress.</p>
12 * {@img Ext.ProgressBar/Ext.ProgressBar.png Ext.ProgressBar component}
14 var p = Ext.create('Ext.ProgressBar', {
15 renderTo: Ext.getBody(),
19 //Wait for 5 seconds, then update the status el (progress bar will auto-reset)
21 interval: 500, //bar will move fast!
27 p.updateText('Done!');
30 * @cfg {Float} value A floating point value between 0 and 1 (e.g., .5, defaults to 0)
31 * @cfg {String} text The progress bar text (defaults to '')
32 * @cfg {Mixed} textEl The element to render the progress text to (defaults to the progress
33 * bar's internal text element)
34 * @cfg {String} id The progress bar element's id (defaults to an auto-generated id)
37 Ext.define('Ext.ProgressBar', {
38 extend: 'Ext.Component',
39 alias: 'widget.progressbar',
43 'Ext.CompositeElement',
45 'Ext.layout.component.ProgressBar'
48 uses: ['Ext.fx.Anim'],
49 <span id='Ext-ProgressBar-cfg-baseCls'> /**
50 </span> * @cfg {String} baseCls
51 * The base CSS class to apply to the progress bar's wrapper element (defaults to 'x-progress')
53 baseCls: Ext.baseCSSPrefix + 'progress',
56 <span id='Ext-ProgressBar-cfg-animate'> /**
57 </span> * @cfg {Boolean} animate
58 * True to animate the progress bar during transitions (defaults to false)
62 <span id='Ext-ProgressBar-cfg-text'> /**
63 </span> * @cfg {String} text The text shown in the progress bar (defaults to '')
72 '<div class="{baseCls}-text {baseCls}-text-back">',
73 '<div>&#160;</div>',
75 '<div class="{baseCls}-bar">',
76 '<div class="{baseCls}-text">',
77 '<div>&#160;</div>',
82 componentLayout: 'progressbar',
85 initComponent: function() {
88 this.renderSelectors = Ext.apply(this.renderSelectors || {}, {
89 textTopEl: '.' + this.baseCls + '-text',
90 textBackEl: '.' + this.baseCls + '-text-back',
91 bar: '.' + this.baseCls + '-bar'
95 <span id='Ext-ProgressBar-event-update'> /**
96 </span> * @event update
97 * Fires after each update interval
98 * @param {Ext.ProgressBar} this
99 * @param {Number} The current progress value
100 * @param {String} The current progress text
106 afterRender : function() {
109 me.textEl = me.textEl ? Ext.get(me.textEl) : me.el.select('.' + me.baseCls + '-text');
111 this.callParent(arguments);
114 me.updateProgress(me.value, me.text);
117 me.updateText(me.text);
121 <span id='Ext-ProgressBar-method-updateProgress'> /**
122 </span> * Updates the progress bar value, and optionally its text. If the text argument is not specified,
123 * any existing text value will be unchanged. To blank out existing text, pass ''. Note that even
124 * if the progress bar value exceeds 1, it will never automatically reset -- you are responsible for
125 * determining when the progress is complete and calling {@link #reset} to clear and/or hide the control.
126 * @param {Float} value (optional) A floating point value between 0 and 1 (e.g., .5, defaults to 0)
127 * @param {String} text (optional) The string to display in the progress text element (defaults to '')
128 * @param {Boolean} animate (optional) Whether to animate the transition of the progress bar. If this value is
129 * not specified, the default for the class is used (default to false)
130 * @return {Ext.ProgressBar} this
132 updateProgress: function(value, text, animate) {
134 this.value = value || 0;
136 this.updateText(text);
138 if (this.rendered && !this.isDestroyed) {
139 newWidth = Math.floor(this.value * this.el.getWidth(true));
140 if (Ext.isForcedBorderBox) {
141 newWidth += this.bar.getBorderWidth("lr");
143 if (animate === true || (animate !== false && this.animate)) {
144 this.bar.stopAnimation();
145 this.bar.animate(Ext.apply({
147 width: newWidth + 'px'
151 this.bar.setWidth(newWidth);
154 this.fireEvent('update', this, this.value, text);
158 <span id='Ext-ProgressBar-method-updateText'> /**
159 </span> * Updates the progress bar text. If specified, textEl will be updated, otherwise the progress
160 * bar itself will display the updated text.
161 * @param {String} text (optional) The string to display in the progress text element (defaults to '')
162 * @return {Ext.ProgressBar} this
164 updateText: function(text) {
167 this.textEl.update(this.text);
172 applyText : function(text) {
173 this.updateText(text);
176 <span id='Ext-ProgressBar-method-wait'> /**
177 </span> * Initiates an auto-updating progress bar. A duration can be specified, in which case the progress
178 * bar will automatically reset after a fixed amount of time and optionally call a callback function
179 * if specified. If no duration is passed in, then the progress bar will run indefinitely and must
180 * be manually cleared by calling {@link #reset}. The wait method accepts a config object with
181 * the following properties:
183 Property Type Description
184 ---------- ------------ ----------------------------------------------------------------------
185 duration Number The length of time in milliseconds that the progress bar should
186 run before resetting itself (defaults to undefined, in which case it
187 will run indefinitely until reset is called)
188 interval Number The length of time in milliseconds between each progress update
189 (defaults to 1000 ms)
190 animate Boolean Whether to animate the transition of the progress bar. If this value is
191 not specified, the default for the class is used.
192 increment Number The number of progress update segments to display within the progress
193 bar (defaults to 10). If the bar reaches the end and is still
194 updating, it will automatically wrap back to the beginning.
195 text String Optional text to display in the progress bar element (defaults to '').
196 fn Function A callback function to execute after the progress bar finishes auto-
197 updating. The function will be called with no arguments. This function
198 will be ignored if duration is not specified since in that case the
199 progress bar can only be stopped programmatically, so any required function
200 should be called by the same code after it resets the progress bar.
201 scope Object The scope that is passed to the callback function (only applies when
202 duration and fn are both passed).
206 * <pre><code>
207 var p = new Ext.ProgressBar({
211 //Wait for 5 seconds, then update the status el (progress bar will auto-reset)
212 var p = Ext.create('Ext.ProgressBar', {
213 renderTo: Ext.getBody(),
217 //Wait for 5 seconds, then update the status el (progress bar will auto-reset)
219 interval: 500, //bar will move fast!
225 p.updateText('Done!');
229 //Or update indefinitely until some async action completes, then reset manually
231 myAction.on('complete', function(){
233 p.updateText('Done!');
235 </code></pre>
236 * @param {Object} config (optional) Configuration options
237 * @return {Ext.ProgressBar} this
240 if (!this.waitTimer) {
243 this.updateText(o.text);
244 this.waitTimer = Ext.TaskManager.start({
246 var inc = o.increment || 10;
248 this.updateProgress(((((i+inc)%inc)+1)*(100/inc))*0.01, null, o.animate);
250 interval: o.interval || 1000,
251 duration: o.duration,
254 o.fn.apply(o.scope || this);
264 <span id='Ext-ProgressBar-method-isWaiting'> /**
265 </span> * Returns true if the progress bar is currently in a {@link #wait} operation
266 * @return {Boolean} True if waiting, else false
268 isWaiting: function(){
269 return this.waitTimer !== null;
272 <span id='Ext-ProgressBar-method-reset'> /**
273 </span> * Resets the progress bar value to 0 and text to empty string. If hide = true, the progress
274 * bar will also be hidden (using the {@link #hideMode} property internally).
275 * @param {Boolean} hide (optional) True to hide the progress bar (defaults to false)
276 * @return {Ext.ProgressBar} this
278 reset: function(hide){
279 this.updateProgress(0);
288 clearTimer: function(){
289 if (this.waitTimer) {
290 this.waitTimer.onStop = null; //prevent recursion
291 Ext.TaskManager.stop(this.waitTimer);
292 this.waitTimer = null;
296 onDestroy: function(){
299 if (this.textEl.isComposite) {
302 Ext.destroyMembers(this, 'textEl', 'progressBar', 'textTopEl');
307 </pre></pre></body></html>