3 // TODO: The "Users" menu containing buttons is completely screwed: ButtonGroup needs work.
5 Ext.onReady(function(){
8 var dateMenu = Ext.create('Ext.menu.DatePicker', {
9 handler: function(dp, date){
10 Ext.example.msg('Date Selected', 'You choose {0}.', Ext.Date.format(date, 'M j, Y'));
15 var colorMenu = Ext.create('Ext.menu.ColorPicker', {
16 handler: function(cm, color){
17 Ext.example.msg('Color Selected', '<span style="color:#' + color + ';">You choose {0}.</span>', color);
21 var store = Ext.create('Ext.data.ArrayStore', {
22 fields: ['abbr', 'state'],
23 data : Ext.example.states
26 var combo = Ext.create('Ext.form.field.ComboBox', {
29 displayField: 'state',
33 emptyText: 'Select a state...',
39 var menu = Ext.create('Ext.menu.Menu', {
42 overflow: 'visible' // For the Combo popup
45 combo, // A Field in a Menu
48 checked: true, // when checked has a boolean value, it is assumed to be a CheckItem
49 checkHandler: onItemCheck
51 text: 'Radio Options',
52 menu: { // <-- submenu by nested config object
54 // stick any markup in a menu
55 '<b class="menu-title">Choose a Theme</b>',
60 checkHandler: onItemCheck
65 checkHandler: onItemCheck
70 checkHandler: onItemCheck
72 text: 'Default Theme',
75 checkHandler: onItemCheck
80 text: 'Choose a Date',
82 menu: dateMenu // <-- submenu by reference
84 text: 'Choose a Color',
85 menu: colorMenu // <-- submenu by reference
90 var tb = Ext.create('Ext.toolbar.Toolbar');
91 tb.suspendLayout = true;
95 text:'Button w/ Menu',
96 iconCls: 'bmenu', // <-- icon
97 menu: menu // assign menu by instance
105 xtype: 'buttongroup',
106 title: 'User options',
114 text: 'User<br/>manager',
129 text: 'Who is online?',
136 Ext.create('Ext.button.Split', {
137 text: 'Split Button',
138 handler: onButtonClick,
139 tooltip: {text:'This is a an example QuickTip for a toolbar item', title:'Tip Title'},
141 // Menus can be built/referenced by using nested menu config objects
144 text: '<b>Bold</b>', handler: onItemClick
146 text: '<i>Italic</i>', handler: onItemClick
148 text: '<u>Underline</u>', handler: onItemClick
150 text: 'Pick a Color',
151 handler: onItemClick,
153 showSeparator: false,
155 Ext.create('Ext.ColorPalette', {
157 select: function(cp, color){
158 Ext.example.msg('Color Selected', 'You chose {0}.', color);
163 text: 'More Colors...',
176 toggleHandler: onItemToggle,
182 // Menus have a rich api for
183 // adding and removing elements dynamically
184 var item = menu.add({
185 text: 'Dynamically added Item'
187 // items support full Observable API
188 item.on('click', onItemClick);
190 // items can easily be looked up
192 text: 'Disabled Item',
193 id: 'disableMe' // <-- Items can also have an id for easy lookup
194 // disabled: true <-- allowed but for sake of example we use long way below
196 // access items by id or index
197 menu.items.get('disableMe').disable();
199 // They can also be referenced by id in or components
201 icon: 'list-items.gif', // icons can also be specified inline
203 tooltip: '<b>Quick Tips</b><br/>Icon only button with tooltip',
205 Ext.example.msg('Button Click','You clicked the "icon only" button.');
209 var scrollMenu = Ext.create('Ext.menu.Menu');
210 for (var i = 0; i < 50; ++i){
212 text: 'Item ' + (i + 1),
219 cls: 'x-btn-text-icon',
220 text: 'Scrolling Menu',
226 url: 'http://www.google.com/search',
230 tooltip: 'This is a link. You can right click. You can see where it will take you'
233 // add a combobox to the toolbar
234 var combo = Ext.create('Ext.form.field.ComboBox', {
237 displayField: 'state',
240 triggerAction: 'all',
241 emptyText:'Select a state...',
246 tb.suspendLayout = false;
249 // functions to display feedback
250 function onButtonClick(btn){
251 Ext.example.msg('Button Click','You clicked the "{0}" button.', btn.text);
254 function onItemClick(item){
255 Ext.example.msg('Menu Click', 'You clicked the "{0}" menu item.', item.text);
258 function onItemCheck(item, checked){
259 Ext.example.msg('Item Check', 'You {1} the "{0}" menu item.', item.text, checked ? 'checked' : 'unchecked');
262 function onItemToggle(item, pressed){
263 Ext.example.msg('Button Toggled', 'Button "{0}" was toggled to {1}.', item.text, pressed);