e6c1b6e1ebd22aa9d2f1c207733959dc9525492a.svn-base 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233
  1. /*
  2. * Ext JS Library 2.0 Copyright(c) 2006-2007, Ext JS, LLC. licensing@extjs.com
  3. *
  4. * http://extjs.com/license
  5. */
  6. Ext.grid.PropertyRecord = Ext.data.Record.create([{
  7. name : "name",
  8. type : "string"
  9. }, "value"]);
  10. Ext.grid.PropertyStore = function(A, B) {
  11. this.grid = A;
  12. this.store = new Ext.data.Store({
  13. recordType : Ext.grid.PropertyRecord
  14. });
  15. this.store.on("update", this.onUpdate, this);
  16. if (B) {
  17. this.setSource(B)
  18. }
  19. Ext.grid.PropertyStore.superclass.constructor.call(this)
  20. };
  21. Ext.extend(Ext.grid.PropertyStore, Ext.util.Observable, {
  22. setSource : function(C) {
  23. this.source = C;
  24. this.store.removeAll();
  25. var B = [];
  26. for (var A in C) {
  27. if (this.isEditableValue(C[A])) {
  28. B.push(new Ext.grid.PropertyRecord({
  29. name : A,
  30. value : C[A]
  31. }, A))
  32. }
  33. }
  34. this.store.loadRecords({
  35. records : B
  36. }, {}, true)
  37. },
  38. onUpdate : function(E, A, D) {
  39. if (D == Ext.data.Record.EDIT) {
  40. var B = A.data["value"];
  41. var C = A.modified["value"];
  42. if (this.grid.fireEvent("beforepropertychange",
  43. this.source, A.id, B, C) !== false) {
  44. this.source[A.id] = B;
  45. A.commit();
  46. this.grid.fireEvent("propertychange", this.source,
  47. A.id, B, C)
  48. } else {
  49. A.reject()
  50. }
  51. }
  52. },
  53. getProperty : function(A) {
  54. return this.store.getAt(A)
  55. },
  56. isEditableValue : function(A) {
  57. if (A && A instanceof Date) {
  58. return true
  59. } else {
  60. if (typeof A == "object" || typeof A == "function") {
  61. return false
  62. }
  63. }
  64. return true
  65. },
  66. setValue : function(B, A) {
  67. this.source[B] = A;
  68. this.store.getById(B).set("value", A)
  69. },
  70. getSource : function() {
  71. return this.source
  72. }
  73. });
  74. Ext.grid.PropertyColumnModel = function(C, B) {
  75. this.grid = C;
  76. var D = Ext.grid;
  77. D.PropertyColumnModel.superclass.constructor.call(this, [{
  78. header : this.nameText,
  79. width : 50,
  80. sortable : true,
  81. dataIndex : "name",
  82. id : "name"
  83. }, {
  84. header : this.valueText,
  85. width : 50,
  86. resizable : false,
  87. dataIndex : "value",
  88. id : "value"
  89. }]);
  90. this.store = B;
  91. this.bselect = Ext.DomHelper.append(document.body, {
  92. tag : "select",
  93. cls : "x-grid-editor x-hide-display",
  94. children : [{
  95. tag : "option",
  96. value : "true",
  97. html : "true"
  98. }, {
  99. tag : "option",
  100. value : "false",
  101. html : "false"
  102. }]
  103. });
  104. var E = Ext.form;
  105. var A = new E.Field({
  106. el : this.bselect,
  107. bselect : this.bselect,
  108. autoShow : true,
  109. getValue : function() {
  110. return this.bselect.value == "true"
  111. }
  112. });
  113. this.editors = {
  114. "date" : new D.GridEditor(new E.DateField({
  115. selectOnFocus : true
  116. })),
  117. "string" : new D.GridEditor(new E.TextField({
  118. selectOnFocus : true
  119. })),
  120. "number" : new D.GridEditor(new E.NumberField({
  121. selectOnFocus : true,
  122. style : "text-align:left;"
  123. })),
  124. "boolean" : new D.GridEditor(A)
  125. };
  126. this.renderCellDelegate = this.renderCell.createDelegate(this);
  127. this.renderPropDelegate = this.renderProp.createDelegate(this)
  128. };
  129. Ext.extend(Ext.grid.PropertyColumnModel, Ext.grid.ColumnModel, {
  130. nameText : "Name",
  131. valueText : "Value",
  132. dateFormat : "m/j/Y",
  133. renderDate : function(A) {
  134. return A.dateFormat(this.dateFormat)
  135. },
  136. renderBool : function(A) {
  137. return A ? "true" : "false"
  138. },
  139. isCellEditable : function(A, B) {
  140. return A == 1
  141. },
  142. getRenderer : function(A) {
  143. return A == 1
  144. ? this.renderCellDelegate
  145. : this.renderPropDelegate
  146. },
  147. renderProp : function(A) {
  148. return this.getPropertyName(A)
  149. },
  150. renderCell : function(A) {
  151. var B = A;
  152. if (A instanceof Date) {
  153. B = this.renderDate(A)
  154. } else {
  155. if (typeof A == "boolean") {
  156. B = this.renderBool(A)
  157. }
  158. }
  159. return Ext.util.Format.htmlEncode(B)
  160. },
  161. getPropertyName : function(B) {
  162. var A = this.grid.propertyNames;
  163. return A && A[B] ? A[B] : B
  164. },
  165. getCellEditor : function(A, E) {
  166. var B = this.store.getProperty(E);
  167. var D = B.data["name"], C = B.data["value"];
  168. if (this.grid.customEditors[D]) {
  169. return this.grid.customEditors[D]
  170. }
  171. if (C instanceof Date) {
  172. return this.editors["date"]
  173. } else {
  174. if (typeof C == "number") {
  175. return this.editors["number"]
  176. } else {
  177. if (typeof C == "boolean") {
  178. return this.editors["boolean"]
  179. } else {
  180. return this.editors["string"]
  181. }
  182. }
  183. }
  184. }
  185. });
  186. Ext.grid.PropertyGrid = Ext.extend(Ext.grid.EditorGridPanel, {
  187. enableColLock : false,
  188. enableColumnMove : false,
  189. stripeRows : false,
  190. trackMouseOver : false,
  191. clicksToEdit : 1,
  192. enableHdMenu : false,
  193. viewConfig : {
  194. forceFit : true
  195. },
  196. initComponent : function() {
  197. this.customEditors = this.customEditors || {};
  198. this.lastEditRow = null;
  199. var B = new Ext.grid.PropertyStore(this);
  200. this.propStore = B;
  201. var A = new Ext.grid.PropertyColumnModel(this, B);
  202. B.store.sort("name", "ASC");
  203. this.addEvents("beforepropertychange", "propertychange");
  204. this.cm = A;
  205. this.ds = B.store;
  206. Ext.grid.PropertyGrid.superclass.initComponent.call(this);
  207. this.selModel.on("beforecellselect", function(E, D, C) {
  208. if (C === 0) {
  209. this.startEditing.defer(200, this, [D, 1]);
  210. return false
  211. }
  212. }, this)
  213. },
  214. onRender : function() {
  215. Ext.grid.PropertyGrid.superclass.onRender
  216. .apply(this, arguments);
  217. this.getGridEl().addClass("x-props-grid")
  218. },
  219. afterRender : function() {
  220. Ext.grid.PropertyGrid.superclass.afterRender.apply(this,
  221. arguments);
  222. if (this.source) {
  223. this.setSource(this.source)
  224. }
  225. },
  226. setSource : function(A) {
  227. this.propStore.setSource(A)
  228. },
  229. getSource : function() {
  230. return this.propStore.getSource()
  231. }
  232. });