3 <title>The source code</title>
4 <link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />
5 <script type="text/javascript" src="../resources/prettify/prettify.js"></script>
7 <body onload="prettyPrint();">
8 <pre class="prettyprint lang-js"><div id="cls-Ext.ux.StatusBar"></div>/**
9 * @class Ext.ux.StatusBar
10 * <p>Basic status bar component that can be used as the bottom toolbar of any {@link Ext.Panel}. In addition to
11 * supporting the standard {@link Ext.Toolbar} interface for adding buttons, menus and other items, the StatusBar
12 * provides a greedy status element that can be aligned to either side and has convenient methods for setting the
13 * status text and icon. You can also indicate that something is processing using the {@link #showBusy} method.</p>
18 bbar: new Ext.ux.StatusBar({
21 // defaults to use when the status is cleared:
22 defaultText: 'Default status text',
23 defaultIconCls: 'default-icon',
25 // values to set initially:
27 iconCls: 'ready-icon',
29 // any standard Toolbar items:
36 // Update the status bar later in code:
37 var sb = Ext.getCmp('my-status');
41 clear: true // auto-clear after a set interval
44 // Set the status bar to show that something is processing:
49 sb.clearStatus(); // once completeed
51 * @extends Ext.Toolbar
53 * Creates a new StatusBar
54 * @param {Object/Array} config A config object
56 Ext.ux.StatusBar = Ext.extend(Ext.Toolbar, {
57 <div id="cfg-Ext.ux.StatusBar-statusAlign"></div>/**
58 * @cfg {String} statusAlign
59 * The alignment of the status element within the overall StatusBar layout. When the StatusBar is rendered,
60 * it creates an internal div containing the status text and icon. Any additional Toolbar items added in the
61 * StatusBar's {@link #items} config, or added via {@link #add} or any of the supported add* methods, will be
62 * rendered, in added order, to the opposite side. The status element is greedy, so it will automatically
63 * expand to take up all sapce left over by any other items. Example usage:
65 // Create a left-aligned status bar containing a button,
66 // separator and text item that will be right-aligned (default):
70 bbar: new Ext.ux.StatusBar({
71 defaultText: 'Default status text',
79 // By adding the statusAlign config, this will create the
80 // exact same toolbar, except the status and toolbar item
81 // layout will be reversed from the previous example:
85 bbar: new Ext.ux.StatusBar({
86 defaultText: 'Default status text',
96 <div id="cfg-Ext.ux.StatusBar-defaultText"></div>/**
97 * @cfg {String} defaultText
98 * The default {@link #text} value. This will be used anytime the status bar is cleared with the
99 * <tt>useDefaults:true</tt> option (defaults to '').
101 <div id="cfg-Ext.ux.StatusBar-defaultIconCls"></div>/**
102 * @cfg {String} defaultIconCls
103 * The default {@link #iconCls} value (see the iconCls docs for additional details about customizing the icon).
104 * This will be used anytime the status bar is cleared with the <tt>useDefaults:true</tt> option (defaults to '').
106 <div id="cfg-Ext.ux.StatusBar-text"></div>/**
108 * A string that will be <b>initially</b> set as the status message. This string
109 * will be set as innerHTML (html tags are accepted) for the toolbar item.
110 * If not specified, the value set for <code>{@link #defaultText}</code>
113 <div id="cfg-Ext.ux.StatusBar-iconCls"></div>/**
114 * @cfg {String} iconCls
115 * A CSS class that will be <b>initially</b> set as the status bar icon and is
116 * expected to provide a background image (defaults to '').
117 * Example usage:<pre><code>
119 .x-statusbar .x-status-custom {
121 background: transparent url(images/custom-icon.gif) no-repeat 3px 2px;
124 // Setting a default icon:
125 var sb = new Ext.ux.StatusBar({
126 defaultIconCls: 'x-status-custom'
129 // Changing the icon:
132 iconCls: 'x-status-custom'
137 <div id="cfg-Ext.ux.StatusBar-cls"></div>/**
139 * The base class applied to the containing element for this component on render (defaults to 'x-statusbar')
142 <div id="cfg-Ext.ux.StatusBar-busyIconCls"></div>/**
143 * @cfg {String} busyIconCls
144 * The default <code>{@link #iconCls}</code> applied when calling
145 * <code>{@link #showBusy}</code> (defaults to <tt>'x-status-busy'</tt>).
146 * It can be overridden at any time by passing the <code>iconCls</code>
147 * argument into <code>{@link #showBusy}</code>.
149 busyIconCls : 'x-status-busy',
150 <div id="cfg-Ext.ux.StatusBar-busyText"></div>/**
151 * @cfg {String} busyText
152 * The default <code>{@link #text}</code> applied when calling
153 * <code>{@link #showBusy}</code> (defaults to <tt>'Loading...'</tt>).
154 * It can be overridden at any time by passing the <code>text</code>
155 * argument into <code>{@link #showBusy}</code>.
157 busyText : 'Loading...',
158 <div id="cfg-Ext.ux.StatusBar-autoClear"></div>/**
159 * @cfg {Number} autoClear
160 * The number of milliseconds to wait after setting the status via
161 * <code>{@link #setStatus}</code> before automatically clearing the status
162 * text and icon (defaults to <tt>5000</tt>). Note that this only applies
163 * when passing the <tt>clear</tt> argument to <code>{@link #setStatus}</code>
164 * since that is the only way to defer clearing the status. This can
165 * be overridden by specifying a different <tt>wait</tt> value in
166 * <code>{@link #setStatus}</code>. Calls to <code>{@link #clearStatus}</code>
167 * always clear the status bar immediately and ignore this value.
171 <div id="cfg-Ext.ux.StatusBar-emptyText"></div>/**
172 * @cfg {String} emptyText
173 * The text string to use if no text has been set. Defaults to
174 * <tt>' '</tt>). If there are no other items in the toolbar using
175 * an empty string (<tt>''</tt>) for this value would end up in the toolbar
176 * height collapsing since the empty string will not maintain the toolbar
177 * height. Use <tt>''</tt> if the toolbar should collapse in height
178 * vertically when no text is specified and there are no other items in
181 emptyText : ' ',
187 initComponent : function(){
188 if(this.statusAlign=='right'){
189 this.cls += ' x-status-right';
191 Ext.ux.StatusBar.superclass.initComponent.call(this);
195 afterRender : function(){
196 Ext.ux.StatusBar.superclass.afterRender.call(this);
198 var right = this.statusAlign == 'right';
199 this.currIconCls = this.iconCls || this.defaultIconCls;
200 this.statusEl = new Ext.Toolbar.TextItem({
201 cls: 'x-status-text ' + (this.currIconCls || ''),
202 text: this.text || this.defaultText || ''
207 this.add(this.statusEl);
209 this.insert(0, this.statusEl);
210 this.insert(1, '->');
213 // this.statusEl = td.createChild({
214 // cls: 'x-status-text ' + (this.iconCls || this.defaultIconCls || ''),
215 // html: this.text || this.defaultText || ''
217 // this.statusEl.unselectable();
219 // this.spacerEl = td.insertSibling({
221 // style: 'width:100%',
222 // cn: [{cls:'ytb-spacer'}]
223 // }, right ? 'before' : 'after');
226 <div id="method-Ext.ux.StatusBar-setStatus"></div>/**
227 * Sets the status {@link #text} and/or {@link #iconCls}. Also supports automatically clearing the
228 * status that was set after a specified interval.
229 * @param {Object/String} config A config object specifying what status to set, or a string assumed
230 * to be the status text (and all other options are defaulted as explained below). A config
231 * object containing any or all of the following properties can be passed:<ul>
232 * <li><tt>text</tt> {String} : (optional) The status text to display. If not specified, any current
233 * status text will remain unchanged.</li>
234 * <li><tt>iconCls</tt> {String} : (optional) The CSS class used to customize the status icon (see
235 * {@link #iconCls} for details). If not specified, any current iconCls will remain unchanged.</li>
236 * <li><tt>clear</tt> {Boolean/Number/Object} : (optional) Allows you to set an internal callback that will
237 * automatically clear the status text and iconCls after a specified amount of time has passed. If clear is not
238 * specified, the new status will not be auto-cleared and will stay until updated again or cleared using
239 * {@link #clearStatus}. If <tt>true</tt> is passed, the status will be cleared using {@link #autoClear},
240 * {@link #defaultText} and {@link #defaultIconCls} via a fade out animation. If a numeric value is passed,
241 * it will be used as the callback interval (in milliseconds), overriding the {@link #autoClear} value.
242 * All other options will be defaulted as with the boolean option. To customize any other options,
243 * you can pass an object in the format:<ul>
244 * <li><tt>wait</tt> {Number} : (optional) The number of milliseconds to wait before clearing
245 * (defaults to {@link #autoClear}).</li>
246 * <li><tt>anim</tt> {Number} : (optional) False to clear the status immediately once the callback
247 * executes (defaults to true which fades the status out).</li>
248 * <li><tt>useDefaults</tt> {Number} : (optional) False to completely clear the status text and iconCls
249 * (defaults to true which uses {@link #defaultText} and {@link #defaultIconCls}).</li>
251 * Example usage:<pre><code>
252 // Simple call to update the text
253 statusBar.setStatus('New status');
255 // Set the status and icon, auto-clearing with default options:
256 statusBar.setStatus({
258 iconCls: 'x-status-custom',
262 // Auto-clear with custom options:
263 statusBar.setStatus({
265 iconCls: 'x-status-custom',
273 * @return {Ext.ux.StatusBar} this
275 setStatus : function(o){
278 if(typeof o == 'string'){
281 if(o.text !== undefined){
282 this.setText(o.text);
284 if(o.iconCls !== undefined){
285 this.setIcon(o.iconCls);
290 wait = this.autoClear,
291 defaults = {useDefaults: true, anim: true};
293 if(typeof c == 'object'){
294 c = Ext.applyIf(c, defaults);
298 }else if(typeof c == 'number'){
301 }else if(typeof c == 'boolean'){
305 c.threadId = this.activeThreadId;
306 this.clearStatus.defer(wait, this, [c]);
311 <div id="method-Ext.ux.StatusBar-clearStatus"></div>/**
312 * Clears the status {@link #text} and {@link #iconCls}. Also supports clearing via an optional fade out animation.
313 * @param {Object} config (optional) A config object containing any or all of the following properties. If this
314 * object is not specified the status will be cleared using the defaults below:<ul>
315 * <li><tt>anim</tt> {Boolean} : (optional) True to clear the status by fading out the status element (defaults
316 * to false which clears immediately).</li>
317 * <li><tt>useDefaults</tt> {Boolean} : (optional) True to reset the text and icon using {@link #defaultText} and
318 * {@link #defaultIconCls} (defaults to false which sets the text to '' and removes any existing icon class).</li>
320 * @return {Ext.ux.StatusBar} this
322 clearStatus : function(o){
325 if(o.threadId && o.threadId !== this.activeThreadId){
326 // this means the current call was made internally, but a newer
327 // thread has set a message since this call was deferred. Since
328 // we don't want to overwrite a newer message just ignore.
332 var text = o.useDefaults ? this.defaultText : this.emptyText,
333 iconCls = o.useDefaults ? (this.defaultIconCls ? this.defaultIconCls : '') : '';
336 // animate the statusEl Ext.Element
337 this.statusEl.el.fadeOut({
341 callback: function(){
347 this.statusEl.el.show();
351 // hide/show the el to avoid jumpy text or icon
352 this.statusEl.hide();
357 this.statusEl.show();
362 <div id="method-Ext.ux.StatusBar-setText"></div>/**
363 * Convenience method for setting the status text directly. For more flexible options see {@link #setStatus}.
364 * @param {String} text (optional) The text to set (defaults to '')
365 * @return {Ext.ux.StatusBar} this
367 setText : function(text){
368 this.activeThreadId++;
369 this.text = text || '';
371 this.statusEl.setText(this.text);
376 <div id="method-Ext.ux.StatusBar-getText"></div>/**
377 * Returns the current status text.
378 * @return {String} The status text
380 getText : function(){
384 <div id="method-Ext.ux.StatusBar-setIcon"></div>/**
385 * Convenience method for setting the status icon directly. For more flexible options see {@link #setStatus}.
386 * See {@link #iconCls} for complete details about customizing the icon.
387 * @param {String} iconCls (optional) The icon class to set (defaults to '', and any current icon class is removed)
388 * @return {Ext.ux.StatusBar} this
390 setIcon : function(cls){
391 this.activeThreadId++;
395 if(this.currIconCls){
396 this.statusEl.removeClass(this.currIconCls);
397 this.currIconCls = null;
400 this.statusEl.addClass(cls);
401 this.currIconCls = cls;
404 this.currIconCls = cls;
409 <div id="method-Ext.ux.StatusBar-showBusy"></div>/**
410 * Convenience method for setting the status text and icon to special values that are pre-configured to indicate
411 * a "busy" state, usually for loading or processing activities.
412 * @param {Object/String} config (optional) A config object in the same format supported by {@link #setStatus}, or a
413 * string to use as the status text (in which case all other options for setStatus will be defaulted). Use the
414 * <tt>text</tt> and/or <tt>iconCls</tt> properties on the config to override the default {@link #busyText}
415 * and {@link #busyIconCls} settings. If the config argument is not specified, {@link #busyText} and
416 * {@link #busyIconCls} will be used in conjunction with all of the default options for {@link #setStatus}.
417 * @return {Ext.ux.StatusBar} this
419 showBusy : function(o){
420 if(typeof o == 'string'){
423 o = Ext.applyIf(o || {}, {
425 iconCls: this.busyIconCls
427 return this.setStatus(o);
430 Ext.reg('statusbar', Ext.ux.StatusBar);