3
* Copyright(c) 2006-2009, Ext JS, LLC.
6
* http://extjs.com/license
10
* @class Ext.StatusBar
11
* <p>Basic status bar component that can be used as the bottom toolbar of any {@link Ext.Panel}. In addition to
12
* supporting the standard {@link Ext.Toolbar} interface for adding buttons, menus and other items, the StatusBar
13
* provides a greedy status element that can be aligned to either side and has convenient methods for setting the
14
* status text and icon. You can also indicate that something is processing using the {@link #showBusy} method.</p>
15
* <p><b>Note:</b> Although StatusBar supports xtype:'statusbar', at this time Ext.Toolbar (the base class) does
16
* not support xtype. For this reason, if you are adding Toolbar items into the StatusBar you must declare it
17
* using the "new StatusBar()" syntax for the items to render correctly.</p>
22
bbar: new Ext.StatusBar({
25
// defaults to use when the status is cleared:
26
defaultText: 'Default status text',
27
defaultIconCls: 'default-icon',
29
// values to set initially:
31
iconCls: 'ready-icon',
33
// any standard Toolbar items:
40
// Update the status bar later in code:
41
var sb = Ext.getCmp('my-status');
45
clear: true // auto-clear after a set interval
48
// Set the status bar to show that something is processing:
53
sb.clearStatus(); // once completeed
55
* @extends Ext.Toolbar
57
* Creates a new StatusBar
58
* @param {Object/Array} config A config object
60
Ext.StatusBar = Ext.extend(Ext.Toolbar, {
62
* @cfg {String} statusAlign
63
* The alignment of the status element within the overall StatusBar layout. When the StatusBar is rendered,
64
* it creates an internal div containing the status text and icon. Any additional Toolbar items added in the
65
* StatusBar's {@link #items} config, or added via {@link #add} or any of the supported add* methods, will be
66
* rendered, in added order, to the opposite side. The status element is greedy, so it will automatically
67
* expand to take up all sapce left over by any other items. Example usage:
69
// Create a left-aligned status bar containing a button,
70
// separator and text item that will be right-aligned (default):
74
bbar: new Ext.StatusBar({
75
defaultText: 'Default status text',
83
// By adding the statusAlign config, this will create the
84
// exact same toolbar, except the status and toolbar item
85
// layout will be reversed from the previous example:
89
bbar: new Ext.StatusBar({
90
defaultText: 'Default status text',
101
* @cfg {String} defaultText
102
* The default {@link #text} value. This will be used anytime the status bar is cleared with the
103
* <tt>useDefaults:true</tt> option (defaults to '').
106
* @cfg {String} defaultIconCls
107
* The default {@link #iconCls} value (see the iconCls docs for additional details about customizing the icon).
108
* This will be used anytime the status bar is cleared with the <tt>useDefaults:true</tt> option (defaults to '').
112
* A string that will be rendered into the status element as the status message (defaults to '');
115
* @cfg {String} iconCls
116
* A CSS class that will be applied to the status element and is expected to provide a background image that will
117
* serve as the status bar icon (defaults to ''). The class is applied directly to the div that also contains the
118
* status text, so the rule should provide the appropriate padding on the div to make room for the image.
119
* Example usage:<pre><code>
121
.x-statusbar .x-status-custom {
123
background: transparent url(images/custom-icon.gif) no-repeat 3px 3px;
126
// Initializing the status bar:
127
var sb = new Ext.StatusBar({
128
defaultIconCls: 'x-status-custom'
131
// Setting it in code:
134
iconCls: 'x-status-custom'
141
* The base class applied to the containing element for this component on render (defaults to 'x-statusbar')
145
* @cfg {String} busyIconCls
146
* The default {@link #iconCls} applied when calling {@link #showBusy} (defaults to 'x-status-busy'). It can be
147
* overridden at any time by passing the <tt>iconCls</tt> argument into <tt>showBusy</tt>. See the
148
* iconCls docs for additional details about customizing the icon.
150
busyIconCls : 'x-status-busy',
152
* @cfg {String} busyText
153
* The default {@link #text} applied when calling {@link #showBusy} (defaults to 'Loading...'). It can be
154
* overridden at any time by passing the <tt>text</tt> argument into <tt>showBusy</tt>.
156
busyText : 'Loading...',
158
* @cfg {Number} autoClear
159
* The number of milliseconds to wait after setting the status via {@link #setStatus} before automatically
160
* clearing the status text and icon (defaults to 5000). Note that this only applies when passing the
161
* <tt>clear</tt> argument to setStatus since that is the only way to defer clearing the status. This can
162
* be overridden by specifying a different <tt>wait</tt> value in setStatus. Calls to {@link #clearStatus}
163
* always clear the status bar immediately and ignore this value.
171
initComponent : function(){
172
if(this.statusAlign=='right'){
173
this.cls += ' x-status-right';
175
Ext.StatusBar.superclass.initComponent.call(this);
179
afterRender : function(){
180
Ext.StatusBar.superclass.afterRender.call(this);
182
var right = this.statusAlign=='right',
183
td = Ext.get(this.nextBlock());
186
this.tr.appendChild(td.dom);
188
td.insertBefore(this.tr.firstChild);
191
this.statusEl = td.createChild({
192
cls: 'x-status-text ' + (this.iconCls || this.defaultIconCls || ''),
193
html: this.text || this.defaultText || ''
195
this.statusEl.unselectable();
197
this.spacerEl = td.insertSibling({
200
cn: [{cls:'ytb-spacer'}]
201
}, right ? 'before' : 'after');
205
* Sets the status {@link #text} and/or {@link #iconCls}. Also supports automatically clearing the
206
* status that was set after a specified interval.
207
* @param {Object/String} config A config object specifying what status to set, or a string assumed
208
* to be the status text (and all other options are defaulted as explained below). A config
209
* object containing any or all of the following properties can be passed:<ul>
210
* <li><tt>text</tt> {String} : (optional) The status text to display. If not specified, any current
211
* status text will remain unchanged.</li>
212
* <li><tt>iconCls</tt> {String} : (optional) The CSS class used to customize the status icon (see
213
* {@link #iconCls} for details). If not specified, any current iconCls will remain unchanged.</li>
214
* <li><tt>clear</tt> {Boolean/Number/Object} : (optional) Allows you to set an internal callback that will
215
* automatically clear the status text and iconCls after a specified amount of time has passed. If clear is not
216
* specified, the new status will not be auto-cleared and will stay until updated again or cleared using
217
* {@link #clearStatus}. If <tt>true</tt> is passed, the status will be cleared using {@link #autoClear},
218
* {@link #defaultText} and {@link #defaultIconCls} via a fade out animation. If a numeric value is passed,
219
* it will be used as the callback interval (in milliseconds), overriding the {@link #autoClear} value.
220
* All other options will be defaulted as with the boolean option. To customize any other options,
221
* you can pass an object in the format:<ul>
222
* <li><tt>wait</tt> {Number} : (optional) The number of milliseconds to wait before clearing
223
* (defaults to {@link #autoClear}).</li>
224
* <li><tt>anim</tt> {Number} : (optional) False to clear the status immediately once the callback
225
* executes (defaults to true which fades the status out).</li>
226
* <li><tt>useDefaults</tt> {Number} : (optional) False to completely clear the status text and iconCls
227
* (defaults to true which uses {@link #defaultText} and {@link #defaultIconCls}).</li>
229
* Example usage:<pre><code>
230
// Simple call to update the text
231
statusBar.setStatus('New status');
233
// Set the status and icon, auto-clearing with default options:
234
statusBar.setStatus({
236
iconCls: 'x-status-custom',
240
// Auto-clear with custom options:
241
statusBar.setStatus({
243
iconCls: 'x-status-custom',
251
* @return {Ext.StatusBar} this
253
setStatus : function(o){
256
if(typeof o == 'string'){
259
if(o.text !== undefined){
260
this.setText(o.text);
262
if(o.iconCls !== undefined){
263
this.setIcon(o.iconCls);
268
wait = this.autoClear,
269
defaults = {useDefaults: true, anim: true};
271
if(typeof c == 'object'){
272
c = Ext.applyIf(c, defaults);
276
}else if(typeof c == 'number'){
279
}else if(typeof c == 'boolean'){
283
c.threadId = this.activeThreadId;
284
this.clearStatus.defer(wait, this, [c]);
290
* Clears the status {@link #text} and {@link #iconCls}. Also supports clearing via an optional fade out animation.
291
* @param {Object} config (optional) A config object containing any or all of the following properties. If this
292
* object is not specified the status will be cleared using the defaults below:<ul>
293
* <li><tt>anim</tt> {Boolean} : (optional) True to clear the status by fading out the status element (defaults
294
* to false which clears immediately).</li>
295
* <li><tt>useDefaults</tt> {Boolean} : (optional) True to reset the text and icon using {@link #defaultText} and
296
* {@link #defaultIconCls} (defaults to false which sets the text to '' and removes any existing icon class).</li>
298
* @return {Ext.StatusBar} this
300
clearStatus : function(o){
303
if(o.threadId && o.threadId !== this.activeThreadId){
304
// this means the current call was made internally, but a newer
305
// thread has set a message since this call was deferred. Since
306
// we don't want to overwrite a newer message just ignore.
310
var text = o.useDefaults ? this.defaultText : '',
311
iconCls = o.useDefaults ? (this.defaultIconCls ? this.defaultIconCls : '') : '';
314
this.statusEl.fadeOut({
318
callback: function(){
323
this.statusEl.show();
327
// hide/show the el to avoid jumpy text or icon
328
this.statusEl.hide();
333
this.statusEl.show();
339
* Convenience method for setting the status text directly. For more flexible options see {@link #setStatus}.
340
* @param {String} text (optional) The text to set (defaults to '')
341
* @return {Ext.StatusBar} this
343
setText : function(text){
344
this.activeThreadId++;
345
this.text = text || '';
347
this.statusEl.update(this.text);
353
* Returns the current status text.
354
* @return {String} The status text
356
getText : function(){
361
* Convenience method for setting the status icon directly. For more flexible options see {@link #setStatus}.
362
* See {@link #iconCls} for complete details about customizing the icon.
363
* @param {String} iconCls (optional) The icon class to set (defaults to '', and any current icon class is removed)
364
* @return {Ext.StatusBar} this
366
setIcon : function(cls){
367
this.activeThreadId++;
371
if(this.currIconCls){
372
this.statusEl.removeClass(this.currIconCls);
373
this.currIconCls = null;
376
this.statusEl.addClass(cls);
377
this.currIconCls = cls;
380
this.currIconCls = cls;
386
* Convenience method for setting the status text and icon to special values that are pre-configured to indicate
387
* a "busy" state, usually for loading or processing activities.
388
* @param {Object/String} config (optional) A config object in the same format supported by {@link #setStatus}, or a
389
* string to use as the status text (in which case all other options for setStatus will be defaulted). Use the
390
* <tt>text</tt> and/or <tt>iconCls</tt> properties on the config to override the default {@link #busyText}
391
* and {@link #busyIconCls} settings. If the config argument is not specified, {@link #busyText} and
392
* {@link #busyIconCls} will be used in conjunction with all of the default options for {@link #setStatus}.
393
* @return {Ext.StatusBar} this
395
showBusy : function(o){
396
if(typeof o == 'string'){
399
o = Ext.applyIf(o || {}, {
401
iconCls: this.busyIconCls
403
return this.setStatus(o);
406
Ext.reg('statusbar', Ext.StatusBar);