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.

139 lines
4.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. // Application instance for showing user-feedback messages.
  16. var App = new Ext.App({});
  17. // Create HttpProxy instance. Notice new configuration parameter "api" here instead of load. However, you can still use
  18. // the "url" paramater -- All CRUD requests will be directed to your single url instead.
  19. var proxy = new Ext.data.HttpProxy({
  20. api: {
  21. read : 'app.php/users/view',
  22. create : 'app.php/users/create',
  23. update: 'app.php/users/update',
  24. destroy: 'app.php/users/destroy'
  25. }
  26. });
  27. // Typical JsonReader. Notice additional meta-data params for defining the core attributes of your json-response
  28. var reader = new Ext.data.JsonReader({
  29. totalProperty: 'total',
  30. successProperty: 'success',
  31. idProperty: 'id',
  32. root: 'data',
  33. messageProperty: 'message' // <-- New "messageProperty" meta-data
  34. }, [
  35. {name: 'id'},
  36. {name: 'email', allowBlank: false},
  37. {name: 'first', allowBlank: false},
  38. {name: 'last', allowBlank: false}
  39. ]);
  40. // The new DataWriter component.
  41. var writer = new Ext.data.JsonWriter({
  42. encode: true,
  43. writeAllFields: false
  44. });
  45. // Typical Store collecting the Proxy, Reader and Writer together.
  46. var store = new Ext.data.Store({
  47. id: 'user',
  48. proxy: proxy,
  49. reader: reader,
  50. writer: writer, // <-- plug a DataWriter into the store just as you would a Reader
  51. autoSave: true // <-- false would delay executing create, update, destroy requests until specifically told to do so with some [save] buton.
  52. });
  53. // load the store immeditately
  54. store.load();
  55. ////
  56. // ***New*** centralized listening of DataProxy events "beforewrite", "write" and "writeexception"
  57. // upon Ext.data.DataProxy class. This is handy for centralizing user-feedback messaging into one place rather than
  58. // attaching listenrs to EACH Store.
  59. //
  60. // Listen to all DataProxy beforewrite events
  61. //
  62. Ext.data.DataProxy.addListener('beforewrite', function(proxy, action) {
  63. App.setAlert(App.STATUS_NOTICE, "Before " + action);
  64. });
  65. ////
  66. // all write events
  67. //
  68. Ext.data.DataProxy.addListener('write', function(proxy, action, result, res, rs) {
  69. App.setAlert(true, action + ':' + res.message);
  70. });
  71. ////
  72. // all exception events
  73. //
  74. Ext.data.DataProxy.addListener('exception', function(proxy, type, action, options, res) {
  75. if (type === 'remote') {
  76. Ext.Msg.show({
  77. title: 'REMOTE EXCEPTION',
  78. msg: res.message,
  79. icon: Ext.MessageBox.ERROR,
  80. buttons: Ext.Msg.OK
  81. });
  82. }
  83. });
  84. // A new generic text field
  85. var textField = new Ext.form.TextField();
  86. // Let's pretend we rendered our grid-columns with meta-data from our ORM framework.
  87. var userColumns = [
  88. {header: "ID", width: 40, sortable: true, dataIndex: 'id'},
  89. {header: "Email", width: 100, sortable: true, dataIndex: 'email', editor: textField},
  90. {header: "First", width: 50, sortable: true, dataIndex: 'first', editor: textField},
  91. {header: "Last", width: 50, sortable: true, dataIndex: 'last', editor: textField}
  92. ];
  93. Ext.onReady(function() {
  94. Ext.QuickTips.init();
  95. // create user.Form instance (@see UserForm.js)
  96. var userForm = new App.user.Form({
  97. renderTo: 'user-form',
  98. listeners: {
  99. create : function(fpanel, data) { // <-- custom "create" event defined in App.user.Form class
  100. var rec = new userGrid.store.recordType(data);
  101. userGrid.store.insert(0, rec);
  102. }
  103. }
  104. });
  105. // create user.Grid instance (@see UserGrid.js)
  106. var userGrid = new App.user.Grid({
  107. renderTo: 'user-grid',
  108. store: store,
  109. columns : userColumns,
  110. listeners: {
  111. rowclick: function(g, index, ev) {
  112. var rec = g.store.getAt(index);
  113. userForm.loadRecord(rec);
  114. },
  115. destroy : function() {
  116. userForm.getForm().reset();
  117. }
  118. }
  119. });
  120. });