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.

486 lines
14 KiB

2 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. /*
  2. This file is part of Ext JS 3.4
  3. Copyright (c) 2011-2013 Sencha Inc
  4. Contact: http://www.sencha.com/contact
  5. GNU General Public License Usage
  6. This file may be used under the terms of the GNU General Public License version 3.0 as
  7. published by the Free Software Foundation and appearing in the file LICENSE included in the
  8. packaging of this file.
  9. Please review the following information to ensure the GNU General Public License version 3.0
  10. requirements will be met: http://www.gnu.org/copyleft/gpl.html.
  11. If you are unsure which license is appropriate for your use, please contact the sales department
  12. at http://www.sencha.com/contact.
  13. Build date: 2013-04-03 15:07:25
  14. */
  15. /**
  16. * @class Ext.ux.TaskBar
  17. * @extends Ext.util.Observable
  18. */
  19. Ext.ux.TaskBar = function(app){
  20. this.app = app;
  21. this.init();
  22. }
  23. Ext.extend(Ext.ux.TaskBar, Ext.util.Observable, {
  24. init : function(){
  25. this.startMenu = new Ext.ux.StartMenu(Ext.apply({
  26. iconCls: 'user',
  27. height: 300,
  28. shadow: true,
  29. title: 'Jack Slocum',
  30. width: 300
  31. }, this.app.startConfig));
  32. this.startBtn = new Ext.Button({
  33. text: 'Start',
  34. id: 'ux-startbutton',
  35. iconCls:'start',
  36. menu: this.startMenu,
  37. menuAlign: 'bl-tl',
  38. renderTo: 'ux-taskbar-start',
  39. clickEvent: 'mousedown',
  40. template: new Ext.Template(
  41. '<table cellspacing="0" class="x-btn"><tbody class="{1}"><tr>',
  42. '<td class="ux-startbutton-left"><i>&#160;</i></td>',
  43. '<td class="ux-startbutton-center"><em class="{2} unselectable="on">',
  44. '<button class="x-btn-text" type="{0}" style="height:30px;"></button>',
  45. '</em></td>',
  46. '<td class="ux-startbutton-right"><i>&#160;</i></td>',
  47. '</tr></tbody></table>')
  48. });
  49. var width = this.startBtn.getEl().getWidth()+10;
  50. var sbBox = new Ext.BoxComponent({
  51. el: 'ux-taskbar-start',
  52. id: 'TaskBarStart',
  53. minWidth: width,
  54. region:'west',
  55. split: true,
  56. width: width
  57. });
  58. this.tbPanel = new Ext.ux.TaskButtonsPanel({
  59. el: 'ux-taskbuttons-panel',
  60. id: 'TaskBarButtons',
  61. region:'center'
  62. });
  63. var container = new Ext.ux.TaskBarContainer({
  64. el: 'ux-taskbar',
  65. layout: 'border',
  66. items: [sbBox,this.tbPanel]
  67. });
  68. return this;
  69. },
  70. addTaskButton : function(win){
  71. return this.tbPanel.addButton(win, 'ux-taskbuttons-panel');
  72. },
  73. removeTaskButton : function(btn){
  74. this.tbPanel.removeButton(btn);
  75. },
  76. setActiveButton : function(btn){
  77. this.tbPanel.setActiveButton(btn);
  78. }
  79. });
  80. /**
  81. * @class Ext.ux.TaskBarContainer
  82. * @extends Ext.Container
  83. */
  84. Ext.ux.TaskBarContainer = Ext.extend(Ext.Container, {
  85. initComponent : function() {
  86. Ext.ux.TaskBarContainer.superclass.initComponent.call(this);
  87. this.el = Ext.get(this.el) || Ext.getBody();
  88. this.el.setHeight = Ext.emptyFn;
  89. this.el.setWidth = Ext.emptyFn;
  90. this.el.setSize = Ext.emptyFn;
  91. this.el.setStyle({
  92. overflow:'hidden',
  93. margin:'0',
  94. border:'0 none'
  95. });
  96. this.el.dom.scroll = 'no';
  97. this.allowDomMove = false;
  98. this.autoWidth = true;
  99. this.autoHeight = true;
  100. Ext.EventManager.onWindowResize(this.fireResize, this);
  101. this.renderTo = this.el;
  102. },
  103. fireResize : function(w, h){
  104. this.onResize(w, h, w, h);
  105. this.fireEvent('resize', this, w, h, w, h);
  106. }
  107. });
  108. /**
  109. * @class Ext.ux.TaskButtonsPanel
  110. * @extends Ext.BoxComponent
  111. */
  112. Ext.ux.TaskButtonsPanel = Ext.extend(Ext.BoxComponent, {
  113. activeButton: null,
  114. enableScroll: true,
  115. scrollIncrement: 0,
  116. scrollRepeatInterval: 400,
  117. scrollDuration: .35,
  118. animScroll: true,
  119. resizeButtons: true,
  120. buttonWidth: 168,
  121. minButtonWidth: 118,
  122. buttonMargin: 2,
  123. buttonWidthSet: false,
  124. initComponent : function() {
  125. Ext.ux.TaskButtonsPanel.superclass.initComponent.call(this);
  126. this.on('resize', this.delegateUpdates);
  127. this.items = [];
  128. this.stripWrap = Ext.get(this.el).createChild({
  129. cls: 'ux-taskbuttons-strip-wrap',
  130. cn: {
  131. tag:'ul', cls:'ux-taskbuttons-strip'
  132. }
  133. });
  134. this.stripSpacer = Ext.get(this.el).createChild({
  135. cls:'ux-taskbuttons-strip-spacer'
  136. });
  137. this.strip = new Ext.Element(this.stripWrap.dom.firstChild);
  138. this.edge = this.strip.createChild({
  139. tag:'li',
  140. cls:'ux-taskbuttons-edge'
  141. });
  142. this.strip.createChild({
  143. cls:'x-clear'
  144. });
  145. },
  146. addButton : function(win){
  147. var li = this.strip.createChild({tag:'li'}, this.edge); // insert before the edge
  148. var btn = new Ext.ux.TaskBar.TaskButton(win, li);
  149. this.items.push(btn);
  150. if(!this.buttonWidthSet){
  151. this.lastButtonWidth = btn.container.getWidth();
  152. }
  153. this.setActiveButton(btn);
  154. return btn;
  155. },
  156. removeButton : function(btn){
  157. var li = document.getElementById(btn.container.id);
  158. btn.destroy();
  159. li.parentNode.removeChild(li);
  160. var s = [];
  161. for(var i = 0, len = this.items.length; i < len; i++) {
  162. if(this.items[i] != btn){
  163. s.push(this.items[i]);
  164. }
  165. }
  166. this.items = s;
  167. this.delegateUpdates();
  168. },
  169. setActiveButton : function(btn){
  170. this.activeButton = btn;
  171. this.delegateUpdates();
  172. },
  173. delegateUpdates : function(){
  174. /*if(this.suspendUpdates){
  175. return;
  176. }*/
  177. if(this.resizeButtons && this.rendered){
  178. this.autoSize();
  179. }
  180. if(this.enableScroll && this.rendered){
  181. this.autoScroll();
  182. }
  183. },
  184. autoSize : function(){
  185. var count = this.items.length;
  186. var ow = this.el.dom.offsetWidth;
  187. var aw = this.el.dom.clientWidth;
  188. if(!this.resizeButtons || count < 1 || !aw){ // !aw for display:none
  189. return;
  190. }
  191. var each = Math.max(Math.min(Math.floor((aw-4) / count) - this.buttonMargin, this.buttonWidth), this.minButtonWidth); // -4 for float errors in IE
  192. var btns = this.stripWrap.dom.getElementsByTagName('button');
  193. this.lastButtonWidth = Ext.get(btns[0].id).findParent('li').offsetWidth;
  194. for(var i = 0, len = btns.length; i < len; i++) {
  195. var btn = btns[i];
  196. var tw = Ext.get(btns[i].id).findParent('li').offsetWidth;
  197. var iw = btn.offsetWidth;
  198. btn.style.width = (each - (tw-iw)) + 'px';
  199. }
  200. },
  201. autoScroll : function(){
  202. var count = this.items.length;
  203. var ow = this.el.dom.offsetWidth;
  204. var tw = this.el.dom.clientWidth;
  205. var wrap = this.stripWrap;
  206. var cw = wrap.dom.offsetWidth;
  207. var pos = this.getScrollPos();
  208. var l = this.edge.getOffsetsTo(this.stripWrap)[0] + pos;
  209. if(!this.enableScroll || count < 1 || cw < 20){ // 20 to prevent display:none issues
  210. return;
  211. }
  212. wrap.setWidth(tw); // moved to here because of problem in Safari
  213. if(l <= tw){
  214. wrap.dom.scrollLeft = 0;
  215. //wrap.setWidth(tw); moved from here because of problem in Safari
  216. if(this.scrolling){
  217. this.scrolling = false;
  218. this.el.removeClass('x-taskbuttons-scrolling');
  219. this.scrollLeft.hide();
  220. this.scrollRight.hide();
  221. }
  222. }else{
  223. if(!this.scrolling){
  224. this.el.addClass('x-taskbuttons-scrolling');
  225. }
  226. tw -= wrap.getMargins('lr');
  227. wrap.setWidth(tw > 20 ? tw : 20);
  228. if(!this.scrolling){
  229. if(!this.scrollLeft){
  230. this.createScrollers();
  231. }else{
  232. this.scrollLeft.show();
  233. this.scrollRight.show();
  234. }
  235. }
  236. this.scrolling = true;
  237. if(pos > (l-tw)){ // ensure it stays within bounds
  238. wrap.dom.scrollLeft = l-tw;
  239. }else{ // otherwise, make sure the active button is still visible
  240. this.scrollToButton(this.activeButton, true); // true to animate
  241. }
  242. this.updateScrollButtons();
  243. }
  244. },
  245. createScrollers : function(){
  246. var h = this.el.dom.offsetHeight; //var h = this.stripWrap.dom.offsetHeight;
  247. // left
  248. var sl = this.el.insertFirst({
  249. cls:'ux-taskbuttons-scroller-left'
  250. });
  251. sl.setHeight(h);
  252. sl.addClassOnOver('ux-taskbuttons-scroller-left-over');
  253. this.leftRepeater = new Ext.util.ClickRepeater(sl, {
  254. interval : this.scrollRepeatInterval,
  255. handler: this.onScrollLeft,
  256. scope: this
  257. });
  258. this.scrollLeft = sl;
  259. // right
  260. var sr = this.el.insertFirst({
  261. cls:'ux-taskbuttons-scroller-right'
  262. });
  263. sr.setHeight(h);
  264. sr.addClassOnOver('ux-taskbuttons-scroller-right-over');
  265. this.rightRepeater = new Ext.util.ClickRepeater(sr, {
  266. interval : this.scrollRepeatInterval,
  267. handler: this.onScrollRight,
  268. scope: this
  269. });
  270. this.scrollRight = sr;
  271. },
  272. getScrollWidth : function(){
  273. return this.edge.getOffsetsTo(this.stripWrap)[0] + this.getScrollPos();
  274. },
  275. getScrollPos : function(){
  276. return parseInt(this.stripWrap.dom.scrollLeft, 10) || 0;
  277. },
  278. getScrollArea : function(){
  279. return parseInt(this.stripWrap.dom.clientWidth, 10) || 0;
  280. },
  281. getScrollAnim : function(){
  282. return {
  283. duration: this.scrollDuration,
  284. callback: this.updateScrollButtons,
  285. scope: this
  286. };
  287. },
  288. getScrollIncrement : function(){
  289. return (this.scrollIncrement || this.lastButtonWidth+2);
  290. },
  291. /* getBtnEl : function(item){
  292. return document.getElementById(item.id);
  293. }, */
  294. scrollToButton : function(item, animate){
  295. item = item.el.dom.parentNode; // li
  296. if(!item){ return; }
  297. var el = item; //this.getBtnEl(item);
  298. var pos = this.getScrollPos(), area = this.getScrollArea();
  299. var left = Ext.fly(el).getOffsetsTo(this.stripWrap)[0] + pos;
  300. var right = left + el.offsetWidth;
  301. if(left < pos){
  302. this.scrollTo(left, animate);
  303. }else if(right > (pos + area)){
  304. this.scrollTo(right - area, animate);
  305. }
  306. },
  307. scrollTo : function(pos, animate){
  308. this.stripWrap.scrollTo('left', pos, animate ? this.getScrollAnim() : false);
  309. if(!animate){
  310. this.updateScrollButtons();
  311. }
  312. },
  313. onScrollRight : function(){
  314. var sw = this.getScrollWidth()-this.getScrollArea();
  315. var pos = this.getScrollPos();
  316. var s = Math.min(sw, pos + this.getScrollIncrement());
  317. if(s != pos){
  318. this.scrollTo(s, this.animScroll);
  319. }
  320. },
  321. onScrollLeft : function(){
  322. var pos = this.getScrollPos();
  323. var s = Math.max(0, pos - this.getScrollIncrement());
  324. if(s != pos){
  325. this.scrollTo(s, this.animScroll);
  326. }
  327. },
  328. updateScrollButtons : function(){
  329. var pos = this.getScrollPos();
  330. this.scrollLeft[pos == 0 ? 'addClass' : 'removeClass']('ux-taskbuttons-scroller-left-disabled');
  331. this.scrollRight[pos >= (this.getScrollWidth()-this.getScrollArea()) ? 'addClass' : 'removeClass']('ux-taskbuttons-scroller-right-disabled');
  332. }
  333. });
  334. /**
  335. * @class Ext.ux.TaskBar.TaskButton
  336. * @extends Ext.Button
  337. */
  338. Ext.ux.TaskBar.TaskButton = function(win, el){
  339. this.win = win;
  340. Ext.ux.TaskBar.TaskButton.superclass.constructor.call(this, {
  341. iconCls: win.iconCls,
  342. text: Ext.util.Format.ellipsis(win.title, 12),
  343. renderTo: el,
  344. handler : function(){
  345. if(win.minimized || win.hidden){
  346. win.show();
  347. }else if(win == win.manager.getActive()){
  348. win.minimize();
  349. }else{
  350. win.toFront();
  351. }
  352. },
  353. clickEvent:'mousedown',
  354. template: new Ext.Template(
  355. '<table cellspacing="0" class="x-btn {3}"><tbody><tr>',
  356. '<td class="ux-taskbutton-left"><i>&#160;</i></td>',
  357. '<td class="ux-taskbutton-center"><em class="{5} unselectable="on">',
  358. '<button class="x-btn-text {2}" type="{1}" style="height:28px;">{0}</button>',
  359. '</em></td>',
  360. '<td class="ux-taskbutton-right"><i>&#160;</i></td>',
  361. "</tr></tbody></table>")
  362. });
  363. };
  364. Ext.extend(Ext.ux.TaskBar.TaskButton, Ext.Button, {
  365. onRender : function(){
  366. Ext.ux.TaskBar.TaskButton.superclass.onRender.apply(this, arguments);
  367. this.cmenu = new Ext.menu.Menu({
  368. items: [{
  369. text: 'Restore',
  370. handler: function(){
  371. if(!this.win.isVisible()){
  372. this.win.show();
  373. }else{
  374. this.win.restore();
  375. }
  376. },
  377. scope: this
  378. },{
  379. text: 'Minimize',
  380. handler: this.win.minimize,
  381. scope: this.win
  382. },{
  383. text: 'Maximize',
  384. handler: this.win.maximize,
  385. scope: this.win
  386. }, '-', {
  387. text: 'Close',
  388. handler: this.closeWin.createDelegate(this, this.win, true),
  389. scope: this.win
  390. }]
  391. });
  392. this.cmenu.on('beforeshow', function(){
  393. var items = this.cmenu.items.items;
  394. var w = this.win;
  395. items[0].setDisabled(w.maximized !== true && w.hidden !== true);
  396. items[1].setDisabled(w.minimized === true);
  397. items[2].setDisabled(w.maximized === true || w.hidden === true);
  398. }, this);
  399. this.el.on('contextmenu', function(e){
  400. e.stopEvent();
  401. if(!this.cmenu.el){
  402. this.cmenu.render();
  403. }
  404. var xy = e.getXY();
  405. xy[1] -= this.cmenu.el.getHeight();
  406. this.cmenu.showAt(xy);
  407. }, this);
  408. },
  409. closeWin : function(cMenu, e, win){
  410. if(!win.isVisible()){
  411. win.show();
  412. }else{
  413. win.restore();
  414. }
  415. win.close();
  416. }
  417. });