2 * Ext JS Library 2.2.1
\r
3 * Copyright(c) 2006-2009, Ext JS, LLC.
\r
4 * licensing@extjs.com
\r
6 * http://extjs.com/license
\r
10 * @class Ext.ProgressBar
\r
11 * @extends Ext.BoxComponent
\r
12 * <p>An updateable progress bar component. The progress bar supports two different modes: manual and automatic.</p>
\r
13 * <p>In manual mode, you are responsible for showing, updating (via {@link #updateProgress}) and clearing the
\r
14 * progress bar as needed from your own code. This method is most appropriate when you want to show progress
\r
15 * throughout an operation that has predictable points of interest at which you can update the control.</p>
\r
16 * <p>In automatic mode, you simply call {@link #wait} and let the progress bar run indefinitely, only clearing it
\r
17 * once the operation is complete. You can optionally have the progress bar wait for a specific amount of time
\r
18 * and then clear itself. Automatic mode is most appropriate for timed operations or asynchronous operations in
\r
19 * which you have no need for indicating intermediate progress.</p>
\r
20 * @cfg {Float} value A floating point value between 0 and 1 (e.g., .5, defaults to 0)
\r
21 * @cfg {String} text The progress bar text (defaults to '')
\r
22 * @cfg {Mixed} textEl The element to render the progress text to (defaults to the progress
\r
23 * bar's internal text element)
\r
24 * @cfg {String} id The progress bar element's id (defaults to an auto-generated id)
\r
26 Ext.ProgressBar = Ext.extend(Ext.BoxComponent, {
\r
28 * @cfg {String} baseCls
\r
29 * The base CSS class to apply to the progress bar's wrapper element (defaults to 'x-progress')
\r
31 baseCls : 'x-progress',
\r
34 * @cfg {Boolean} animate
\r
35 * True to animate the progress bar during transitions (defaults to false)
\r
43 initComponent : function(){
\r
44 Ext.ProgressBar.superclass.initComponent.call(this);
\r
48 * Fires after each update interval
\r
49 * @param {Ext.ProgressBar} this
\r
50 * @param {Number} The current progress value
\r
51 * @param {String} The current progress text
\r
58 onRender : function(ct, position){
\r
59 Ext.ProgressBar.superclass.onRender.call(this, ct, position);
\r
61 var tpl = new Ext.Template(
\r
62 '<div class="{cls}-wrap">',
\r
63 '<div class="{cls}-inner">',
\r
64 '<div class="{cls}-bar">',
\r
65 '<div class="{cls}-text">',
\r
66 '<div> </div>',
\r
69 '<div class="{cls}-text {cls}-text-back">',
\r
70 '<div> </div>',
\r
77 this.el = tpl.insertBefore(position, {cls: this.baseCls}, true);
\r
79 this.el = tpl.append(ct, {cls: this.baseCls}, true);
\r
82 this.el.dom.id = this.id;
\r
84 var inner = this.el.dom.firstChild;
\r
85 this.progressBar = Ext.get(inner.firstChild);
\r
88 //use an external text el
\r
89 this.textEl = Ext.get(this.textEl);
\r
90 delete this.textTopEl;
\r
92 //setup our internal layered text els
\r
93 this.textTopEl = Ext.get(this.progressBar.dom.firstChild);
\r
94 var textBackEl = Ext.get(inner.childNodes[1]);
\r
95 this.textTopEl.setStyle("z-index", 99).addClass('x-hidden');
\r
96 this.textEl = new Ext.CompositeElement([this.textTopEl.dom.firstChild, textBackEl.dom.firstChild]);
\r
97 this.textEl.setWidth(inner.offsetWidth);
\r
99 this.progressBar.setHeight(inner.offsetHeight);
\r
103 afterRender : function(){
\r
104 Ext.ProgressBar.superclass.afterRender.call(this);
\r
106 this.updateProgress(this.value, this.text);
\r
108 this.updateText(this.text);
\r
113 * Updates the progress bar value, and optionally its text. If the text argument is not specified,
\r
114 * any existing text value will be unchanged. To blank out existing text, pass ''. Note that even
\r
115 * if the progress bar value exceeds 1, it will never automatically reset -- you are responsible for
\r
116 * determining when the progress is complete and calling {@link #reset} to clear and/or hide the control.
\r
117 * @param {Float} value (optional) A floating point value between 0 and 1 (e.g., .5, defaults to 0)
\r
118 * @param {String} text (optional) The string to display in the progress text element (defaults to '')
\r
119 * @param {Boolean} animate (optional) Whether to animate the transition of the progress bar. If this value is
\r
120 * not specified, the default for the class is used (default to false)
\r
121 * @return {Ext.ProgressBar} this
\r
123 updateProgress : function(value, text, animate){
\r
124 this.value = value || 0;
\r
126 this.updateText(text);
\r
129 var w = Math.floor(value*this.el.dom.firstChild.offsetWidth);
\r
130 this.progressBar.setWidth(w, animate === true || (animate !== false && this.animate));
\r
131 if(this.textTopEl){
\r
132 //textTopEl should be the same width as the bar so overflow will clip as the bar moves
\r
133 this.textTopEl.removeClass('x-hidden').setWidth(w);
\r
136 this.fireEvent('update', this, value, text);
\r
141 * Initiates an auto-updating progress bar. A duration can be specified, in which case the progress
\r
142 * bar will automatically reset after a fixed amount of time and optionally call a callback function
\r
143 * if specified. If no duration is passed in, then the progress bar will run indefinitely and must
\r
144 * be manually cleared by calling {@link #reset}. The wait method accepts a config object with
\r
145 * the following properties:
\r
147 Property Type Description
\r
148 ---------- ------------ ----------------------------------------------------------------------
\r
149 duration Number The length of time in milliseconds that the progress bar should
\r
150 run before resetting itself (defaults to undefined, in which case it
\r
151 will run indefinitely until reset is called)
\r
152 interval Number The length of time in milliseconds between each progress update
\r
153 (defaults to 1000 ms)
\r
154 animate Boolean Whether to animate the transition of the progress bar. If this value is
\r
155 not specified, the default for the class is used.
\r
156 increment Number The number of progress update segments to display within the progress
\r
157 bar (defaults to 10). If the bar reaches the end and is still
\r
158 updating, it will automatically wrap back to the beginning.
\r
159 text String Optional text to display in the progress bar element (defaults to '').
\r
160 fn Function A callback function to execute after the progress bar finishes auto-
\r
161 updating. The function will be called with no arguments. This function
\r
162 will be ignored if duration is not specified since in that case the
\r
163 progress bar can only be stopped programmatically, so any required function
\r
164 should be called by the same code after it resets the progress bar.
\r
165 scope Object The scope that is passed to the callback function (only applies when
\r
166 duration and fn are both passed).
\r
171 var p = new Ext.ProgressBar({
\r
175 //Wait for 5 seconds, then update the status el (progress bar will auto-reset)
\r
177 interval: 100, //bar will move fast!
\r
180 text: 'Updating...',
\r
183 Ext.fly('status').update('Done!');
\r
187 //Or update indefinitely until some async action completes, then reset manually
\r
189 myAction.on('complete', function(){
\r
191 Ext.fly('status').update('Done!');
\r
194 * @param {Object} config (optional) Configuration options
\r
195 * @return {Ext.ProgressBar} this
\r
197 wait : function(o){
\r
198 if(!this.waitTimer){
\r
201 this.updateText(o.text);
\r
202 this.waitTimer = Ext.TaskMgr.start({
\r
204 var inc = o.increment || 10;
\r
205 this.updateProgress(((((i+inc)%inc)+1)*(100/inc))*.01, null, o.animate);
\r
207 interval: o.interval || 1000,
\r
208 duration: o.duration,
\r
209 onStop: function(){
\r
211 o.fn.apply(o.scope || this);
\r
222 * Returns true if the progress bar is currently in a {@link #wait} operation
\r
223 * @return {Boolean} True if waiting, else false
\r
225 isWaiting : function(){
\r
226 return this.waitTimer != null;
\r
230 * Updates the progress bar text. If specified, textEl will be updated, otherwise the progress
\r
231 * bar itself will display the updated text.
\r
232 * @param {String} text (optional) The string to display in the progress text element (defaults to '')
\r
233 * @return {Ext.ProgressBar} this
\r
235 updateText : function(text){
\r
236 this.text = text || ' ';
\r
238 this.textEl.update(this.text);
\r
244 * Synchronizes the inner bar width to the proper proportion of the total componet width based
\r
245 * on the current progress {@link #value}. This will be called automatically when the ProgressBar
\r
246 * is resized by a layout, but if it is rendered auto width, this method can be called from
\r
247 * another resize handler to sync the ProgressBar if necessary.
\r
249 syncProgressBar : function(){
\r
251 this.updateProgress(this.value, this.text);
\r
257 * Sets the size of the progress bar.
\r
258 * @param {Number} width The new width in pixels
\r
259 * @param {Number} height The new height in pixels
\r
260 * @return {Ext.ProgressBar} this
\r
262 setSize : function(w, h){
\r
263 Ext.ProgressBar.superclass.setSize.call(this, w, h);
\r
264 if(this.textTopEl){
\r
265 var inner = this.el.dom.firstChild;
\r
266 this.textEl.setSize(inner.offsetWidth, inner.offsetHeight);
\r
268 this.syncProgressBar();
\r
273 * Resets the progress bar value to 0 and text to empty string. If hide = true, the progress
\r
274 * bar will also be hidden (using the {@link #hideMode} property internally).
\r
275 * @param {Boolean} hide (optional) True to hide the progress bar (defaults to false)
\r
276 * @return {Ext.ProgressBar} this
\r
278 reset : function(hide){
\r
279 this.updateProgress(0);
\r
280 if(this.textTopEl){
\r
281 this.textTopEl.addClass('x-hidden');
\r
283 if(this.waitTimer){
\r
284 this.waitTimer.onStop = null; //prevent recursion
\r
285 Ext.TaskMgr.stop(this.waitTimer);
\r
286 this.waitTimer = null;
\r
294 Ext.reg('progress', Ext.ProgressBar);