Installer/Updater
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

418 lines
15 KiB

​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. /*!
  2. * Ext JS Library 3.3.1
  3. * Copyright(c) 2006-2010 Sencha Inc.
  4. * licensing@sencha.com
  5. * http://www.sencha.com/license
  6. */
  7. /**
  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. * <pre><code>
  14. new Ext.Panel({
  15. title: 'StatusBar',
  16. // etc.
  17. bbar: new Ext.ux.StatusBar({
  18. id: 'my-status',
  19. // defaults to use when the status is cleared:
  20. defaultText: 'Default status text',
  21. defaultIconCls: 'default-icon',
  22. // values to set initially:
  23. text: 'Ready',
  24. iconCls: 'ready-icon',
  25. // any standard Toolbar items:
  26. items: [{
  27. text: 'A Button'
  28. }, '-', 'Plain Text']
  29. })
  30. });
  31. // Update the status bar later in code:
  32. var sb = Ext.getCmp('my-status');
  33. sb.setStatus({
  34. text: 'OK',
  35. iconCls: 'ok-icon',
  36. clear: true // auto-clear after a set interval
  37. });
  38. // Set the status bar to show that something is processing:
  39. sb.showBusy();
  40. // processing....
  41. sb.clearStatus(); // once completeed
  42. </code></pre>
  43. * @extends Ext.Toolbar
  44. * @constructor
  45. * Creates a new StatusBar
  46. * @param {Object/Array} config A config object
  47. */
  48. Ext.ux.StatusBar = Ext.extend(Ext.Toolbar, {
  49. /**
  50. * @cfg {String} statusAlign
  51. * The alignment of the status element within the overall StatusBar layout. When the StatusBar is rendered,
  52. * it creates an internal div containing the status text and icon. Any additional Toolbar items added in the
  53. * StatusBar's {@link #items} config, or added via {@link #add} or any of the supported add* methods, will be
  54. * rendered, in added order, to the opposite side. The status element is greedy, so it will automatically
  55. * expand to take up all sapce left over by any other items. Example usage:
  56. * <pre><code>
  57. // Create a left-aligned status bar containing a button,
  58. // separator and text item that will be right-aligned (default):
  59. new Ext.Panel({
  60. title: 'StatusBar',
  61. // etc.
  62. bbar: new Ext.ux.StatusBar({
  63. defaultText: 'Default status text',
  64. id: 'status-id',
  65. items: [{
  66. text: 'A Button'
  67. }, '-', 'Plain Text']
  68. })
  69. });
  70. // By adding the statusAlign config, this will create the
  71. // exact same toolbar, except the status and toolbar item
  72. // layout will be reversed from the previous example:
  73. new Ext.Panel({
  74. title: 'StatusBar',
  75. // etc.
  76. bbar: new Ext.ux.StatusBar({
  77. defaultText: 'Default status text',
  78. id: 'status-id',
  79. statusAlign: 'right',
  80. items: [{
  81. text: 'A Button'
  82. }, '-', 'Plain Text']
  83. })
  84. });
  85. </code></pre>
  86. */
  87. /**
  88. * @cfg {String} defaultText
  89. * The default {@link #text} value. This will be used anytime the status bar is cleared with the
  90. * <tt>useDefaults:true</tt> option (defaults to '').
  91. */
  92. /**
  93. * @cfg {String} defaultIconCls
  94. * The default {@link #iconCls} value (see the iconCls docs for additional details about customizing the icon).
  95. * This will be used anytime the status bar is cleared with the <tt>useDefaults:true</tt> option (defaults to '').
  96. */
  97. /**
  98. * @cfg {String} text
  99. * A string that will be <b>initially</b> set as the status message. This string
  100. * will be set as innerHTML (html tags are accepted) for the toolbar item.
  101. * If not specified, the value set for <code>{@link #defaultText}</code>
  102. * will be used.
  103. */
  104. /**
  105. * @cfg {String} iconCls
  106. * A CSS class that will be <b>initially</b> set as the status bar icon and is
  107. * expected to provide a background image (defaults to '').
  108. * Example usage:<pre><code>
  109. // Example CSS rule:
  110. .x-statusbar .x-status-custom {
  111. padding-left: 25px;
  112. background: transparent url(images/custom-icon.gif) no-repeat 3px 2px;
  113. }
  114. // Setting a default icon:
  115. var sb = new Ext.ux.StatusBar({
  116. defaultIconCls: 'x-status-custom'
  117. });
  118. // Changing the icon:
  119. sb.setStatus({
  120. text: 'New status',
  121. iconCls: 'x-status-custom'
  122. });
  123. </code></pre>
  124. */
  125. /**
  126. * @cfg {String} cls
  127. * The base class applied to the containing element for this component on render (defaults to 'x-statusbar')
  128. */
  129. cls : 'x-statusbar',
  130. /**
  131. * @cfg {String} busyIconCls
  132. * The default <code>{@link #iconCls}</code> applied when calling
  133. * <code>{@link #showBusy}</code> (defaults to <tt>'x-status-busy'</tt>).
  134. * It can be overridden at any time by passing the <code>iconCls</code>
  135. * argument into <code>{@link #showBusy}</code>.
  136. */
  137. busyIconCls : 'x-status-busy',
  138. /**
  139. * @cfg {String} busyText
  140. * The default <code>{@link #text}</code> applied when calling
  141. * <code>{@link #showBusy}</code> (defaults to <tt>'Loading...'</tt>).
  142. * It can be overridden at any time by passing the <code>text</code>
  143. * argument into <code>{@link #showBusy}</code>.
  144. */
  145. busyText : 'Loading...',
  146. /**
  147. * @cfg {Number} autoClear
  148. * The number of milliseconds to wait after setting the status via
  149. * <code>{@link #setStatus}</code> before automatically clearing the status
  150. * text and icon (defaults to <tt>5000</tt>). Note that this only applies
  151. * when passing the <tt>clear</tt> argument to <code>{@link #setStatus}</code>
  152. * since that is the only way to defer clearing the status. This can
  153. * be overridden by specifying a different <tt>wait</tt> value in
  154. * <code>{@link #setStatus}</code>. Calls to <code>{@link #clearStatus}</code>
  155. * always clear the status bar immediately and ignore this value.
  156. */
  157. autoClear : 5000,
  158. /**
  159. * @cfg {String} emptyText
  160. * The text string to use if no text has been set. Defaults to
  161. * <tt>'&nbsp;'</tt>). If there are no other items in the toolbar using
  162. * an empty string (<tt>''</tt>) for this value would end up in the toolbar
  163. * height collapsing since the empty string will not maintain the toolbar
  164. * height. Use <tt>''</tt> if the toolbar should collapse in height
  165. * vertically when no text is specified and there are no other items in
  166. * the toolbar.
  167. */
  168. emptyText : '&nbsp;',
  169. // private
  170. activeThreadId : 0,
  171. // private
  172. initComponent : function(){
  173. if(this.statusAlign=='right'){
  174. this.cls += ' x-status-right';
  175. }
  176. Ext.ux.StatusBar.superclass.initComponent.call(this);
  177. },
  178. // private
  179. afterRender : function(){
  180. Ext.ux.StatusBar.superclass.afterRender.call(this);
  181. var right = this.statusAlign == 'right';
  182. this.currIconCls = this.iconCls || this.defaultIconCls;
  183. this.statusEl = new Ext.Toolbar.TextItem({
  184. cls: 'x-status-text ' + (this.currIconCls || ''),
  185. text: this.text || this.defaultText || ''
  186. });
  187. if(right){
  188. this.add('->');
  189. this.add(this.statusEl);
  190. }else{
  191. this.insert(0, this.statusEl);
  192. this.insert(1, '->');
  193. }
  194. this.doLayout();
  195. },
  196. /**
  197. * Sets the status {@link #text} and/or {@link #iconCls}. Also supports automatically clearing the
  198. * status that was set after a specified interval.
  199. * @param {Object/String} config A config object specifying what status to set, or a string assumed
  200. * to be the status text (and all other options are defaulted as explained below). A config
  201. * object containing any or all of the following properties can be passed:<ul>
  202. * <li><tt>text</tt> {String} : (optional) The status text to display. If not specified, any current
  203. * status text will remain unchanged.</li>
  204. * <li><tt>iconCls</tt> {String} : (optional) The CSS class used to customize the status icon (see
  205. * {@link #iconCls} for details). If not specified, any current iconCls will remain unchanged.</li>
  206. * <li><tt>clear</tt> {Boolean/Number/Object} : (optional) Allows you to set an internal callback that will
  207. * automatically clear the status text and iconCls after a specified amount of time has passed. If clear is not
  208. * specified, the new status will not be auto-cleared and will stay until updated again or cleared using
  209. * {@link #clearStatus}. If <tt>true</tt> is passed, the status will be cleared using {@link #autoClear},
  210. * {@link #defaultText} and {@link #defaultIconCls} via a fade out animation. If a numeric value is passed,
  211. * it will be used as the callback interval (in milliseconds), overriding the {@link #autoClear} value.
  212. * All other options will be defaulted as with the boolean option. To customize any other options,
  213. * you can pass an object in the format:<ul>
  214. * <li><tt>wait</tt> {Number} : (optional) The number of milliseconds to wait before clearing
  215. * (defaults to {@link #autoClear}).</li>
  216. * <li><tt>anim</tt> {Number} : (optional) False to clear the status immediately once the callback
  217. * executes (defaults to true which fades the status out).</li>
  218. * <li><tt>useDefaults</tt> {Number} : (optional) False to completely clear the status text and iconCls
  219. * (defaults to true which uses {@link #defaultText} and {@link #defaultIconCls}).</li>
  220. * </ul></li></ul>
  221. * Example usage:<pre><code>
  222. // Simple call to update the text
  223. statusBar.setStatus('New status');
  224. // Set the status and icon, auto-clearing with default options:
  225. statusBar.setStatus({
  226. text: 'New status',
  227. iconCls: 'x-status-custom',
  228. clear: true
  229. });
  230. // Auto-clear with custom options:
  231. statusBar.setStatus({
  232. text: 'New status',
  233. iconCls: 'x-status-custom',
  234. clear: {
  235. wait: 8000,
  236. anim: false,
  237. useDefaults: false
  238. }
  239. });
  240. </code></pre>
  241. * @return {Ext.ux.StatusBar} this
  242. */
  243. setStatus : function(o){
  244. o = o || {};
  245. if(typeof o == 'string'){
  246. o = {text:o};
  247. }
  248. if(o.text !== undefined){
  249. this.setText(o.text);
  250. }
  251. if(o.iconCls !== undefined){
  252. this.setIcon(o.iconCls);
  253. }
  254. if(o.clear){
  255. var c = o.clear,
  256. wait = this.autoClear,
  257. defaults = {useDefaults: true, anim: true};
  258. if(typeof c == 'object'){
  259. c = Ext.applyIf(c, defaults);
  260. if(c.wait){
  261. wait = c.wait;
  262. }
  263. }else if(typeof c == 'number'){
  264. wait = c;
  265. c = defaults;
  266. }else if(typeof c == 'boolean'){
  267. c = defaults;
  268. }
  269. c.threadId = this.activeThreadId;
  270. this.clearStatus.defer(wait, this, [c]);
  271. }
  272. return this;
  273. },
  274. /**
  275. * Clears the status {@link #text} and {@link #iconCls}. Also supports clearing via an optional fade out animation.
  276. * @param {Object} config (optional) A config object containing any or all of the following properties. If this
  277. * object is not specified the status will be cleared using the defaults below:<ul>
  278. * <li><tt>anim</tt> {Boolean} : (optional) True to clear the status by fading out the status element (defaults
  279. * to false which clears immediately).</li>
  280. * <li><tt>useDefaults</tt> {Boolean} : (optional) True to reset the text and icon using {@link #defaultText} and
  281. * {@link #defaultIconCls} (defaults to false which sets the text to '' and removes any existing icon class).</li>
  282. * </ul>
  283. * @return {Ext.ux.StatusBar} this
  284. */
  285. clearStatus : function(o){
  286. o = o || {};
  287. if(o.threadId && o.threadId !== this.activeThreadId){
  288. // this means the current call was made internally, but a newer
  289. // thread has set a message since this call was deferred. Since
  290. // we don't want to overwrite a newer message just ignore.
  291. return this;
  292. }
  293. var text = o.useDefaults ? this.defaultText : this.emptyText,
  294. iconCls = o.useDefaults ? (this.defaultIconCls ? this.defaultIconCls : '') : '';
  295. if(o.anim){
  296. // animate the statusEl Ext.Element
  297. this.statusEl.el.fadeOut({
  298. remove: false,
  299. useDisplay: true,
  300. scope: this,
  301. callback: function(){
  302. this.setStatus({
  303. text: text,
  304. iconCls: iconCls
  305. });
  306. this.statusEl.el.show();
  307. }
  308. });
  309. }else{
  310. // hide/show the el to avoid jumpy text or icon
  311. this.statusEl.hide();
  312. this.setStatus({
  313. text: text,
  314. iconCls: iconCls
  315. });
  316. this.statusEl.show();
  317. }
  318. return this;
  319. },
  320. /**
  321. * Convenience method for setting the status text directly. For more flexible options see {@link #setStatus}.
  322. * @param {String} text (optional) The text to set (defaults to '')
  323. * @return {Ext.ux.StatusBar} this
  324. */
  325. setText : function(text){
  326. this.activeThreadId++;
  327. this.text = text || '';
  328. if(this.rendered){
  329. this.statusEl.setText(this.text);
  330. }
  331. return this;
  332. },
  333. /**
  334. * Returns the current status text.
  335. * @return {String} The status text
  336. */
  337. getText : function(){
  338. return this.text;
  339. },
  340. /**
  341. * Convenience method for setting the status icon directly. For more flexible options see {@link #setStatus}.
  342. * See {@link #iconCls} for complete details about customizing the icon.
  343. * @param {String} iconCls (optional) The icon class to set (defaults to '', and any current icon class is removed)
  344. * @return {Ext.ux.StatusBar} this
  345. */
  346. setIcon : function(cls){
  347. this.activeThreadId++;
  348. cls = cls || '';
  349. if(this.rendered){
  350. if(this.currIconCls){
  351. this.statusEl.removeClass(this.currIconCls);
  352. this.currIconCls = null;
  353. }
  354. if(cls.length > 0){
  355. this.statusEl.addClass(cls);
  356. this.currIconCls = cls;
  357. }
  358. }else{
  359. this.currIconCls = cls;
  360. }
  361. return this;
  362. },
  363. /**
  364. * Convenience method for setting the status text and icon to special values that are pre-configured to indicate
  365. * a "busy" state, usually for loading or processing activities.
  366. * @param {Object/String} config (optional) A config object in the same format supported by {@link #setStatus}, or a
  367. * string to use as the status text (in which case all other options for setStatus will be defaulted). Use the
  368. * <tt>text</tt> and/or <tt>iconCls</tt> properties on the config to override the default {@link #busyText}
  369. * and {@link #busyIconCls} settings. If the config argument is not specified, {@link #busyText} and
  370. * {@link #busyIconCls} will be used in conjunction with all of the default options for {@link #setStatus}.
  371. * @return {Ext.ux.StatusBar} this
  372. */
  373. showBusy : function(o){
  374. if(typeof o == 'string'){
  375. o = {text:o};
  376. }
  377. o = Ext.applyIf(o || {}, {
  378. text: this.busyText,
  379. iconCls: this.busyIconCls
  380. });
  381. return this.setStatus(o);
  382. }
  383. });
  384. Ext.reg('statusbar', Ext.ux.StatusBar);