Store2.html 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  5. <title>The source code</title>
  6. <link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />
  7. <script type="text/javascript" src="../resources/prettify/prettify.js"></script>
  8. <style type="text/css">
  9. .highlight { display: block; background-color: #ddd; }
  10. </style>
  11. <script type="text/javascript">
  12. function highlight() {
  13. document.getElementById(location.hash.replace(/#/, "")).className = "highlight";
  14. }
  15. </script>
  16. </head>
  17. <body onload="prettyPrint(); highlight();">
  18. <pre class="prettyprint lang-js"><span id='Ext-grid-property-Store'>/**
  19. </span> * A custom {@link Ext.data.Store} for the {@link Ext.grid.property.Grid}. This class handles the mapping
  20. * between the custom data source objects supported by the grid and the {@link Ext.grid.property.Property} format
  21. * used by the {@link Ext.data.Store} base class.
  22. */
  23. Ext.define('Ext.grid.property.Store', {
  24. extend: 'Ext.data.Store',
  25. alternateClassName: 'Ext.grid.PropertyStore',
  26. sortOnLoad: false,
  27. uses: ['Ext.data.reader.Reader', 'Ext.data.proxy.Proxy', 'Ext.data.ResultSet', 'Ext.grid.property.Property'],
  28. <span id='Ext-grid-property-Store-method-constructor'> /**
  29. </span> * Creates new property store.
  30. * @param {Ext.grid.Panel} grid The grid this store will be bound to
  31. * @param {Object} source The source data config object
  32. */
  33. constructor : function(grid, source){
  34. var me = this;
  35. me.grid = grid;
  36. me.source = source;
  37. me.callParent([{
  38. data: source,
  39. model: Ext.grid.property.Property,
  40. proxy: me.getProxy()
  41. }]);
  42. },
  43. // Return a singleton, customized Proxy object which configures itself with a custom Reader
  44. getProxy: function() {
  45. if (!this.proxy) {
  46. Ext.grid.property.Store.prototype.proxy = new Ext.data.proxy.Memory({
  47. model: Ext.grid.property.Property,
  48. reader: this.getReader()
  49. });
  50. }
  51. return this.proxy;
  52. },
  53. // Return a singleton, customized Reader object which reads Ext.grid.property.Property records from an object.
  54. getReader: function() {
  55. if (!this.reader) {
  56. Ext.grid.property.Store.prototype.reader = new Ext.data.reader.Reader({
  57. model: Ext.grid.property.Property,
  58. buildExtractors: Ext.emptyFn,
  59. read: function(dataObject) {
  60. return this.readRecords(dataObject);
  61. },
  62. readRecords: function(dataObject) {
  63. var val,
  64. propName,
  65. result = {
  66. records: [],
  67. success: true
  68. };
  69. for (propName in dataObject) {
  70. if (dataObject.hasOwnProperty(propName)) {
  71. val = dataObject[propName];
  72. if (this.isEditableValue(val)) {
  73. result.records.push(new Ext.grid.property.Property({
  74. name: propName,
  75. value: val
  76. }, propName));
  77. }
  78. }
  79. }
  80. result.total = result.count = result.records.length;
  81. return new Ext.data.ResultSet(result);
  82. },
  83. // private
  84. isEditableValue: function(val){
  85. return Ext.isPrimitive(val) || Ext.isDate(val);
  86. }
  87. });
  88. }
  89. return this.reader;
  90. },
  91. // protected - should only be called by the grid. Use grid.setSource instead.
  92. setSource : function(dataObject) {
  93. var me = this;
  94. me.source = dataObject;
  95. me.suspendEvents();
  96. me.removeAll();
  97. me.proxy.data = dataObject;
  98. me.load();
  99. me.resumeEvents();
  100. me.fireEvent('datachanged', me);
  101. me.fireEvent('refresh', me);
  102. },
  103. // private
  104. getProperty : function(row) {
  105. return Ext.isNumber(row) ? this.getAt(row) : this.getById(row);
  106. },
  107. // private
  108. setValue : function(prop, value, create){
  109. var me = this,
  110. rec = me.getRec(prop);
  111. if (rec) {
  112. rec.set('value', value);
  113. me.source[prop] = value;
  114. } else if (create) {
  115. // only create if specified.
  116. me.source[prop] = value;
  117. rec = new Ext.grid.property.Property({name: prop, value: value}, prop);
  118. me.add(rec);
  119. }
  120. },
  121. // private
  122. remove : function(prop) {
  123. var rec = this.getRec(prop);
  124. if (rec) {
  125. this.callParent([rec]);
  126. delete this.source[prop];
  127. }
  128. },
  129. // private
  130. getRec : function(prop) {
  131. return this.getById(prop);
  132. },
  133. // protected - should only be called by the grid. Use grid.getSource instead.
  134. getSource : function() {
  135. return this.source;
  136. }
  137. });</pre>
  138. </body>
  139. </html>