Path: blob/master/extensions/admin_ui/media/javascript/ux/StatusBar.js
1154 views
//1// Copyright (c) 2006-2025 Wade Alcorn - [email protected]2// Browser Exploitation Framework (BeEF) - https://beefproject.com3// See the file 'doc/COPYING' for copying permission4//56/*!7* Ext JS Library 3.1.18* Copyright(c) 2006-2010 Ext JS, LLC9* [email protected]10* http://www.extjs.com/license11*/12/**13* @class Ext.ux.StatusBar14* <p>Basic status bar component that can be used as the bottom toolbar of any {@link Ext.Panel}. In addition to15* supporting the standard {@link Ext.Toolbar} interface for adding buttons, menus and other items, the StatusBar16* provides a greedy status element that can be aligned to either side and has convenient methods for setting the17* status text and icon. You can also indicate that something is processing using the {@link #showBusy} method.</p>18* <pre><code>19new Ext.Panel({20title: 'StatusBar',21// etc.22bbar: new Ext.ux.StatusBar({23id: 'my-status',2425// defaults to use when the status is cleared:26defaultText: 'Default status text',27defaultIconCls: 'default-icon',2829// values to set initially:30text: 'Ready',31iconCls: 'ready-icon',3233// any standard Toolbar items:34items: [{35text: 'A Button'36}, '-', 'Plain Text']37})38});3940// Update the status bar later in code:41var sb = Ext.getCmp('my-status');42sb.setStatus({43text: 'OK',44iconCls: 'ok-icon',45clear: true // auto-clear after a set interval46});4748// Set the status bar to show that something is processing:49sb.showBusy();5051// processing....5253sb.clearStatus(); // once completeed54</code></pre>55* @extends Ext.Toolbar56* @constructor57* Creates a new StatusBar58* @param {Object/Array} config A config object59*/60Ext.ux.StatusBar = Ext.extend(Ext.Toolbar, {61/**62* @cfg {String} statusAlign63* 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 the65* StatusBar's {@link #items} config, or added via {@link #add} or any of the supported add* methods, will be66* rendered, in added order, to the opposite side. The status element is greedy, so it will automatically67* expand to take up all sapce left over by any other items. Example usage:68* <pre><code>69// Create a left-aligned status bar containing a button,70// separator and text item that will be right-aligned (default):71new Ext.Panel({72title: 'StatusBar',73// etc.74bbar: new Ext.ux.StatusBar({75defaultText: 'Default status text',76id: 'status-id',77items: [{78text: 'A Button'79}, '-', 'Plain Text']80})81});8283// By adding the statusAlign config, this will create the84// exact same toolbar, except the status and toolbar item85// layout will be reversed from the previous example:86new Ext.Panel({87title: 'StatusBar',88// etc.89bbar: new Ext.ux.StatusBar({90defaultText: 'Default status text',91id: 'status-id',92statusAlign: 'right',93items: [{94text: 'A Button'95}, '-', 'Plain Text']96})97});98</code></pre>99*/100/**101* @cfg {String} defaultText102* The default {@link #text} value. This will be used anytime the status bar is cleared with the103* <tt>useDefaults:true</tt> option (defaults to '').104*/105/**106* @cfg {String} defaultIconCls107* 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 '').109*/110/**111* @cfg {String} text112* A string that will be <b>initially</b> set as the status message. This string113* will be set as innerHTML (html tags are accepted) for the toolbar item.114* If not specified, the value set for <code>{@link #defaultText}</code>115* will be used.116*/117/**118* @cfg {String} iconCls119* A CSS class that will be <b>initially</b> set as the status bar icon and is120* expected to provide a background image (defaults to '').121* Example usage:<pre><code>122// Example CSS rule:123.x-statusbar .x-status-custom {124padding-left: 25px;125background: transparent url(images/custom-icon.gif) no-repeat 3px 2px;126}127128// Setting a default icon:129var sb = new Ext.ux.StatusBar({130defaultIconCls: 'x-status-custom'131});132133// Changing the icon:134sb.setStatus({135text: 'New status',136iconCls: 'x-status-custom'137});138</code></pre>139*/140141/**142* @cfg {String} cls143* The base class applied to the containing element for this component on render (defaults to 'x-statusbar')144*/145cls : 'x-statusbar',146/**147* @cfg {String} busyIconCls148* The default <code>{@link #iconCls}</code> applied when calling149* <code>{@link #showBusy}</code> (defaults to <tt>'x-status-busy'</tt>).150* It can be overridden at any time by passing the <code>iconCls</code>151* argument into <code>{@link #showBusy}</code>.152*/153busyIconCls : 'x-status-busy',154155//BEEF ADDED156errorIconCls : 'x-status-error',157validIconCls : 'x-status-valid',158159/**160* @cfg {String} busyText161* The default <code>{@link #text}</code> applied when calling162* <code>{@link #showBusy}</code> (defaults to <tt>'Loading...'</tt>).163* It can be overridden at any time by passing the <code>text</code>164* argument into <code>{@link #showBusy}</code>.165*/166busyText : 'Loading...',167/**168* @cfg {Number} autoClear169* The number of milliseconds to wait after setting the status via170* <code>{@link #setStatus}</code> before automatically clearing the status171* text and icon (defaults to <tt>5000</tt>). Note that this only applies172* when passing the <tt>clear</tt> argument to <code>{@link #setStatus}</code>173* since that is the only way to defer clearing the status. This can174* be overridden by specifying a different <tt>wait</tt> value in175* <code>{@link #setStatus}</code>. Calls to <code>{@link #clearStatus}</code>176* always clear the status bar immediately and ignore this value.177*/178autoClear : 5000,179180/**181* @cfg {String} emptyText182* The text string to use if no text has been set. Defaults to183* <tt>' '</tt>). If there are no other items in the toolbar using184* an empty string (<tt>''</tt>) for this value would end up in the toolbar185* height collapsing since the empty string will not maintain the toolbar186* height. Use <tt>''</tt> if the toolbar should collapse in height187* vertically when no text is specified and there are no other items in188* the toolbar.189*/190emptyText : ' ',191192// private193activeThreadId : 0,194195// private196initComponent : function(){197if(this.statusAlign=='right'){198this.cls += ' x-status-right';199}200Ext.ux.StatusBar.superclass.initComponent.call(this);201},202203// private204afterRender : function(){205Ext.ux.StatusBar.superclass.afterRender.call(this);206207var right = this.statusAlign == 'right';208this.currIconCls = this.iconCls || this.defaultIconCls;209this.statusEl = new Ext.Toolbar.TextItem({210cls: 'x-status-text ' + (this.currIconCls || ''),211text: this.text || this.defaultText || ''212});213214if(right){215this.add('->');216this.add(this.statusEl);217}else{218this.insert(0, this.statusEl);219this.insert(1, '->');220}221this.doLayout();222},223224/**225* Sets the status {@link #text} and/or {@link #iconCls}. Also supports automatically clearing the226* status that was set after a specified interval.227* @param {Object/String} config A config object specifying what status to set, or a string assumed228* to be the status text (and all other options are defaulted as explained below). A config229* object containing any or all of the following properties can be passed:<ul>230* <li><tt>text</tt> {String} : (optional) The status text to display. If not specified, any current231* status text will remain unchanged.</li>232* <li><tt>iconCls</tt> {String} : (optional) The CSS class used to customize the status icon (see233* {@link #iconCls} for details). If not specified, any current iconCls will remain unchanged.</li>234* <li><tt>clear</tt> {Boolean/Number/Object} : (optional) Allows you to set an internal callback that will235* automatically clear the status text and iconCls after a specified amount of time has passed. If clear is not236* specified, the new status will not be auto-cleared and will stay until updated again or cleared using237* {@link #clearStatus}. If <tt>true</tt> is passed, the status will be cleared using {@link #autoClear},238* {@link #defaultText} and {@link #defaultIconCls} via a fade out animation. If a numeric value is passed,239* it will be used as the callback interval (in milliseconds), overriding the {@link #autoClear} value.240* All other options will be defaulted as with the boolean option. To customize any other options,241* you can pass an object in the format:<ul>242* <li><tt>wait</tt> {Number} : (optional) The number of milliseconds to wait before clearing243* (defaults to {@link #autoClear}).</li>244* <li><tt>anim</tt> {Number} : (optional) False to clear the status immediately once the callback245* executes (defaults to true which fades the status out).</li>246* <li><tt>useDefaults</tt> {Number} : (optional) False to completely clear the status text and iconCls247* (defaults to true which uses {@link #defaultText} and {@link #defaultIconCls}).</li>248* </ul></li></ul>249* Example usage:<pre><code>250// Simple call to update the text251statusBar.setStatus('New status');252253// Set the status and icon, auto-clearing with default options:254statusBar.setStatus({255text: 'New status',256iconCls: 'x-status-custom',257clear: true258});259260// Auto-clear with custom options:261statusBar.setStatus({262text: 'New status',263iconCls: 'x-status-custom',264clear: {265wait: 8000,266anim: false,267useDefaults: false268}269});270</code></pre>271* @return {Ext.ux.StatusBar} this272*/273setStatus : function(o){274o = o || {};275276if(typeof o == 'string'){277o = {text:o};278}279if(o.text !== undefined){280this.setText(o.text);281}282if(o.iconCls !== undefined){283this.setIcon(o.iconCls);284}285286if(o.clear){287var c = o.clear,288wait = this.autoClear,289defaults = {useDefaults: true, anim: true};290291if(typeof c == 'object'){292c = Ext.applyIf(c, defaults);293if(c.wait){294wait = c.wait;295}296}else if(typeof c == 'number'){297wait = c;298c = defaults;299}else if(typeof c == 'boolean'){300c = defaults;301}302303c.threadId = this.activeThreadId;304this.clearStatus.defer(wait, this, [c]);305}306return this;307},308309/**310* Clears the status {@link #text} and {@link #iconCls}. Also supports clearing via an optional fade out animation.311* @param {Object} config (optional) A config object containing any or all of the following properties. If this312* object is not specified the status will be cleared using the defaults below:<ul>313* <li><tt>anim</tt> {Boolean} : (optional) True to clear the status by fading out the status element (defaults314* to false which clears immediately).</li>315* <li><tt>useDefaults</tt> {Boolean} : (optional) True to reset the text and icon using {@link #defaultText} and316* {@link #defaultIconCls} (defaults to false which sets the text to '' and removes any existing icon class).</li>317* </ul>318* @return {Ext.ux.StatusBar} this319*/320clearStatus : function(o){321o = o || {};322323if(o.threadId && o.threadId !== this.activeThreadId){324// this means the current call was made internally, but a newer325// thread has set a message since this call was deferred. Since326// we don't want to overwrite a newer message just ignore.327return this;328}329330var text = o.useDefaults ? this.defaultText : this.emptyText,331iconCls = o.useDefaults ? (this.defaultIconCls ? this.defaultIconCls : '') : '';332333if(o.anim){334// animate the statusEl Ext.Element335this.statusEl.el.fadeOut({336remove: false,337useDisplay: true,338scope: this,339callback: function(){340this.setStatus({341text: text,342iconCls: iconCls343});344345this.statusEl.el.show();346}347});348}else{349// hide/show the el to avoid jumpy text or icon350this.statusEl.hide();351this.setStatus({352text: text,353iconCls: iconCls354});355this.statusEl.show();356}357return this;358},359360/**361* Convenience method for setting the status text directly. For more flexible options see {@link #setStatus}.362* @param {String} text (optional) The text to set (defaults to '')363* @return {Ext.ux.StatusBar} this364*/365setText : function(text){366this.activeThreadId++;367this.text = text || '';368if(this.rendered){369this.statusEl.setText(this.text);370}371return this;372},373374/**375* Returns the current status text.376* @return {String} The status text377*/378getText : function(){379return this.text;380},381382/**383* Convenience method for setting the status icon directly. For more flexible options see {@link #setStatus}.384* See {@link #iconCls} for complete details about customizing the icon.385* @param {String} iconCls (optional) The icon class to set (defaults to '', and any current icon class is removed)386* @return {Ext.ux.StatusBar} this387*/388setIcon : function(cls){389this.activeThreadId++;390cls = cls || '';391392if(this.rendered){393if(this.currIconCls){394this.statusEl.removeClass(this.currIconCls);395this.currIconCls = null;396}397if(cls.length > 0){398this.statusEl.addClass(cls);399this.currIconCls = cls;400}401}else{402this.currIconCls = cls;403}404return this;405},406407/**408* Convenience method for setting the status text and icon to special values that are pre-configured to indicate409* a "busy" state, usually for loading or processing activities.410* @param {Object/String} config (optional) A config object in the same format supported by {@link #setStatus}, or a411* string to use as the status text (in which case all other options for setStatus will be defaulted). Use the412* <tt>text</tt> and/or <tt>iconCls</tt> properties on the config to override the default {@link #busyText}413* and {@link #busyIconCls} settings. If the config argument is not specified, {@link #busyText} and414* {@link #busyIconCls} will be used in conjunction with all of the default options for {@link #setStatus}.415* @return {Ext.ux.StatusBar} this416*/417showBusy : function(o){418if(typeof o == 'string'){419o = {text:o};420}421o = Ext.applyIf(o || {}, {422text: this.busyText,423iconCls: this.busyIconCls424});425return this.setStatus(o);426},427428//BEEF ADDED429showError : function(o){430if(typeof o == 'string'){431o = {text:o};432}433o = Ext.applyIf(o || {}, {434text: this.busyText,435iconCls: this.errorIconCls436});437return this.setStatus(o);438},439440showValid : function(o){441if(typeof o == 'string'){442o = {text:o};443}444o = Ext.applyIf(o || {}, {445text: this.busyText,446iconCls: this.validIconCls447});448return this.setStatus(o);449}450});451Ext.reg('statusbar', Ext.ux.StatusBar);452453