menus.js 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269
  1. Ext.require([
  2. 'Ext.tip.QuickTipManager',
  3. 'Ext.menu.*',
  4. 'Ext.form.field.ComboBox',
  5. 'Ext.layout.container.Table',
  6. 'Ext.container.ButtonGroup'
  7. ]);
  8. Ext.onReady(function(){
  9. // functions to display feedback
  10. function onButtonClick(btn){
  11. Ext.example.msg('Button Click','You clicked the "{0}" button.', btn.text);
  12. }
  13. function onItemClick(item){
  14. Ext.example.msg('Menu Click', 'You clicked the "{0}" menu item.', item.text);
  15. }
  16. function onItemCheck(item, checked){
  17. Ext.example.msg('Item Check', 'You {1} the "{0}" menu item.', item.text, checked ? 'checked' : 'unchecked');
  18. }
  19. function onItemToggle(item, pressed){
  20. Ext.example.msg('Button Toggled', 'Button "{0}" was toggled to {1}.', item.text, pressed);
  21. }
  22. Ext.QuickTips.init();
  23. var dateMenu = Ext.create('Ext.menu.DatePicker', {
  24. handler: function(dp, date){
  25. Ext.example.msg('Date Selected', 'You choose {0}.', Ext.Date.format(date, 'M j, Y'));
  26. }
  27. });
  28. var colorMenu = Ext.create('Ext.menu.ColorPicker', {
  29. handler: function(cm, color){
  30. Ext.example.msg('Color Selected', '<span style="color:#' + color + ';">You choose {0}.</span>', color);
  31. }
  32. });
  33. var store = Ext.create('Ext.data.ArrayStore', {
  34. fields: ['abbr', 'state'],
  35. data : Ext.example.states
  36. });
  37. var combo = Ext.create('Ext.form.field.ComboBox', {
  38. hideLabel: true,
  39. store: store,
  40. displayField: 'state',
  41. typeAhead: true,
  42. queryMode: 'local',
  43. triggerAction: 'all',
  44. emptyText: 'Select a state...',
  45. selectOnFocus: true,
  46. width: 135,
  47. iconCls: 'no-icon'
  48. });
  49. var menu = Ext.create('Ext.menu.Menu', {
  50. id: 'mainMenu',
  51. style: {
  52. overflow: 'visible' // For the Combo popup
  53. },
  54. items: [
  55. combo, // A Field in a Menu
  56. {
  57. text: 'I like Ext',
  58. checked: true, // when checked has a boolean value, it is assumed to be a CheckItem
  59. checkHandler: onItemCheck
  60. }, '-', {
  61. text: 'Radio Options',
  62. menu: { // <-- submenu by nested config object
  63. items: [
  64. // stick any markup in a menu
  65. '<b class="menu-title">Choose a Theme</b>',
  66. {
  67. text: 'Aero Glass',
  68. checked: true,
  69. group: 'theme',
  70. checkHandler: onItemCheck
  71. }, {
  72. text: 'Vista Black',
  73. checked: false,
  74. group: 'theme',
  75. checkHandler: onItemCheck
  76. }, {
  77. text: 'Gray Theme',
  78. checked: false,
  79. group: 'theme',
  80. checkHandler: onItemCheck
  81. }, {
  82. text: 'Default Theme',
  83. checked: false,
  84. group: 'theme',
  85. checkHandler: onItemCheck
  86. }
  87. ]
  88. }
  89. },{
  90. text: 'Choose a Date',
  91. iconCls: 'calendar',
  92. menu: dateMenu // <-- submenu by reference
  93. },{
  94. text: 'Choose a Color',
  95. menu: colorMenu // <-- submenu by reference
  96. }
  97. ]
  98. });
  99. var tb = Ext.create('Ext.toolbar.Toolbar');
  100. tb.render('toolbar');
  101. tb.suspendLayouts();
  102. tb.add({
  103. text:'Button w/ Menu',
  104. iconCls: 'bmenu', // <-- icon
  105. menu: menu // assign menu by instance
  106. }, {
  107. text: 'Users',
  108. iconCls: 'user',
  109. menu: {
  110. xtype: 'menu',
  111. plain: true,
  112. items: {
  113. xtype: 'buttongroup',
  114. title: 'User options',
  115. columns: 2,
  116. defaults: {
  117. xtype: 'button',
  118. scale: 'large',
  119. iconAlign: 'left'
  120. },
  121. items: [{
  122. text: 'User<br/>manager',
  123. iconCls: 'edit',
  124. width: 90
  125. },{
  126. iconCls: 'add',
  127. tooltip: 'Add user',
  128. width: 40
  129. },{
  130. colspan: 2,
  131. text: 'Import',
  132. scale: 'small',
  133. width: 130
  134. },{
  135. colspan: 2,
  136. text: 'Who is online?',
  137. scale: 'small',
  138. width: 130
  139. }]
  140. }
  141. }
  142. },
  143. Ext.create('Ext.button.Split', {
  144. text: 'Split Button',
  145. handler: onButtonClick,
  146. tooltip: {text:'This is a an example QuickTip for a toolbar item', title:'Tip Title'},
  147. iconCls: 'blist',
  148. // Menus can be built/referenced by using nested menu config objects
  149. menu : {
  150. items: [{
  151. text: '<b>Bold</b>', handler: onItemClick
  152. }, {
  153. text: '<i>Italic</i>', handler: onItemClick
  154. }, {
  155. text: '<u>Underline</u>', handler: onItemClick
  156. }, '-', {
  157. text: 'Pick a Color',
  158. handler: onItemClick,
  159. menu: {
  160. showSeparator: false,
  161. items: [
  162. Ext.create('Ext.ColorPalette', {
  163. listeners: {
  164. select: function(cp, color){
  165. Ext.example.msg('Color Selected', 'You chose {0}.', color);
  166. }
  167. }
  168. }), '-',
  169. {
  170. text: 'More Colors...',
  171. handler: onItemClick
  172. }
  173. ]
  174. }
  175. }, {
  176. text: 'Extellent!',
  177. handler: onItemClick
  178. }]
  179. }
  180. }), '-', {
  181. text: 'Toggle Me',
  182. enableToggle: true,
  183. toggleHandler: onItemToggle,
  184. pressed: true
  185. });
  186. menu.add(' ');
  187. // Menus have a rich api for
  188. // adding and removing elements dynamically
  189. var item = menu.add({
  190. text: 'Dynamically added Item'
  191. });
  192. // items support full Observable API
  193. item.on('click', onItemClick);
  194. // items can easily be looked up
  195. menu.add({
  196. text: 'Disabled Item',
  197. id: 'disableMe' // <-- Items can also have an id for easy lookup
  198. // disabled: true <-- allowed but for sake of example we use long way below
  199. });
  200. // access items by id or index
  201. menu.items.get('disableMe').disable();
  202. // They can also be referenced by id in or components
  203. tb.add('-', {
  204. icon: 'list-items.gif', // icons can also be specified inline
  205. cls: 'x-btn-icon',
  206. tooltip: '<b>Quick Tips</b><br/>Icon only button with tooltip<br><b>Activated on mousedown</b>',
  207. clickEvent: 'mousedown',
  208. handler: function(){
  209. Ext.example.msg('Button Click','You clicked the "icon only" button.');
  210. }
  211. }, '-');
  212. var scrollMenu = Ext.create('Ext.menu.Menu');
  213. for (var i = 0; i < 50; ++i){
  214. scrollMenu.add({
  215. text: 'Item ' + (i + 1),
  216. handler: onItemClick
  217. });
  218. }
  219. // scrollable menu
  220. tb.add({
  221. icon: 'preview.png',
  222. cls: 'x-btn-text-icon',
  223. text: 'Scrolling Menu',
  224. menu: scrollMenu
  225. });
  226. tb.add({
  227. text: 'Link',
  228. url: 'http://www.google.com/search',
  229. baseParams: {
  230. q: 'html+anchor+tag'
  231. },
  232. tooltip: 'This is a link. You can right click. You can see where it will take you'
  233. });
  234. // add a combobox to the toolbar
  235. combo = Ext.create('Ext.form.field.ComboBox', {
  236. hideLabel: true,
  237. store: store,
  238. displayField: 'state',
  239. typeAhead: true,
  240. queryMode: 'local',
  241. triggerAction: 'all',
  242. emptyText:'Select a state...',
  243. selectOnFocus:true,
  244. width:135
  245. });
  246. tb.add(combo);
  247. tb.resumeLayouts(true);
  248. });