Web Interface For Lite Argus Control modules
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.

136 lines
3.9 KiB

​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. /*!
  2. * Ext JS Library 3.3.1
  3. * Copyright(c) 2006-2010 Sencha Inc.
  4. * licensing@sencha.com
  5. * http://www.sencha.com/license
  6. */
  7. // Application instance for showing user-feedback messages.
  8. var App = new Ext.App({});
  9. // Create a standard HttpProxy instance.
  10. var proxy = new Ext.data.HttpProxy({
  11. url: 'app.php/users'
  12. });
  13. // Typical JsonReader. Notice additional meta-data params for defining the core attributes of your json-response
  14. var reader = new Ext.data.JsonReader({
  15. totalProperty: 'total',
  16. successProperty: 'success',
  17. idProperty: 'id',
  18. root: 'data',
  19. messageProperty: 'message' // <-- New "messageProperty" meta-data
  20. }, [
  21. {name: 'id'},
  22. {name: 'email', allowBlank: false},
  23. {name: 'first', allowBlank: false},
  24. {name: 'last', allowBlank: false}
  25. ]);
  26. // The new DataWriter component.
  27. var writer = new Ext.data.JsonWriter({
  28. encode: false // <-- don't return encoded JSON -- causes Ext.Ajax#request to send data using jsonData config rather than HTTP params
  29. });
  30. // Typical Store collecting the Proxy, Reader and Writer together.
  31. var store = new Ext.data.Store({
  32. id: 'user',
  33. restful: true, // <-- This Store is RESTful
  34. proxy: proxy,
  35. reader: reader,
  36. writer: writer // <-- plug a DataWriter into the store just as you would a Reader
  37. });
  38. // load the store immeditately
  39. store.load();
  40. ////
  41. // ***New*** centralized listening of DataProxy events "beforewrite", "write" and "writeexception"
  42. // upon Ext.data.DataProxy class. This is handy for centralizing user-feedback messaging into one place rather than
  43. // attaching listenrs to EACH Store.
  44. //
  45. // Listen to all DataProxy beforewrite events
  46. //
  47. Ext.data.DataProxy.addListener('beforewrite', function(proxy, action) {
  48. App.setAlert(App.STATUS_NOTICE, "Before " + action);
  49. });
  50. ////
  51. // all write events
  52. //
  53. Ext.data.DataProxy.addListener('write', function(proxy, action, result, res, rs) {
  54. App.setAlert(true, action + ':' + res.message);
  55. });
  56. ////
  57. // all exception events
  58. //
  59. Ext.data.DataProxy.addListener('exception', function(proxy, type, action, options, res) {
  60. App.setAlert(false, "Something bad happend while executing " + action);
  61. });
  62. // Let's pretend we rendered our grid-columns with meta-data from our ORM framework.
  63. var userColumns = [
  64. {header: "ID", width: 40, sortable: true, dataIndex: 'id'},
  65. {header: "Email", width: 100, sortable: true, dataIndex: 'email', editor: new Ext.form.TextField({})},
  66. {header: "First", width: 50, sortable: true, dataIndex: 'first', editor: new Ext.form.TextField({})},
  67. {header: "Last", width: 50, sortable: true, dataIndex: 'last', editor: new Ext.form.TextField({})}
  68. ];
  69. Ext.onReady(function() {
  70. Ext.QuickTips.init();
  71. // use RowEditor for editing
  72. var editor = new Ext.ux.grid.RowEditor({
  73. saveText: 'Update'
  74. });
  75. // Create a typical GridPanel with RowEditor plugin
  76. var userGrid = new Ext.grid.GridPanel({
  77. renderTo: 'user-grid',
  78. iconCls: 'icon-grid',
  79. frame: true,
  80. title: 'Users',
  81. height: 300,
  82. store: store,
  83. plugins: [editor],
  84. columns : userColumns,
  85. tbar: [{
  86. text: 'Add',
  87. iconCls: 'silk-add',
  88. handler: onAdd
  89. }, '-', {
  90. text: 'Delete',
  91. iconCls: 'silk-delete',
  92. handler: onDelete
  93. }, '-'],
  94. viewConfig: {
  95. forceFit: true
  96. }
  97. });
  98. /**
  99. * onAdd
  100. */
  101. function onAdd(btn, ev) {
  102. var u = new userGrid.store.recordType({
  103. first : '',
  104. last: '',
  105. email : ''
  106. });
  107. editor.stopEditing();
  108. userGrid.store.insert(0, u);
  109. editor.startEditing(0);
  110. }
  111. /**
  112. * onDelete
  113. */
  114. function onDelete() {
  115. var rec = userGrid.getSelectionModel().getSelected();
  116. if (!rec) {
  117. return false;
  118. }
  119. userGrid.store.remove(rec);
  120. }
  121. });