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.

262 lines
7.3 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.StartMenu
  17. * @extends Ext.menu.Menu
  18. * A start menu object.
  19. * @constructor
  20. * Creates a new StartMenu
  21. * @param {Object} config Configuration options
  22. *
  23. * SAMPLE USAGE:
  24. *
  25. * this.startMenu = new Ext.ux.StartMenu({
  26. * iconCls: 'user',
  27. * height: 300,
  28. * shadow: true,
  29. * title: get_cookie('memberName'),
  30. * width: 300
  31. * });
  32. *
  33. * this.startMenu.add({
  34. * text: 'Grid Window',
  35. * iconCls:'icon-grid',
  36. * handler : this.createWindow,
  37. * scope: this
  38. * });
  39. *
  40. * this.startMenu.addTool({
  41. * text:'Logout',
  42. * iconCls:'logout',
  43. * handler:function(){ window.location = "logout.php"; },
  44. * scope:this
  45. * });
  46. */
  47. Ext.namespace("Ext.ux");
  48. Ext.ux.StartMenu = Ext.extend(Ext.menu.Menu, {
  49. initComponent: function(config) {
  50. Ext.ux.StartMenu.superclass.initComponent.call(this, config);
  51. var tools = this.toolItems;
  52. this.toolItems = new Ext.util.MixedCollection();
  53. if(tools){
  54. this.addTool.apply(this, tools);
  55. }
  56. },
  57. // private
  58. onRender : function(ct, position){
  59. Ext.ux.StartMenu.superclass.onRender.call(this, ct, position);
  60. var el = this.el.addClass('ux-start-menu');
  61. var header = el.createChild({
  62. tag: "div",
  63. cls: "x-window-header x-unselectable x-panel-icon "+this.iconCls
  64. });
  65. this.header = header;
  66. var headerText = header.createChild({
  67. tag: "span",
  68. cls: "x-window-header-text"
  69. });
  70. var tl = header.wrap({
  71. cls: "ux-start-menu-tl"
  72. });
  73. var tr = header.wrap({
  74. cls: "ux-start-menu-tr"
  75. });
  76. var tc = header.wrap({
  77. cls: "ux-start-menu-tc"
  78. });
  79. this.menuBWrap = el.createChild({
  80. tag: "div",
  81. cls: "x-window-body x-border-layout-ct ux-start-menu-body"
  82. });
  83. var ml = this.menuBWrap.wrap({
  84. cls: "ux-start-menu-ml"
  85. });
  86. var mc = this.menuBWrap.wrap({
  87. cls: "x-window-mc ux-start-menu-bwrap"
  88. });
  89. this.menuPanel = this.menuBWrap.createChild({
  90. tag: "div",
  91. cls: "x-panel x-border-panel ux-start-menu-apps-panel"
  92. });
  93. this.toolsPanel = this.menuBWrap.createChild({
  94. tag: "div",
  95. cls: "x-panel x-border-panel ux-start-menu-tools-panel"
  96. });
  97. var bwrap = ml.wrap({cls: "x-window-bwrap"});
  98. var bc = bwrap.createChild({
  99. tag: "div",
  100. cls: "ux-start-menu-bc"
  101. });
  102. var bl = bc.wrap({
  103. cls: "ux-start-menu-bl x-panel-nofooter"
  104. });
  105. var br = bc.wrap({
  106. cls: "ux-start-menu-br"
  107. });
  108. this.ul.appendTo(this.menuPanel);
  109. var toolsUl = this.toolsPanel.createChild({
  110. tag: "ul",
  111. cls: "x-menu-list"
  112. });
  113. this.mon(toolsUl, 'click', this.onClick, this);
  114. this.mon(toolsUl, 'mouseover', this.onMouseOver, this);
  115. this.mon(toolsUl, 'mouseout', this.onMouseOut, this);
  116. this.items.each(function(item){
  117. item.parentMenu = this;
  118. }, this);
  119. this.toolItems.each(
  120. function(item){
  121. var li = document.createElement("li");
  122. li.className = "x-menu-list-item";
  123. toolsUl.dom.appendChild(li);
  124. item.render(li);
  125. item.parentMenu = this;
  126. }, this);
  127. this.toolsUl = toolsUl;
  128. this.menuBWrap.setStyle('position', 'relative');
  129. this.menuBWrap.setHeight(this.height - 28);
  130. this.menuPanel.setStyle({
  131. padding: '2px',
  132. position: 'absolute',
  133. overflow: 'auto'
  134. });
  135. this.toolsPanel.setStyle({
  136. padding: '2px 4px 2px 2px',
  137. position: 'absolute',
  138. overflow: 'auto'
  139. });
  140. this.setTitle(this.title);
  141. },
  142. // private
  143. findTargetItem : function(e){
  144. var t = e.getTarget(".x-menu-list-item", this.ul, true);
  145. if(t && t.menuItemId){
  146. if(this.items.get(t.menuItemId)){
  147. return this.items.get(t.menuItemId);
  148. }else{
  149. return this.toolItems.get(t.menuItemId);
  150. }
  151. }
  152. },
  153. /**
  154. * Displays this menu relative to another element
  155. * @param {Mixed} element The element to align to
  156. * @param {String} position (optional) The {@link Ext.Element#alignTo} anchor position to use in aligning to
  157. * the element (defaults to this.defaultAlign)
  158. * @param {Ext.ux.StartMenu} parentMenu (optional) This menu's parent menu, if applicable (defaults to undefined)
  159. */
  160. show : function(el, pos, parentMenu){
  161. this.parentMenu = parentMenu;
  162. if(!this.el){
  163. this.render();
  164. }
  165. this.fireEvent("beforeshow", this);
  166. this.showAt(this.el.getAlignToXY(el, pos || this.defaultAlign), parentMenu, false);
  167. var tPanelWidth = 100;
  168. var box = this.menuBWrap.getBox();
  169. this.menuPanel.setWidth(box.width-tPanelWidth);
  170. this.menuPanel.setHeight(box.height);
  171. this.toolsPanel.setWidth(tPanelWidth);
  172. this.toolsPanel.setX(box.x+box.width-tPanelWidth);
  173. this.toolsPanel.setHeight(box.height);
  174. },
  175. addTool : function(){
  176. var a = arguments, l = a.length, item;
  177. for(var i = 0; i < l; i++){
  178. var el = a[i];
  179. if(el.render){ // some kind of Item
  180. item = this.addToolItem(el);
  181. }else if(typeof el == "string"){ // string
  182. if(el == "separator" || el == "-"){
  183. item = this.addToolSeparator();
  184. }else{
  185. item = this.addText(el);
  186. }
  187. }else if(el.tagName || el.el){ // element
  188. item = this.addElement(el);
  189. }else if(typeof el == "object"){ // must be menu item config?
  190. item = this.addToolMenuItem(el);
  191. }
  192. }
  193. return item;
  194. },
  195. /**
  196. * Adds a separator bar to the Tools
  197. * @return {Ext.menu.Item} The menu item that was added
  198. */
  199. addToolSeparator : function(){
  200. return this.addToolItem(new Ext.menu.Separator({itemCls: 'ux-toolmenu-sep'}));
  201. },
  202. addToolItem : function(item){
  203. this.toolItems.add(item);
  204. if(this.ul){
  205. var li = document.createElement("li");
  206. li.className = "x-menu-list-item";
  207. this.ul.dom.appendChild(li);
  208. item.render(li, this);
  209. this.delayAutoWidth();
  210. }
  211. return item;
  212. },
  213. addToolMenuItem : function(config){
  214. if(!(config instanceof Ext.menu.Item)){
  215. if(typeof config.checked == "boolean"){ // must be check menu item config?
  216. config = new Ext.menu.CheckItem(config);
  217. }else{
  218. config = new Ext.menu.Item(config);
  219. }
  220. }
  221. return this.addToolItem(config);
  222. },
  223. setTitle : function(title, iconCls){
  224. this.title = title;
  225. this.header.child('span').update(title);
  226. return this;
  227. }
  228. });