StatusBar.html 17 KB

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