]> git.proxmox.com Git - extjs.git/blame - extjs/examples/classic/menu/actions.js
add extjs 6.0.1 sources
[extjs.git] / extjs / examples / classic / menu / actions.js
CommitLineData
6527f429
DM
1Ext.require([\r
2 'Ext.panel.Panel',\r
3 'Ext.Action',\r
4 'Ext.button.Button',\r
5 'Ext.window.MessageBox'\r
6]);\r
7\r
8Ext.onReady(function(){\r
9 var action = Ext.create('Ext.Action', {\r
10 text: 'Action 1',\r
11 iconCls: 'icon-add',\r
12 handler: function(){\r
13 Ext.example.msg('Click', 'You clicked on "Action 1".');\r
14 }\r
15 });\r
16 \r
17 var panel = Ext.create('Ext.panel.Panel', {\r
18 title: 'Actions',\r
19 renderTo: document.body,\r
20 width: 600,\r
21 height: 300,\r
22 bodyPadding: 10,\r
23 dockedItems: {\r
24 itemId: 'toolbar',\r
25 xtype: 'toolbar',\r
26 items: [\r
27 action, // Add the action directly to a toolbar\r
28 {\r
29 text: 'Action menu',\r
30 menu: [action] // Add the action directly to a menu\r
31 }\r
32 ]\r
33 },\r
34 items: Ext.create('Ext.button.Button', action) // Add the action as a button\r
35 });\r
36 \r
37 /*\r
38 * Add toolbar items dynamically after creation\r
39 */\r
40 var toolbar = panel.child('#toolbar');\r
41 toolbar.add('->', {\r
42 text: 'Disable',\r
43 handler: function(){\r
44 action.setDisabled(!action.isDisabled());\r
45 this.setText(action.isDisabled() ? 'Enable' : 'Disable');\r
46 }\r
47 }, {\r
48 text: 'Change Text',\r
49 handler: function(){\r
50 Ext.Msg.prompt('Enter Text', 'Enter new text for Action 1:', function(btn, text){\r
51 if(btn == 'ok' && text){\r
52 action.setText(text);\r
53 action.setHandler(function(){\r
54 Ext.example.msg('Click','You clicked on "'+text+'".');\r
55 });\r
56 }\r
57 });\r
58 }\r
59 }, {\r
60 text: 'Change Icon',\r
61 handler: function(){\r
62 action.setIconCls(action.getIconCls() == 'icon-add' ? 'icon-edit' : 'icon-add');\r
63 }\r
64 });\r
65});\r