3
* Copyright(c) 2006-2008, Ext JS, LLC.
6
* http://extjs.com/license
10
* @class Ext.ProgressBar
11
* @extends Ext.BoxComponent
12
* <p>An updateable progress bar component. The progress bar supports two different modes: manual and automatic.</p>
13
* <p>In manual mode, you are responsible for showing, updating (via {@link #updateProgress}) and clearing the
14
* progress bar as needed from your own code. This method is most appropriate when you want to show progress
15
* throughout an operation that has predictable points of interest at which you can update the control.</p>
16
* <p>In automatic mode, you simply call {@link #wait} and let the progress bar run indefinitely, only clearing it
17
* once the operation is complete. You can optionally have the progress bar wait for a specific amount of time
18
* and then clear itself. Automatic mode is most appropriate for timed operations or asymchronous operations in
19
* which you have no need for indicating intermediate progress.</p>
20
* @cfg {Float} value A floating point value between 0 and 1 (e.g., .5, defaults to 0)
21
* @cfg {String} text The progress bar text (defaults to '')
22
* @cfg {Mixed} textEl The element to render the progress text to (defaults to the progress
23
* bar's internal text element)
24
* @cfg {String} id The progress bar element's id (defaults to an auto-generated id)
26
Ext.ProgressBar = Ext.extend(Ext.BoxComponent, {
28
* @cfg {String} baseCls
29
* The base CSS class to apply to the progress bar's wrapper element (defaults to 'x-progress')
31
baseCls : 'x-progress',
37
initComponent : function(){
38
Ext.ProgressBar.superclass.initComponent.call(this);
42
* Fires after each update interval
43
* @param {Ext.ProgressBar} this
44
* @param {Number} The current progress value
45
* @param {String} The current progress text
52
onRender : function(ct, position){
53
Ext.ProgressBar.superclass.onRender.call(this, ct, position);
55
var tpl = new Ext.Template(
56
'<div class="{cls}-wrap">',
57
'<div class="{cls}-inner">',
58
'<div class="{cls}-bar">',
59
'<div class="{cls}-text">',
63
'<div class="{cls}-text {cls}-text-back">',
71
this.el = tpl.insertBefore(position, {cls: this.baseCls}, true);
73
this.el = tpl.append(ct, {cls: this.baseCls}, true);
76
this.el.dom.id = this.id;
78
var inner = this.el.dom.firstChild;
79
this.progressBar = Ext.get(inner.firstChild);
82
//use an external text el
83
this.textEl = Ext.get(this.textEl);
84
delete this.textTopEl;
86
//setup our internal layered text els
87
this.textTopEl = Ext.get(this.progressBar.dom.firstChild);
88
var textBackEl = Ext.get(inner.childNodes[1]);
89
this.textTopEl.setStyle("z-index", 99).addClass('x-hidden');
90
this.textEl = new Ext.CompositeElement([this.textTopEl.dom.firstChild, textBackEl.dom.firstChild]);
91
this.textEl.setWidth(inner.offsetWidth);
93
this.progressBar.setHeight(inner.offsetHeight);
97
afterRender : function(){
98
Ext.ProgressBar.superclass.afterRender.call(this);
100
this.updateProgress(this.value, this.text);
102
this.updateText(this.text);
107
* Updates the progress bar value, and optionally its text. If the text argument is not specified,
108
* any existing text value will be unchanged. To blank out existing text, pass ''. Note that even
109
* if the progress bar value exceeds 1, it will never automatically reset -- you are responsible for
110
* determining when the progress is complete and calling {@link #reset} to clear and/or hide the control.
111
* @param {Float} value (optional) A floating point value between 0 and 1 (e.g., .5, defaults to 0)
112
* @param {String} text (optional) The string to display in the progress text element (defaults to '')
113
* @return {Ext.ProgressBar} this
115
updateProgress : function(value, text){
116
this.value = value || 0;
118
this.updateText(text);
121
var w = Math.floor(value*this.el.dom.firstChild.offsetWidth);
122
this.progressBar.setWidth(w);
124
//textTopEl should be the same width as the bar so overflow will clip as the bar moves
125
this.textTopEl.removeClass('x-hidden').setWidth(w);
128
this.fireEvent('update', this, value, text);
133
* Initiates an auto-updating progress bar. A duration can be specified, in which case the progress
134
* bar will automatically reset after a fixed amount of time and optionally call a callback function
135
* if specified. If no duration is passed in, then the progress bar will run indefinitely and must
136
* be manually cleared by calling {@link #reset}. The wait method accepts a config object with
137
* the following properties:
139
Property Type Description
140
---------- ------------ ----------------------------------------------------------------------
141
duration Number The length of time in milliseconds that the progress bar should
142
run before resetting itself (defaults to undefined, in which case it
143
will run indefinitely until reset is called)
144
interval Number The length of time in milliseconds between each progress update
145
(defaults to 1000 ms)
146
increment Number The number of progress update segments to display within the progress
147
bar (defaults to 10). If the bar reaches the end and is still
148
updating, it will automatically wrap back to the beginning.
149
text String Optional text to display in the progress bar element (defaults to '').
150
fn Function A callback function to execute after the progress bar finishes auto-
151
updating. The function will be called with no arguments. This function
152
will be ignored if duration is not specified since in that case the
153
progress bar can only be stopped programmatically, so any required function
154
should be called by the same code after it resets the progress bar.
155
scope Object The scope that is passed to the callback function (only applies when
156
duration and fn are both passed).
161
var p = new Ext.ProgressBar({
165
//Wait for 5 seconds, then update the status el (progress bar will auto-reset)
167
interval: 100, //bar will move fast!
173
Ext.fly('status').update('Done!');
177
//Or update indefinitely until some async action completes, then reset manually
179
myAction.on('complete', function(){
181
Ext.fly('status').update('Done!');
184
* @param {Object} config (optional) Configuration options
185
* @return {Ext.ProgressBar} this
191
this.updateText(o.text);
192
this.waitTimer = Ext.TaskMgr.start({
194
var inc = o.increment || 10;
195
this.updateProgress(((((i+inc)%inc)+1)*(100/inc))*.01);
197
interval: o.interval || 1000,
198
duration: o.duration,
201
o.fn.apply(o.scope || this);
212
* Returns true if the progress bar is currently in a {@link #wait} operation
213
* @return {Boolean} True if waiting, else false
215
isWaiting : function(){
216
return this.waitTimer != null;
220
* Updates the progress bar text. If specified, textEl will be updated, otherwise the progress
221
* bar itself will display the updated text.
222
* @param {String} text (optional) The string to display in the progress text element (defaults to '')
223
* @return {Ext.ProgressBar} this
225
updateText : function(text){
226
this.text = text || ' ';
228
this.textEl.update(this.text);
234
* Synchronizes the inner bar width to the proper proportion of the total componet width based
235
* on the current progress {@link #value}. This will be called automatically when the ProgressBar
236
* is resized by a layout, but if it is rendered auto width, this method can be called from
237
* another resize handler to sync the ProgressBar if necessary.
239
syncProgressBar : function(){
241
this.updateProgress(this.value, this.text);
247
* Sets the size of the progress bar.
248
* @param {Number} width The new width in pixels
249
* @param {Number} height The new height in pixels
250
* @return {Ext.ProgressBar} this
252
setSize : function(w, h){
253
Ext.ProgressBar.superclass.setSize.call(this, w, h);
255
var inner = this.el.dom.firstChild;
256
this.textEl.setSize(inner.offsetWidth, inner.offsetHeight);
258
this.syncProgressBar();
263
* Resets the progress bar value to 0 and text to empty string. If hide = true, the progress
264
* bar will also be hidden (using the {@link #hideMode} property internally).
265
* @param {Boolean} hide (optional) True to hide the progress bar (defaults to false)
266
* @return {Ext.ProgressBar} this
268
reset : function(hide){
269
this.updateProgress(0);
271
this.textTopEl.addClass('x-hidden');
274
this.waitTimer.onStop = null; //prevent recursion
275
Ext.TaskMgr.stop(this.waitTimer);
276
this.waitTimer = null;
284
Ext.reg('progress', Ext.ProgressBar);
b'\\ No newline at end of file'