statusbar-demo.js 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257
  1. Ext.Loader.setConfig({
  2. enabled: true
  3. });
  4. Ext.Loader.setPath('Ext.ux', '../ux/');
  5. Ext.require([
  6. 'Ext.panel.Panel',
  7. 'Ext.button.Button',
  8. 'Ext.window.Window',
  9. 'Ext.ux.statusbar.StatusBar',
  10. 'Ext.toolbar.TextItem',
  11. 'Ext.menu.Menu',
  12. 'Ext.toolbar.Spacer',
  13. 'Ext.button.Split',
  14. 'Ext.form.field.TextArea'
  15. ]);
  16. Ext.onReady(function(){
  17. // This is a shared function that simulates a load action on a StatusBar.
  18. // It is reused by most of the example panels.
  19. var loadFn = function(btn, statusBar){
  20. btn = Ext.getCmp(btn);
  21. statusBar = Ext.getCmp(statusBar);
  22. btn.disable();
  23. statusBar.showBusy();
  24. Ext.defer(function(){
  25. statusBar.clearStatus({useDefaults:true});
  26. btn.enable();
  27. }, 2000);
  28. };
  29. /*
  30. * ================ Basic StatusBar example =======================
  31. */
  32. Ext.create('Ext.Panel', {
  33. title: 'Basic StatusBar',
  34. renderTo: 'basic',
  35. width: 550,
  36. height: 100,
  37. bodyPadding: 10,
  38. items:[{
  39. xtype: 'button',
  40. id: 'basic-button',
  41. text: 'Do Loading',
  42. handler: Ext.Function.pass(loadFn, ['basic-button', 'basic-statusbar'])
  43. }],
  44. bbar: Ext.create('Ext.ux.StatusBar', {
  45. id: 'basic-statusbar',
  46. // defaults to use when the status is cleared:
  47. defaultText: 'Default status text',
  48. //defaultIconCls: 'default-icon',
  49. // values to set initially:
  50. text: 'Ready',
  51. iconCls: 'x-status-valid',
  52. // any standard Toolbar items:
  53. items: [
  54. {
  55. xtype: 'button',
  56. text: 'Show Warning & Clear',
  57. handler: function (){
  58. var sb = Ext.getCmp('basic-statusbar');
  59. sb.setStatus({
  60. text: 'Oops!',
  61. iconCls: 'x-status-error',
  62. clear: true // auto-clear after a set interval
  63. });
  64. }
  65. },
  66. {
  67. xtype: 'button',
  68. text: 'Show Busy',
  69. handler: function (){
  70. var sb = Ext.getCmp('basic-statusbar');
  71. // Set the status bar to show that something is processing:
  72. sb.showBusy();
  73. }
  74. },
  75. {
  76. xtype: 'button',
  77. text: 'Clear status',
  78. handler: function (){
  79. var sb = Ext.getCmp('basic-statusbar');
  80. // once completed
  81. sb.clearStatus();
  82. }
  83. },
  84. '-',
  85. 'Plain Text'
  86. ]
  87. })
  88. });
  89. /*
  90. * ================ Right-aligned StatusBar example =======================
  91. */
  92. Ext.create('Ext.Panel', {
  93. title: 'Right-aligned StatusBar',
  94. renderTo: 'right-aligned',
  95. width: 550,
  96. height: 100,
  97. bodyPadding: 10,
  98. items:[{
  99. xtype: 'button',
  100. id: 'right-button',
  101. text: 'Do Loading',
  102. handler: Ext.Function.pass(loadFn, ['right-button', 'right-statusbar'])
  103. }],
  104. bbar: Ext.create('Ext.ux.StatusBar', {
  105. defaultText: 'Default status',
  106. id: 'right-statusbar',
  107. statusAlign: 'right', // the magic config
  108. items: [{
  109. text: 'A Button'
  110. }, '-', 'Plain Text', ' ', ' ']
  111. })
  112. });
  113. /*
  114. * ================ StatusBar Window example =======================
  115. */
  116. var win = Ext.create('Ext.Window', {
  117. title: 'StatusBar Window',
  118. width: 400,
  119. minWidth: 350,
  120. height: 150,
  121. modal: true,
  122. closeAction: 'hide',
  123. bodyPadding: 10,
  124. items:[{
  125. xtype: 'button',
  126. id: 'win-button',
  127. text: 'Do Loading',
  128. handler: Ext.Function.pass(loadFn, ['win-button', 'win-statusbar'])
  129. }],
  130. bbar: Ext.create('Ext.ux.StatusBar', {
  131. id: 'win-statusbar',
  132. defaultText: 'Ready',
  133. items: [{
  134. xtype: 'button',
  135. text: 'A Button'
  136. }, '-',
  137. Ext.Date.format(new Date(), 'n/d/Y'), ' ', ' ', '-', {
  138. xtype:'splitbutton',
  139. text:'Status Menu',
  140. menuAlign: 'br-tr?',
  141. menu: Ext.create('Ext.menu.Menu', {
  142. items: [{text: 'Item 1'}, {text: 'Item 2'}]
  143. })
  144. }]
  145. })
  146. });
  147. Ext.create('Ext.Button', {
  148. text: 'Show Window',
  149. renderTo: 'window',
  150. handler: function(){
  151. win.show();
  152. }
  153. });
  154. /*
  155. * ================ Ext Word Processor example =======================
  156. *
  157. * The StatusBar used in this example is completely standard. What is
  158. * customized are the styles and event handling to make the example a
  159. * lot more dynamic and application-oriented.
  160. *
  161. */
  162. // Create these explicitly so we can manipulate them later
  163. var wordCount = Ext.create('Ext.toolbar.TextItem', {text: 'Words: 0'}),
  164. charCount = Ext.create('Ext.toolbar.TextItem', {text: 'Chars: 0'}),
  165. clock = Ext.create('Ext.toolbar.TextItem', {text: Ext.Date.format(new Date(), 'g:i:s A')}),
  166. event = Ext.isOpera ? 'keypress' : 'keydown'; // opera behaves a little weird with keydown
  167. Ext.create('Ext.Panel', {
  168. title: 'Ext Word Processor',
  169. renderTo: 'word-proc',
  170. width: 500,
  171. bodyPadding: 5,
  172. layout: 'fit',
  173. bbar: Ext.create('Ext.ux.StatusBar', {
  174. id: 'word-status',
  175. // These are just the standard toolbar TextItems we created above. They get
  176. // custom classes below in the render handler which is what gives them their
  177. // customized inset appearance.
  178. items: [wordCount, ' ', charCount, ' ', clock, ' ']
  179. }),
  180. items: {
  181. xtype: 'textarea',
  182. id: 'word-textarea',
  183. enableKeyEvents: true,
  184. hideLabel: true,
  185. grow: true,
  186. growMin: 100,
  187. growMax: 200
  188. },
  189. listeners: {
  190. render: {
  191. fn: function(){
  192. // Add a class to the parent TD of each text item so we can give them some custom inset box
  193. // styling. Also, since we are using a greedy spacer, we have to add a block level element
  194. // into each text TD in order to give them a fixed width (TextItems are spans). Insert a
  195. // spacer div into each TD using createChild() so that we can give it a width in CSS.
  196. Ext.fly(wordCount.getEl().parent()).addCls('x-status-text-panel').createChild({cls:'spacer'});
  197. Ext.fly(charCount.getEl().parent()).addCls('x-status-text-panel').createChild({cls:'spacer'});
  198. Ext.fly(clock.getEl().parent()).addCls('x-status-text-panel').createChild({cls:'spacer'});
  199. // Kick off the clock timer that updates the clock el every second:
  200. Ext.TaskManager.start({
  201. run: function(){
  202. Ext.fly(clock.getEl()).update(Ext.Date.format(new Date(), 'g:i:s A'));
  203. },
  204. interval: 1000
  205. });
  206. },
  207. delay: 100
  208. }
  209. }
  210. });
  211. // This sets up a fake auto-save function. It monitors keyboard activity and after no typing
  212. // has occurred for 1.5 seconds, it updates the status message to indicate that it's saving.
  213. // After a fake delay so that you can see the save activity it will update again to indicate
  214. // that the action succeeded.
  215. Ext.getCmp('word-textarea').on(event, function(){
  216. var sb = Ext.getCmp('word-status');
  217. sb.showBusy('Saving draft...');
  218. Ext.defer(function(){
  219. sb.setStatus({
  220. iconCls: 'x-status-saved',
  221. text: 'Draft auto-saved at ' + Ext.Date.format(new Date(), 'g:i:s A')
  222. });
  223. }, 4000);
  224. }, null, {buffer:1500});
  225. // Set up our event for updating the word/char count
  226. Ext.getCmp('word-textarea').on(event, function(comp){
  227. var v = comp.getValue(),
  228. wc = 0,
  229. cc = v.length ? v.length : 0;
  230. if (cc > 0) {
  231. wc = v.match(/\b/g);
  232. wc = wc ? wc.length / 2 : 0;
  233. }
  234. wordCount.update('Words: ' + wc);
  235. charCount.update('Chars: ' + cc);
  236. }, null, {buffer: 1});
  237. });