3 * Copyright(c) 2006-2009 Ext JS, LLC
5 * http://www.extjs.com/license
8 * @class Ext.ux.StatusBar
9 * <p>Basic status bar component that can be used as the bottom toolbar of any {@link Ext.Panel}. In addition to
10 * supporting the standard {@link Ext.Toolbar} interface for adding buttons, menus and other items, the StatusBar
11 * provides a greedy status element that can be aligned to either side and has convenient methods for setting the
12 * status text and icon. You can also indicate that something is processing using the {@link #showBusy} method.</p>
13 * <p><b>Note:</b> Although StatusBar supports xtype:'statusbar', at this time Ext.Toolbar (the base class) does
14 * not support xtype. For this reason, if you are adding Toolbar items into the StatusBar you must declare it
15 * using the "new StatusBar()" syntax for the items to render correctly.</p>
20 bbar: new Ext.ux.StatusBar({
23 // defaults to use when the status is cleared:
24 defaultText: 'Default status text',
25 defaultIconCls: 'default-icon',
27 // values to set initially:
29 iconCls: 'ready-icon',
31 // any standard Toolbar items:
38 // Update the status bar later in code:
39 var sb = Ext.getCmp('my-status');
43 clear: true // auto-clear after a set interval
46 // Set the status bar to show that something is processing:
51 sb.clearStatus(); // once completeed
53 * @extends Ext.Toolbar
55 * Creates a new StatusBar
56 * @param {Object/Array} config A config object
58 Ext.ux.StatusBar = Ext.extend(Ext.Toolbar, {
60 * @cfg {String} statusAlign
61 * The alignment of the status element within the overall StatusBar layout. When the StatusBar is rendered,
62 * it creates an internal div containing the status text and icon. Any additional Toolbar items added in the
63 * StatusBar's {@link #items} config, or added via {@link #add} or any of the supported add* methods, will be
64 * rendered, in added order, to the opposite side. The status element is greedy, so it will automatically
65 * expand to take up all sapce left over by any other items. Example usage:
67 // Create a left-aligned status bar containing a button,
68 // separator and text item that will be right-aligned (default):
72 bbar: new Ext.ux.StatusBar({
73 defaultText: 'Default status text',
81 // By adding the statusAlign config, this will create the
82 // exact same toolbar, except the status and toolbar item
83 // layout will be reversed from the previous example:
87 bbar: new Ext.ux.StatusBar({
88 defaultText: 'Default status text',
99 * @cfg {String} defaultText
100 * The default {@link #text} value. This will be used anytime the status bar is cleared with the
101 * <tt>useDefaults:true</tt> option (defaults to '').
104 * @cfg {String} defaultIconCls
105 * The default {@link #iconCls} value (see the iconCls docs for additional details about customizing the icon).
106 * This will be used anytime the status bar is cleared with the <tt>useDefaults:true</tt> option (defaults to '').
110 * A string that will be rendered into the status element as the status message (defaults to '');
113 * @cfg {String} iconCls
114 * A CSS class that will be applied to the status element and is expected to provide a background image that will
115 * serve as the status bar icon (defaults to ''). The class is applied directly to the div that also contains the
116 * status text, so the rule should provide the appropriate padding on the div to make room for the image.
117 * Example usage:<pre><code>
119 .x-statusbar .x-status-custom {
121 background: transparent url(images/custom-icon.gif) no-repeat 3px 3px;
124 // Initializing the status bar:
125 var sb = new Ext.ux.StatusBar({
126 defaultIconCls: 'x-status-custom'
129 // Setting it in code:
132 iconCls: 'x-status-custom'
139 * The base class applied to the containing element for this component on render (defaults to 'x-statusbar')
143 * @cfg {String} busyIconCls
144 * The default {@link #iconCls} applied when calling {@link #showBusy} (defaults to 'x-status-busy'). It can be
145 * overridden at any time by passing the <tt>iconCls</tt> argument into <tt>showBusy</tt>. See the
146 * iconCls docs for additional details about customizing the icon.
148 busyIconCls : 'x-status-busy',
150 * @cfg {String} busyText
151 * The default {@link #text} applied when calling {@link #showBusy} (defaults to 'Loading...'). It can be
152 * overridden at any time by passing the <tt>text</tt> argument into <tt>showBusy</tt>.
154 busyText : 'Loading...',
156 * @cfg {Number} autoClear
157 * The number of milliseconds to wait after setting the status via {@link #setStatus} before automatically
158 * clearing the status text and icon (defaults to 5000). Note that this only applies when passing the
159 * <tt>clear</tt> argument to setStatus since that is the only way to defer clearing the status. This can
160 * be overridden by specifying a different <tt>wait</tt> value in setStatus. Calls to {@link #clearStatus}
161 * always clear the status bar immediately and ignore this value.
169 initComponent : function(){
170 if(this.statusAlign=='right'){
171 this.cls += ' x-status-right';
173 Ext.ux.StatusBar.superclass.initComponent.call(this);
177 afterRender : function(){
178 Ext.ux.StatusBar.superclass.afterRender.call(this);
180 var right = this.statusAlign == 'right';
181 this.statusEl = new Ext.Toolbar.TextItem({
182 cls: 'x-status-text ' + (this.iconCls || this.defaultIconCls || ''),
183 text: this.text || this.defaultText || ''
188 this.add(this.statusEl);
190 this.insert(0, this.statusEl);
191 this.insert(1, '->');
194 // this.statusEl = td.createChild({
195 // cls: 'x-status-text ' + (this.iconCls || this.defaultIconCls || ''),
196 // html: this.text || this.defaultText || ''
198 // this.statusEl.unselectable();
200 // this.spacerEl = td.insertSibling({
202 // style: 'width:100%',
203 // cn: [{cls:'ytb-spacer'}]
204 // }, right ? 'before' : 'after');
208 * Sets the status {@link #text} and/or {@link #iconCls}. Also supports automatically clearing the
209 * status that was set after a specified interval.
210 * @param {Object/String} config A config object specifying what status to set, or a string assumed
211 * to be the status text (and all other options are defaulted as explained below). A config
212 * object containing any or all of the following properties can be passed:<ul>
213 * <li><tt>text</tt> {String} : (optional) The status text to display. If not specified, any current
214 * status text will remain unchanged.</li>
215 * <li><tt>iconCls</tt> {String} : (optional) The CSS class used to customize the status icon (see
216 * {@link #iconCls} for details). If not specified, any current iconCls will remain unchanged.</li>
217 * <li><tt>clear</tt> {Boolean/Number/Object} : (optional) Allows you to set an internal callback that will
218 * automatically clear the status text and iconCls after a specified amount of time has passed. If clear is not
219 * specified, the new status will not be auto-cleared and will stay until updated again or cleared using
220 * {@link #clearStatus}. If <tt>true</tt> is passed, the status will be cleared using {@link #autoClear},
221 * {@link #defaultText} and {@link #defaultIconCls} via a fade out animation. If a numeric value is passed,
222 * it will be used as the callback interval (in milliseconds), overriding the {@link #autoClear} value.
223 * All other options will be defaulted as with the boolean option. To customize any other options,
224 * you can pass an object in the format:<ul>
225 * <li><tt>wait</tt> {Number} : (optional) The number of milliseconds to wait before clearing
226 * (defaults to {@link #autoClear}).</li>
227 * <li><tt>anim</tt> {Number} : (optional) False to clear the status immediately once the callback
228 * executes (defaults to true which fades the status out).</li>
229 * <li><tt>useDefaults</tt> {Number} : (optional) False to completely clear the status text and iconCls
230 * (defaults to true which uses {@link #defaultText} and {@link #defaultIconCls}).</li>
232 * Example usage:<pre><code>
233 // Simple call to update the text
234 statusBar.setStatus('New status');
236 // Set the status and icon, auto-clearing with default options:
237 statusBar.setStatus({
239 iconCls: 'x-status-custom',
243 // Auto-clear with custom options:
244 statusBar.setStatus({
246 iconCls: 'x-status-custom',
254 * @return {Ext.ux.StatusBar} this
256 setStatus : function(o){
259 if(typeof o == 'string'){
262 if(o.text !== undefined){
263 this.setText(o.text);
265 if(o.iconCls !== undefined){
266 this.setIcon(o.iconCls);
271 wait = this.autoClear,
272 defaults = {useDefaults: true, anim: true};
274 if(typeof c == 'object'){
275 c = Ext.applyIf(c, defaults);
279 }else if(typeof c == 'number'){
282 }else if(typeof c == 'boolean'){
286 c.threadId = this.activeThreadId;
287 this.clearStatus.defer(wait, this, [c]);
293 * Clears the status {@link #text} and {@link #iconCls}. Also supports clearing via an optional fade out animation.
294 * @param {Object} config (optional) A config object containing any or all of the following properties. If this
295 * object is not specified the status will be cleared using the defaults below:<ul>
296 * <li><tt>anim</tt> {Boolean} : (optional) True to clear the status by fading out the status element (defaults
297 * to false which clears immediately).</li>
298 * <li><tt>useDefaults</tt> {Boolean} : (optional) True to reset the text and icon using {@link #defaultText} and
299 * {@link #defaultIconCls} (defaults to false which sets the text to '' and removes any existing icon class).</li>
301 * @return {Ext.ux.StatusBar} this
303 clearStatus : function(o){
306 if(o.threadId && o.threadId !== this.activeThreadId){
307 // this means the current call was made internally, but a newer
308 // thread has set a message since this call was deferred. Since
309 // we don't want to overwrite a newer message just ignore.
313 var text = o.useDefaults ? this.defaultText : '',
314 iconCls = o.useDefaults ? (this.defaultIconCls ? this.defaultIconCls : '') : '';
317 this.statusEl.fadeOut({
321 callback: function(){
326 this.statusEl.show();
330 // hide/show the el to avoid jumpy text or icon
331 this.statusEl.hide();
336 this.statusEl.show();
342 * Convenience method for setting the status text directly. For more flexible options see {@link #setStatus}.
343 * @param {String} text (optional) The text to set (defaults to '')
344 * @return {Ext.ux.StatusBar} this
346 setText : function(text){
347 this.activeThreadId++;
348 this.text = text || '';
350 this.statusEl.setText(this.text);
356 * Returns the current status text.
357 * @return {String} The status text
359 getText : function(){
364 * Convenience method for setting the status icon directly. For more flexible options see {@link #setStatus}.
365 * See {@link #iconCls} for complete details about customizing the icon.
366 * @param {String} iconCls (optional) The icon class to set (defaults to '', and any current icon class is removed)
367 * @return {Ext.ux.StatusBar} this
369 setIcon : function(cls){
370 this.activeThreadId++;
374 if(this.currIconCls){
375 this.statusEl.removeClass(this.currIconCls);
376 this.currIconCls = null;
379 this.statusEl.addClass(cls);
380 this.currIconCls = cls;
383 this.currIconCls = cls;
389 * Convenience method for setting the status text and icon to special values that are pre-configured to indicate
390 * a "busy" state, usually for loading or processing activities.
391 * @param {Object/String} config (optional) A config object in the same format supported by {@link #setStatus}, or a
392 * string to use as the status text (in which case all other options for setStatus will be defaulted). Use the
393 * <tt>text</tt> and/or <tt>iconCls</tt> properties on the config to override the default {@link #busyText}
394 * and {@link #busyIconCls} settings. If the config argument is not specified, {@link #busyText} and
395 * {@link #busyIconCls} will be used in conjunction with all of the default options for {@link #setStatus}.
396 * @return {Ext.ux.StatusBar} this
398 showBusy : function(o){
399 if(typeof o == 'string'){
402 o = Ext.applyIf(o || {}, {
404 iconCls: this.busyIconCls
406 return this.setStatus(o);
409 Ext.reg('statusbar', Ext.ux.StatusBar);