/ext-4.1.0_b3/examples/menu/actions.js

https://bitbucket.org/srogerf/javascript · JavaScript · 65 lines · 59 code · 3 blank · 3 comment · 5 complexity · bafd216305767b0103be87095857dbed MD5 · raw file

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