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.

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