TaskBar.js 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262
  1. /*!
  2. * Ext JS Library 4.0
  3. * Copyright(c) 2006-2011 Sencha Inc.
  4. * licensing@sencha.com
  5. * http://www.sencha.com/license
  6. */
  7. /**
  8. * @class Ext.ux.desktop.TaskBar
  9. * @extends Ext.toolbar.Toolbar
  10. */
  11. Ext.define('Ext.ux.desktop.TaskBar', {
  12. extend: 'Ext.toolbar.Toolbar', // TODO - make this a basic hbox panel...
  13. requires: [
  14. 'Ext.button.Button',
  15. 'Ext.resizer.Splitter',
  16. 'Ext.menu.Menu',
  17. 'Ext.ux.desktop.StartMenu'
  18. ],
  19. alias: 'widget.taskbar',
  20. cls: 'ux-taskbar',
  21. /**
  22. * @cfg {String} startBtnText
  23. * The text for the Start Button.
  24. */
  25. startBtnText: 'Start',
  26. initComponent: function () {
  27. var me = this;
  28. me.startMenu = new Ext.ux.desktop.StartMenu(me.startConfig);
  29. me.quickStart = new Ext.toolbar.Toolbar(me.getQuickStart());
  30. me.windowBar = new Ext.toolbar.Toolbar(me.getWindowBarConfig());
  31. me.tray = new Ext.toolbar.Toolbar(me.getTrayConfig());
  32. me.items = [
  33. {
  34. xtype: 'button',
  35. cls: 'ux-start-button',
  36. iconCls: 'ux-start-button-icon',
  37. menu: me.startMenu,
  38. menuAlign: 'bl-tl',
  39. text: me.startBtnText
  40. },
  41. me.quickStart,
  42. {
  43. xtype: 'splitter', html: ' ',
  44. height: 14, width: 2, // TODO - there should be a CSS way here
  45. cls: 'x-toolbar-separator x-toolbar-separator-horizontal'
  46. },
  47. //'-',
  48. me.windowBar,
  49. '-',
  50. me.tray
  51. ];
  52. me.callParent();
  53. },
  54. afterLayout: function () {
  55. var me = this;
  56. me.callParent();
  57. me.windowBar.el.on('contextmenu', me.onButtonContextMenu, me);
  58. },
  59. /**
  60. * This method returns the configuration object for the Quick Start toolbar. A derived
  61. * class can override this method, call the base version to build the config and
  62. * then modify the returned object before returning it.
  63. */
  64. getQuickStart: function () {
  65. var me = this, ret = {
  66. minWidth: 20,
  67. width: 60,
  68. items: [],
  69. enableOverflow: true
  70. };
  71. Ext.each(this.quickStart, function (item) {
  72. ret.items.push({
  73. tooltip: { text: item.name, align: 'bl-tl' },
  74. //tooltip: item.name,
  75. overflowText: item.name,
  76. iconCls: item.iconCls,
  77. module: item.module,
  78. handler: me.onQuickStartClick,
  79. scope: me
  80. });
  81. });
  82. return ret;
  83. },
  84. /**
  85. * This method returns the configuration object for the Tray toolbar. A derived
  86. * class can override this method, call the base version to build the config and
  87. * then modify the returned object before returning it.
  88. */
  89. getTrayConfig: function () {
  90. var ret = {
  91. width: 80,
  92. items: this.trayItems
  93. };
  94. delete this.trayItems;
  95. return ret;
  96. },
  97. getWindowBarConfig: function () {
  98. return {
  99. flex: 1,
  100. cls: 'ux-desktop-windowbar',
  101. items: [ ' ' ],
  102. layout: { overflowHandler: 'Scroller' }
  103. };
  104. },
  105. getWindowBtnFromEl: function (el) {
  106. var c = this.windowBar.getChildByElement(el);
  107. return c || null;
  108. },
  109. onQuickStartClick: function (btn) {
  110. var module = this.app.getModule(btn.module),
  111. window;
  112. if (module) {
  113. window = module.createWindow();
  114. window.show();
  115. }
  116. },
  117. onButtonContextMenu: function (e) {
  118. var me = this, t = e.getTarget(), btn = me.getWindowBtnFromEl(t);
  119. if (btn) {
  120. e.stopEvent();
  121. me.windowMenu.theWin = btn.win;
  122. me.windowMenu.showBy(t);
  123. }
  124. },
  125. onWindowBtnClick: function (btn) {
  126. var win = btn.win;
  127. if (win.minimized || win.hidden) {
  128. win.show();
  129. } else if (win.active) {
  130. win.minimize();
  131. } else {
  132. win.toFront();
  133. }
  134. },
  135. addTaskButton: function(win) {
  136. var config = {
  137. iconCls: win.iconCls,
  138. enableToggle: true,
  139. toggleGroup: 'all',
  140. width: 140,
  141. margins: '0 2 0 3',
  142. text: Ext.util.Format.ellipsis(win.title, 20),
  143. listeners: {
  144. click: this.onWindowBtnClick,
  145. scope: this
  146. },
  147. win: win
  148. };
  149. var cmp = this.windowBar.add(config);
  150. cmp.toggle(true);
  151. return cmp;
  152. },
  153. removeTaskButton: function (btn) {
  154. var found, me = this;
  155. me.windowBar.items.each(function (item) {
  156. if (item === btn) {
  157. found = item;
  158. }
  159. return !found;
  160. });
  161. if (found) {
  162. me.windowBar.remove(found);
  163. }
  164. return found;
  165. },
  166. setActiveButton: function(btn) {
  167. if (btn) {
  168. btn.toggle(true);
  169. } else {
  170. this.windowBar.items.each(function (item) {
  171. if (item.isButton) {
  172. item.toggle(false);
  173. }
  174. });
  175. }
  176. }
  177. });
  178. /**
  179. * @class Ext.ux.desktop.TrayClock
  180. * @extends Ext.toolbar.TextItem
  181. * This class displays a clock on the toolbar.
  182. */
  183. Ext.define('Ext.ux.desktop.TrayClock', {
  184. extend: 'Ext.toolbar.TextItem',
  185. alias: 'widget.trayclock',
  186. cls: 'ux-desktop-trayclock',
  187. html: ' ',
  188. timeFormat: 'g:i A',
  189. tpl: '{time}',
  190. initComponent: function () {
  191. var me = this;
  192. me.callParent();
  193. if (typeof(me.tpl) == 'string') {
  194. me.tpl = new Ext.XTemplate(me.tpl);
  195. }
  196. },
  197. afterRender: function () {
  198. var me = this;
  199. Ext.Function.defer(me.updateTime, 100, me);
  200. me.callParent();
  201. },
  202. onDestroy: function () {
  203. var me = this;
  204. if (me.timer) {
  205. window.clearTimeout(me.timer);
  206. me.timer = null;
  207. }
  208. me.callParent();
  209. },
  210. updateTime: function () {
  211. var me = this, time = Ext.Date.format(new Date(), me.timeFormat),
  212. text = me.tpl.apply({ time: time });
  213. if (me.lastText != text) {
  214. me.setText(text);
  215. me.lastText = text;
  216. }
  217. me.timer = Ext.Function.defer(me.updateTime, 10000, me);
  218. }
  219. });