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.

148 lines
3.9 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.ns('App', 'App.user');
  16. /**
  17. * App.user.Grid
  18. * A typical EditorGridPanel extension.
  19. */
  20. App.user.Grid = Ext.extend(Ext.grid.EditorGridPanel, {
  21. renderTo: 'user-grid',
  22. iconCls: 'silk-grid',
  23. frame: true,
  24. title: 'Users',
  25. height: 300,
  26. width: 500,
  27. style: 'margin-top: 10px',
  28. initComponent : function() {
  29. // typical viewConfig
  30. this.viewConfig = {
  31. forceFit: true
  32. };
  33. // relay the Store's CRUD events into this grid so these events can be conveniently listened-to in our application-code.
  34. this.relayEvents(this.store, ['destroy', 'save', 'update']);
  35. // build toolbars and buttons.
  36. this.tbar = this.buildTopToolbar();
  37. this.bbar = this.buildBottomToolbar();
  38. this.buttons = this.buildUI();
  39. // super
  40. App.user.Grid.superclass.initComponent.call(this);
  41. },
  42. /**
  43. * buildTopToolbar
  44. */
  45. buildTopToolbar : function() {
  46. return [{
  47. text: 'Add',
  48. iconCls: 'silk-add',
  49. handler: this.onAdd,
  50. scope: this
  51. }, '-', {
  52. text: 'Delete',
  53. iconCls: 'silk-delete',
  54. handler: this.onDelete,
  55. scope: this
  56. }, '-'];
  57. },
  58. /**
  59. * buildBottomToolbar
  60. */
  61. buildBottomToolbar : function() {
  62. return ['<b>@cfg:</b>', '-', {
  63. text: 'autoSave',
  64. enableToggle: true,
  65. pressed: true,
  66. tooltip: 'When enabled, Store will execute Ajax requests as soon as a Record becomes dirty.',
  67. toggleHandler: function(btn, pressed) {
  68. this.store.autoSave = pressed;
  69. },
  70. scope: this
  71. }, '-', {
  72. text: 'batch',
  73. enableToggle: true,
  74. pressed: true,
  75. tooltip: 'When enabled, Store will batch all records for each type of CRUD verb into a single Ajax request.',
  76. toggleHandler: function(btn, pressed) {
  77. this.store.batch = pressed;
  78. },
  79. scope: this
  80. }, '-', {
  81. text: 'writeAllFields',
  82. enableToggle: true,
  83. tooltip: 'When enabled, Writer will write *all* fields to the server -- not just those that changed.',
  84. toggleHandler: function(btn, pressed) {
  85. store.writer.writeAllFields = pressed;
  86. },
  87. scope: this
  88. }, '-'];
  89. },
  90. /**
  91. * buildUI
  92. */
  93. buildUI : function() {
  94. return [{
  95. text: 'Save',
  96. iconCls: 'icon-save',
  97. handler: this.onSave,
  98. scope: this
  99. }];
  100. },
  101. /**
  102. * onSave
  103. */
  104. onSave : function(btn, ev) {
  105. this.store.save();
  106. },
  107. /**
  108. * onAdd
  109. */
  110. onAdd : function(btn, ev) {
  111. var u = new this.store.recordType({
  112. first : '',
  113. last: '',
  114. email : ''
  115. });
  116. this.stopEditing();
  117. this.store.insert(0, u);
  118. this.startEditing(0, 1);
  119. },
  120. /**
  121. * onDelete
  122. */
  123. onDelete : function(btn, ev) {
  124. var index = this.getSelectionModel().getSelectedCell();
  125. if (!index) {
  126. return false;
  127. }
  128. var rec = this.store.getAt(index[0]);
  129. this.store.remove(rec);
  130. }
  131. });