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.

479 lines
20 KiB

2 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  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-PropertyRecord-method-constructor'><span id='Ext-grid-PropertyRecord'>/**
  19. </span></span> * @class Ext.grid.PropertyRecord
  20. * A specific {@link Ext.data.Record} type that represents a name/value pair and is made to work with the
  21. * {@link Ext.grid.PropertyGrid}. Typically, PropertyRecords do not need to be created directly as they can be
  22. * created implicitly by simply using the appropriate data configs either via the {@link Ext.grid.PropertyGrid#source}
  23. * config property or by calling {@link Ext.grid.PropertyGrid#setSource}. However, if the need arises, these records
  24. * can also be created explicitly as shwon below. Example usage:
  25. * &lt;pre&gt;&lt;code&gt;
  26. var rec = new Ext.grid.PropertyRecord({
  27. name: 'Birthday',
  28. value: new Date(Date.parse('05/26/1972'))
  29. });
  30. // Add record to an already populated grid
  31. grid.store.addSorted(rec);
  32. &lt;/code&gt;&lt;/pre&gt;
  33. * @constructor
  34. * @param {Object} config A data object in the format: {name: [name], value: [value]}. The specified value's type
  35. * will be read automatically by the grid to determine the type of editor to use when displaying it.
  36. */
  37. Ext.grid.PropertyRecord = Ext.data.Record.create([
  38. {name:'name',type:'string'}, 'value'
  39. ]);
  40. <span id='Ext-grid-PropertyStore-method-constructor'><span id='Ext-grid-PropertyStore'>/**
  41. </span></span> * @class Ext.grid.PropertyStore
  42. * @extends Ext.util.Observable
  43. * A custom wrapper for the {@link Ext.grid.PropertyGrid}'s {@link Ext.data.Store}. This class handles the mapping
  44. * between the custom data source objects supported by the grid and the {@link Ext.grid.PropertyRecord} format
  45. * required for compatibility with the underlying store. Generally this class should not need to be used directly --
  46. * the grid's data should be accessed from the underlying store via the {@link #store} property.
  47. * @constructor
  48. * @param {Ext.grid.Grid} grid The grid this store will be bound to
  49. * @param {Object} source The source data config object
  50. */
  51. Ext.grid.PropertyStore = Ext.extend(Ext.util.Observable, {
  52. constructor : function(grid, source){
  53. this.grid = grid;
  54. this.store = new Ext.data.Store({
  55. recordType : Ext.grid.PropertyRecord
  56. });
  57. this.store.on('update', this.onUpdate, this);
  58. if(source){
  59. this.setSource(source);
  60. }
  61. Ext.grid.PropertyStore.superclass.constructor.call(this);
  62. },
  63. <span id='Ext-grid-PropertyStore-method-setSource'> // protected - should only be called by the grid. Use grid.setSource instead.
  64. </span> setSource : function(o){
  65. this.source = o;
  66. this.store.removeAll();
  67. var data = [];
  68. for(var k in o){
  69. if(this.isEditableValue(o[k])){
  70. data.push(new Ext.grid.PropertyRecord({name: k, value: o[k]}, k));
  71. }
  72. }
  73. this.store.loadRecords({records: data}, {}, true);
  74. },
  75. <span id='Ext-grid-PropertyStore-method-onUpdate'> // private
  76. </span> onUpdate : function(ds, record, type){
  77. if(type == Ext.data.Record.EDIT){
  78. var v = record.data.value;
  79. var oldValue = record.modified.value;
  80. if(this.grid.fireEvent('beforepropertychange', this.source, record.id, v, oldValue) !== false){
  81. this.source[record.id] = v;
  82. record.commit();
  83. this.grid.fireEvent('propertychange', this.source, record.id, v, oldValue);
  84. }else{
  85. record.reject();
  86. }
  87. }
  88. },
  89. <span id='Ext-grid-PropertyStore-method-getProperty'> // private
  90. </span> getProperty : function(row){
  91. return this.store.getAt(row);
  92. },
  93. <span id='Ext-grid-PropertyStore-method-isEditableValue'> // private
  94. </span> isEditableValue: function(val){
  95. return Ext.isPrimitive(val) || Ext.isDate(val);
  96. },
  97. <span id='Ext-grid-PropertyStore-method-setValue'> // private
  98. </span> setValue : function(prop, value, create){
  99. var r = this.getRec(prop);
  100. if(r){
  101. r.set('value', value);
  102. this.source[prop] = value;
  103. }else if(create){
  104. // only create if specified.
  105. this.source[prop] = value;
  106. r = new Ext.grid.PropertyRecord({name: prop, value: value}, prop);
  107. this.store.add(r);
  108. }
  109. },
  110. <span id='Ext-grid-PropertyStore-method-remove'> // private
  111. </span> remove : function(prop){
  112. var r = this.getRec(prop);
  113. if(r){
  114. this.store.remove(r);
  115. delete this.source[prop];
  116. }
  117. },
  118. <span id='Ext-grid-PropertyStore-method-getRec'> // private
  119. </span> getRec : function(prop){
  120. return this.store.getById(prop);
  121. },
  122. <span id='Ext-grid-PropertyStore-method-getSource'> // protected - should only be called by the grid. Use grid.getSource instead.
  123. </span> getSource : function(){
  124. return this.source;
  125. }
  126. });
  127. <span id='Ext-grid-PropertyColumnModel-method-constructor'><span id='Ext-grid-PropertyColumnModel'>/**
  128. </span></span> * @class Ext.grid.PropertyColumnModel
  129. * @extends Ext.grid.ColumnModel
  130. * A custom column model for the {@link Ext.grid.PropertyGrid}. Generally it should not need to be used directly.
  131. * @constructor
  132. * @param {Ext.grid.Grid} grid The grid this store will be bound to
  133. * @param {Object} source The source data config object
  134. */
  135. Ext.grid.PropertyColumnModel = Ext.extend(Ext.grid.ColumnModel, {
  136. <span id='Ext-grid-PropertyColumnModel-property-nameText'> // private - strings used for locale support
  137. </span> nameText : 'Name',
  138. <span id='Ext-grid-PropertyColumnModel-property-valueText'> valueText : 'Value',
  139. </span><span id='Ext-grid-PropertyColumnModel-property-dateFormat'> dateFormat : 'm/j/Y',
  140. </span><span id='Ext-grid-PropertyColumnModel-property-trueText'> trueText: 'true',
  141. </span><span id='Ext-grid-PropertyColumnModel-property-falseText'> falseText: 'false',
  142. </span>
  143. constructor : function(grid, store){
  144. var g = Ext.grid,
  145. f = Ext.form;
  146. this.grid = grid;
  147. g.PropertyColumnModel.superclass.constructor.call(this, [
  148. {header: this.nameText, width:50, sortable: true, dataIndex:'name', id: 'name', menuDisabled:true},
  149. {header: this.valueText, width:50, resizable:false, dataIndex: 'value', id: 'value', menuDisabled:true}
  150. ]);
  151. this.store = store;
  152. var bfield = new f.Field({
  153. autoCreate: {tag: 'select', children: [
  154. {tag: 'option', value: 'true', html: this.trueText},
  155. {tag: 'option', value: 'false', html: this.falseText}
  156. ]},
  157. getValue : function(){
  158. return this.el.dom.value == 'true';
  159. }
  160. });
  161. this.editors = {
  162. 'date' : new g.GridEditor(new f.DateField({selectOnFocus:true})),
  163. 'string' : new g.GridEditor(new f.TextField({selectOnFocus:true})),
  164. 'number' : new g.GridEditor(new f.NumberField({selectOnFocus:true, style:'text-align:left;'})),
  165. 'boolean' : new g.GridEditor(bfield, {
  166. autoSize: 'both'
  167. })
  168. };
  169. this.renderCellDelegate = this.renderCell.createDelegate(this);
  170. this.renderPropDelegate = this.renderProp.createDelegate(this);
  171. },
  172. <span id='Ext-grid-PropertyColumnModel-method-renderDate'> // private
  173. </span> renderDate : function(dateVal){
  174. return dateVal.dateFormat(this.dateFormat);
  175. },
  176. <span id='Ext-grid-PropertyColumnModel-method-renderBool'> // private
  177. </span> renderBool : function(bVal){
  178. return this[bVal ? 'trueText' : 'falseText'];
  179. },
  180. <span id='Ext-grid-PropertyColumnModel-method-isCellEditable'> // private
  181. </span> isCellEditable : function(colIndex, rowIndex){
  182. return colIndex == 1;
  183. },
  184. <span id='Ext-grid-PropertyColumnModel-method-getRenderer'> // private
  185. </span> getRenderer : function(col){
  186. return col == 1 ?
  187. this.renderCellDelegate : this.renderPropDelegate;
  188. },
  189. <span id='Ext-grid-PropertyColumnModel-method-renderProp'> // private
  190. </span> renderProp : function(v){
  191. return this.getPropertyName(v);
  192. },
  193. <span id='Ext-grid-PropertyColumnModel-method-renderCell'> // private
  194. </span> renderCell : function(val, meta, rec){
  195. var renderer = this.grid.customRenderers[rec.get('name')];
  196. if(renderer){
  197. return renderer.apply(this, arguments);
  198. }
  199. var rv = val;
  200. if(Ext.isDate(val)){
  201. rv = this.renderDate(val);
  202. }else if(typeof val == 'boolean'){
  203. rv = this.renderBool(val);
  204. }
  205. return Ext.util.Format.htmlEncode(rv);
  206. },
  207. <span id='Ext-grid-PropertyColumnModel-method-getPropertyName'> // private
  208. </span> getPropertyName : function(name){
  209. var pn = this.grid.propertyNames;
  210. return pn &amp;&amp; pn[name] ? pn[name] : name;
  211. },
  212. <span id='Ext-grid-PropertyColumnModel-method-getCellEditor'> // private
  213. </span> getCellEditor : function(colIndex, rowIndex){
  214. var p = this.store.getProperty(rowIndex),
  215. n = p.data.name,
  216. val = p.data.value;
  217. if(this.grid.customEditors[n]){
  218. return this.grid.customEditors[n];
  219. }
  220. if(Ext.isDate(val)){
  221. return this.editors.date;
  222. }else if(typeof val == 'number'){
  223. return this.editors.number;
  224. }else if(typeof val == 'boolean'){
  225. return this.editors['boolean'];
  226. }else{
  227. return this.editors.string;
  228. }
  229. },
  230. <span id='Ext-grid-PropertyColumnModel-method-destroy'> // inherit docs
  231. </span> destroy : function(){
  232. Ext.grid.PropertyColumnModel.superclass.destroy.call(this);
  233. this.destroyEditors(this.editors);
  234. this.destroyEditors(this.grid.customEditors);
  235. },
  236. <span id='Ext-grid-PropertyColumnModel-method-destroyEditors'> destroyEditors: function(editors){
  237. </span> for(var ed in editors){
  238. Ext.destroy(editors[ed]);
  239. }
  240. }
  241. });
  242. <span id='Ext-grid-PropertyGrid-method-constructor'><span id='Ext-grid-PropertyGrid'>/**
  243. </span></span> * @class Ext.grid.PropertyGrid
  244. * @extends Ext.grid.EditorGridPanel
  245. * A specialized grid implementation intended to mimic the traditional property grid as typically seen in
  246. * development IDEs. Each row in the grid represents a property of some object, and the data is stored
  247. * as a set of name/value pairs in {@link Ext.grid.PropertyRecord}s. Example usage:
  248. * &lt;pre&gt;&lt;code&gt;
  249. var grid = new Ext.grid.PropertyGrid({
  250. title: 'Properties Grid',
  251. autoHeight: true,
  252. width: 300,
  253. renderTo: 'grid-ct',
  254. source: {
  255. &quot;(name)&quot;: &quot;My Object&quot;,
  256. &quot;Created&quot;: new Date(Date.parse('10/15/2006')),
  257. &quot;Available&quot;: false,
  258. &quot;Version&quot;: .01,
  259. &quot;Description&quot;: &quot;A test object&quot;
  260. }
  261. });
  262. &lt;/code&gt;&lt;/pre&gt;
  263. * @constructor
  264. * @param {Object} config The grid config object
  265. */
  266. Ext.grid.PropertyGrid = Ext.extend(Ext.grid.EditorGridPanel, {
  267. <span id='Ext-grid-PropertyGrid-cfg-propertyNames'> /**
  268. </span> * @cfg {Object} propertyNames An object containing property name/display name pairs.
  269. * If specified, the display name will be shown in the name column instead of the property name.
  270. */
  271. <span id='Ext-grid-PropertyGrid-cfg-source'> /**
  272. </span> * @cfg {Object} source A data object to use as the data source of the grid (see {@link #setSource} for details).
  273. */
  274. <span id='Ext-grid-PropertyGrid-cfg-customEditors'> /**
  275. </span> * @cfg {Object} customEditors An object containing name/value pairs of custom editor type definitions that allow
  276. * the grid to support additional types of editable fields. By default, the grid supports strongly-typed editing
  277. * of strings, dates, numbers and booleans using built-in form editors, but any custom type can be supported and
  278. * associated with a custom input control by specifying a custom editor. The name of the editor
  279. * type should correspond with the name of the property that will use the editor. Example usage:
  280. * &lt;pre&gt;&lt;code&gt;
  281. var grid = new Ext.grid.PropertyGrid({
  282. ...
  283. customEditors: {
  284. 'Start Time': new Ext.grid.GridEditor(new Ext.form.TimeField({selectOnFocus:true}))
  285. },
  286. source: {
  287. 'Start Time': '10:00 AM'
  288. }
  289. });
  290. &lt;/code&gt;&lt;/pre&gt;
  291. */
  292. <span id='Ext-grid-PropertyGrid-cfg-customRenderers'> /**
  293. </span> * @cfg {Object} customRenderers An object containing name/value pairs of custom renderer type definitions that allow
  294. * the grid to support custom rendering of fields. By default, the grid supports strongly-typed rendering
  295. * of strings, dates, numbers and booleans using built-in form editors, but any custom type can be supported and
  296. * associated with the type of the value. The name of the renderer type should correspond with the name of the property
  297. * that it will render. Example usage:
  298. * &lt;pre&gt;&lt;code&gt;
  299. var grid = new Ext.grid.PropertyGrid({
  300. ...
  301. customRenderers: {
  302. Available: function(v){
  303. if(v){
  304. return '&lt;span style=&quot;color: green;&quot;&gt;Yes&lt;/span&gt;';
  305. }else{
  306. return '&lt;span style=&quot;color: red;&quot;&gt;No&lt;/span&gt;';
  307. }
  308. }
  309. },
  310. source: {
  311. Available: true
  312. }
  313. });
  314. &lt;/code&gt;&lt;/pre&gt;
  315. */
  316. <span id='Ext-grid-PropertyGrid-cfg-enableColumnMove'> // private config overrides
  317. </span> enableColumnMove:false,
  318. <span id='Ext-grid-PropertyGrid-cfg-stripeRows'> stripeRows:false,
  319. </span><span id='Ext-grid-PropertyGrid-cfg-trackMouseOver'> trackMouseOver: false,
  320. </span><span id='Ext-grid-PropertyGrid-cfg-clicksToEdit'> clicksToEdit:1,
  321. </span><span id='Ext-grid-PropertyGrid-cfg-enableHdMenu'> enableHdMenu : false,
  322. </span><span id='Ext-grid-PropertyGrid-cfg-viewConfig'> viewConfig : {
  323. </span> forceFit:true
  324. },
  325. <span id='Ext-grid-PropertyGrid-method-initComponent'> // private
  326. </span> initComponent : function(){
  327. this.customRenderers = this.customRenderers || {};
  328. this.customEditors = this.customEditors || {};
  329. this.lastEditRow = null;
  330. var store = new Ext.grid.PropertyStore(this);
  331. this.propStore = store;
  332. var cm = new Ext.grid.PropertyColumnModel(this, store);
  333. store.store.sort('name', 'ASC');
  334. this.addEvents(
  335. <span id='Ext-grid-PropertyGrid-event-beforepropertychange'> /**
  336. </span> * @event beforepropertychange
  337. * Fires before a property value changes. Handlers can return false to cancel the property change
  338. * (this will internally call {@link Ext.data.Record#reject} on the property's record).
  339. * @param {Object} source The source data object for the grid (corresponds to the same object passed in
  340. * as the {@link #source} config property).
  341. * @param {String} recordId The record's id in the data store
  342. * @param {Mixed} value The current edited property value
  343. * @param {Mixed} oldValue The original property value prior to editing
  344. */
  345. 'beforepropertychange',
  346. <span id='Ext-grid-PropertyGrid-event-propertychange'> /**
  347. </span> * @event propertychange
  348. * Fires after a property value has changed.
  349. * @param {Object} source The source data object for the grid (corresponds to the same object passed in
  350. * as the {@link #source} config property).
  351. * @param {String} recordId The record's id in the data store
  352. * @param {Mixed} value The current edited property value
  353. * @param {Mixed} oldValue The original property value prior to editing
  354. */
  355. 'propertychange'
  356. );
  357. this.cm = cm;
  358. this.ds = store.store;
  359. Ext.grid.PropertyGrid.superclass.initComponent.call(this);
  360. this.mon(this.selModel, 'beforecellselect', function(sm, rowIndex, colIndex){
  361. if(colIndex === 0){
  362. this.startEditing.defer(200, this, [rowIndex, 1]);
  363. return false;
  364. }
  365. }, this);
  366. },
  367. <span id='Ext-grid-PropertyGrid-method-onRender'> // private
  368. </span> onRender : function(){
  369. Ext.grid.PropertyGrid.superclass.onRender.apply(this, arguments);
  370. this.getGridEl().addClass('x-props-grid');
  371. },
  372. <span id='Ext-grid-PropertyGrid-method-afterRender'> // private
  373. </span> afterRender: function(){
  374. Ext.grid.PropertyGrid.superclass.afterRender.apply(this, arguments);
  375. if(this.source){
  376. this.setSource(this.source);
  377. }
  378. },
  379. <span id='Ext-grid-PropertyGrid-method-setSource'> /**
  380. </span> * Sets the source data object containing the property data. The data object can contain one or more name/value
  381. * pairs representing all of the properties of an object to display in the grid, and this data will automatically
  382. * be loaded into the grid's {@link #store}. The values should be supplied in the proper data type if needed,
  383. * otherwise string type will be assumed. If the grid already contains data, this method will replace any
  384. * existing data. See also the {@link #source} config value. Example usage:
  385. * &lt;pre&gt;&lt;code&gt;
  386. grid.setSource({
  387. &quot;(name)&quot;: &quot;My Object&quot;,
  388. &quot;Created&quot;: new Date(Date.parse('10/15/2006')), // date type
  389. &quot;Available&quot;: false, // boolean type
  390. &quot;Version&quot;: .01, // decimal type
  391. &quot;Description&quot;: &quot;A test object&quot;
  392. });
  393. &lt;/code&gt;&lt;/pre&gt;
  394. * @param {Object} source The data object
  395. */
  396. setSource : function(source){
  397. this.propStore.setSource(source);
  398. },
  399. <span id='Ext-grid-PropertyGrid-method-getSource'> /**
  400. </span> * Gets the source data object containing the property data. See {@link #setSource} for details regarding the
  401. * format of the data object.
  402. * @return {Object} The data object
  403. */
  404. getSource : function(){
  405. return this.propStore.getSource();
  406. },
  407. <span id='Ext-grid-PropertyGrid-method-setProperty'> /**
  408. </span> * Sets the value of a property.
  409. * @param {String} prop The name of the property to set
  410. * @param {Mixed} value The value to test
  411. * @param {Boolean} create (Optional) True to create the property if it doesn't already exist. Defaults to &lt;tt&gt;false&lt;/tt&gt;.
  412. */
  413. setProperty : function(prop, value, create){
  414. this.propStore.setValue(prop, value, create);
  415. },
  416. <span id='Ext-grid-PropertyGrid-method-removeProperty'> /**
  417. </span> * Removes a property from the grid.
  418. * @param {String} prop The name of the property to remove
  419. */
  420. removeProperty : function(prop){
  421. this.propStore.remove(prop);
  422. }
  423. <span id='Ext-grid-PropertyGrid-cfg-store'> /**
  424. </span> * @cfg store
  425. * @hide
  426. */
  427. <span id='Ext-grid-PropertyGrid-cfg-colModel'> /**
  428. </span> * @cfg colModel
  429. * @hide
  430. */
  431. <span id='Ext-grid-PropertyGrid-cfg-cm'> /**
  432. </span> * @cfg cm
  433. * @hide
  434. */
  435. <span id='Ext-grid-PropertyGrid-cfg-columns'> /**
  436. </span> * @cfg columns
  437. * @hide
  438. */
  439. });
  440. Ext.reg(&quot;propertygrid&quot;, Ext.grid.PropertyGrid);
  441. </pre>
  442. </body>
  443. </html>