3 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
4 <title>The source code</title>
5 <link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />
6 <script type="text/javascript" src="../resources/prettify/prettify.js"></script>
8 <body onload="prettyPrint();">
9 <pre class="prettyprint lang-js">/*!
10 * Ext JS Library 3.2.0
11 * Copyright(c) 2006-2010 Ext JS, Inc.
13 * http://www.extjs.com/license
15 <div id="cls-Ext.ProgressBar"></div>/**
16 * @class Ext.ProgressBar
17 * @extends Ext.BoxComponent
18 * <p>An updateable progress bar component. The progress bar supports two different modes: manual and automatic.</p>
19 * <p>In manual mode, you are responsible for showing, updating (via {@link #updateProgress}) and clearing the
20 * progress bar as needed from your own code. This method is most appropriate when you want to show progress
21 * throughout an operation that has predictable points of interest at which you can update the control.</p>
22 * <p>In automatic mode, you simply call {@link #wait} and let the progress bar run indefinitely, only clearing it
23 * once the operation is complete. You can optionally have the progress bar wait for a specific amount of time
24 * and then clear itself. Automatic mode is most appropriate for timed operations or asynchronous operations in
25 * which you have no need for indicating intermediate progress.</p>
26 * @cfg {Float} value A floating point value between 0 and 1 (e.g., .5, defaults to 0)
27 * @cfg {String} text The progress bar text (defaults to '')
28 * @cfg {Mixed} textEl The element to render the progress text to (defaults to the progress
29 * bar's internal text element)
30 * @cfg {String} id The progress bar element's id (defaults to an auto-generated id)
33 Ext.ProgressBar = Ext.extend(Ext.BoxComponent, {
35 * @cfg {String} baseCls
36 * The base CSS class to apply to the progress bar's wrapper element (defaults to 'x-progress')
38 baseCls : 'x-progress',
41 * @cfg {Boolean} animate
42 * True to animate the progress bar during transitions (defaults to false)
50 initComponent : function(){
51 Ext.ProgressBar.superclass.initComponent.call(this);
55 * Fires after each update interval
56 * @param {Ext.ProgressBar} this
57 * @param {Number} The current progress value
58 * @param {String} The current progress text
65 onRender : function(ct, position){
66 var tpl = new Ext.Template(
67 '<div class="{cls}-wrap">',
68 '<div class="{cls}-inner">',
69 '<div class="{cls}-bar">',
70 '<div class="{cls}-text">',
74 '<div class="{cls}-text {cls}-text-back">',
81 this.el = position ? tpl.insertBefore(position, {cls: this.baseCls}, true)
82 : tpl.append(ct, {cls: this.baseCls}, true);
85 this.el.dom.id = this.id;
87 var inner = this.el.dom.firstChild;
88 this.progressBar = Ext.get(inner.firstChild);
91 //use an external text el
92 this.textEl = Ext.get(this.textEl);
93 delete this.textTopEl;
95 //setup our internal layered text els
96 this.textTopEl = Ext.get(this.progressBar.dom.firstChild);
97 var textBackEl = Ext.get(inner.childNodes[1]);
98 this.textTopEl.setStyle("z-index", 99).addClass('x-hidden');
99 this.textEl = new Ext.CompositeElement([this.textTopEl.dom.firstChild, textBackEl.dom.firstChild]);
100 this.textEl.setWidth(inner.offsetWidth);
102 this.progressBar.setHeight(inner.offsetHeight);
106 afterRender : function(){
107 Ext.ProgressBar.superclass.afterRender.call(this);
109 this.updateProgress(this.value, this.text);
111 this.updateText(this.text);
116 * Updates the progress bar value, and optionally its text. If the text argument is not specified,
117 * any existing text value will be unchanged. To blank out existing text, pass ''. Note that even
118 * if the progress bar value exceeds 1, it will never automatically reset -- you are responsible for
119 * determining when the progress is complete and calling {@link #reset} to clear and/or hide the control.
120 * @param {Float} value (optional) A floating point value between 0 and 1 (e.g., .5, defaults to 0)
121 * @param {String} text (optional) The string to display in the progress text element (defaults to '')
122 * @param {Boolean} animate (optional) Whether to animate the transition of the progress bar. If this value is
123 * not specified, the default for the class is used (default to false)
124 * @return {Ext.ProgressBar} this
126 updateProgress : function(value, text, animate){
127 this.value = value || 0;
129 this.updateText(text);
131 if(this.rendered && !this.isDestroyed){
132 var w = Math.floor(value*this.el.dom.firstChild.offsetWidth);
133 this.progressBar.setWidth(w, animate === true || (animate !== false && this.animate));
135 //textTopEl should be the same width as the bar so overflow will clip as the bar moves
136 this.textTopEl.removeClass('x-hidden').setWidth(w);
139 this.fireEvent('update', this, value, text);
144 * Initiates an auto-updating progress bar. A duration can be specified, in which case the progress
145 * bar will automatically reset after a fixed amount of time and optionally call a callback function
146 * if specified. If no duration is passed in, then the progress bar will run indefinitely and must
147 * be manually cleared by calling {@link #reset}. The wait method accepts a config object with
148 * the following properties:
150 Property Type Description
151 ---------- ------------ ----------------------------------------------------------------------
152 duration Number The length of time in milliseconds that the progress bar should
153 run before resetting itself (defaults to undefined, in which case it
154 will run indefinitely until reset is called)
155 interval Number The length of time in milliseconds between each progress update
156 (defaults to 1000 ms)
157 animate Boolean Whether to animate the transition of the progress bar. If this value is
158 not specified, the default for the class is used.
159 increment Number The number of progress update segments to display within the progress
160 bar (defaults to 10). If the bar reaches the end and is still
161 updating, it will automatically wrap back to the beginning.
162 text String Optional text to display in the progress bar element (defaults to '').
163 fn Function A callback function to execute after the progress bar finishes auto-
164 updating. The function will be called with no arguments. This function
165 will be ignored if duration is not specified since in that case the
166 progress bar can only be stopped programmatically, so any required function
167 should be called by the same code after it resets the progress bar.
168 scope Object The scope that is passed to the callback function (only applies when
169 duration and fn are both passed).
174 var p = new Ext.ProgressBar({
178 //Wait for 5 seconds, then update the status el (progress bar will auto-reset)
180 interval: 100, //bar will move fast!
186 Ext.fly('status').update('Done!');
190 //Or update indefinitely until some async action completes, then reset manually
192 myAction.on('complete', function(){
194 Ext.fly('status').update('Done!');
197 * @param {Object} config (optional) Configuration options
198 * @return {Ext.ProgressBar} this
204 this.updateText(o.text);
205 this.waitTimer = Ext.TaskMgr.start({
207 var inc = o.increment || 10;
209 this.updateProgress(((((i+inc)%inc)+1)*(100/inc))*0.01, null, o.animate);
211 interval: o.interval || 1000,
212 duration: o.duration,
215 o.fn.apply(o.scope || this);
226 * Returns true if the progress bar is currently in a {@link #wait} operation
227 * @return {Boolean} True if waiting, else false
229 isWaiting : function(){
230 return this.waitTimer !== null;
234 * Updates the progress bar text. If specified, textEl will be updated, otherwise the progress
235 * bar itself will display the updated text.
236 * @param {String} text (optional) The string to display in the progress text element (defaults to '')
237 * @return {Ext.ProgressBar} this
239 updateText : function(text){
240 this.text = text || ' ';
242 this.textEl.update(this.text);
248 * Synchronizes the inner bar width to the proper proportion of the total componet width based
249 * on the current progress {@link #value}. This will be called automatically when the ProgressBar
250 * is resized by a layout, but if it is rendered auto width, this method can be called from
251 * another resize handler to sync the ProgressBar if necessary.
253 syncProgressBar : function(){
255 this.updateProgress(this.value, this.text);
261 * Sets the size of the progress bar.
262 * @param {Number} width The new width in pixels
263 * @param {Number} height The new height in pixels
264 * @return {Ext.ProgressBar} this
266 setSize : function(w, h){
267 Ext.ProgressBar.superclass.setSize.call(this, w, h);
269 var inner = this.el.dom.firstChild;
270 this.textEl.setSize(inner.offsetWidth, inner.offsetHeight);
272 this.syncProgressBar();
277 * Resets the progress bar value to 0 and text to empty string. If hide = true, the progress
278 * bar will also be hidden (using the {@link #hideMode} property internally).
279 * @param {Boolean} hide (optional) True to hide the progress bar (defaults to false)
280 * @return {Ext.ProgressBar} this
282 reset : function(hide){
283 this.updateProgress(0);
285 this.textTopEl.addClass('x-hidden');
295 clearTimer : function(){
297 this.waitTimer.onStop = null; //prevent recursion
298 Ext.TaskMgr.stop(this.waitTimer);
299 this.waitTimer = null;
303 onDestroy: function(){
306 if(this.textEl.isComposite){
309 Ext.destroyMembers(this, 'textEl', 'progressBar', 'textTopEl');
311 Ext.ProgressBar.superclass.onDestroy.call(this);
314 Ext.reg('progress', Ext.ProgressBar);</pre>