3 This file is part of Ext JS 4
5 Copyright (c) 2011 Sencha Inc
7 Contact: http://www.sencha.com/contact
9 GNU General Public License Usage
10 This file may be used under the terms of the GNU General Public License version 3.0 as published by the Free Software Foundation and appearing in the file LICENSE included in the packaging of this file. Please review the following information to ensure the GNU General Public License version 3.0 requirements will be met: http://www.gnu.org/copyleft/gpl.html.
12 If you are unsure which license is appropriate for your use, please contact the sales department at http://www.sencha.com/contact.
16 * @class Ext.grid.property.Store
17 * @extends Ext.data.Store
18 * A custom {@link Ext.data.Store} for the {@link Ext.grid.property.Grid}. This class handles the mapping
19 * between the custom data source objects supported by the grid and the {@link Ext.grid.property.Property} format
20 * used by the {@link Ext.data.Store} base class.
22 Ext.define('Ext.grid.property.Store', {
24 extend: 'Ext.data.Store',
26 alternateClassName: 'Ext.grid.PropertyStore',
28 uses: ['Ext.data.reader.Reader', 'Ext.data.proxy.Proxy', 'Ext.data.ResultSet', 'Ext.grid.property.Property'],
31 * Creates new property store.
32 * @param {Ext.grid.Panel} grid The grid this store will be bound to
33 * @param {Object} source The source data config object
35 constructor : function(grid, source){
42 model: Ext.grid.property.Property,
47 // Return a singleton, customized Proxy object which configures itself with a custom Reader
48 getProxy: function() {
50 Ext.grid.property.Store.prototype.proxy = Ext.create('Ext.data.proxy.Memory', {
51 model: Ext.grid.property.Property,
52 reader: this.getReader()
58 // Return a singleton, customized Reader object which reads Ext.grid.property.Property records from an object.
59 getReader: function() {
61 Ext.grid.property.Store.prototype.reader = Ext.create('Ext.data.reader.Reader', {
62 model: Ext.grid.property.Property,
64 buildExtractors: Ext.emptyFn,
66 read: function(dataObject) {
67 return this.readRecords(dataObject);
70 readRecords: function(dataObject) {
78 for (propName in dataObject) {
79 if (dataObject.hasOwnProperty(propName)) {
80 val = dataObject[propName];
81 if (this.isEditableValue(val)) {
82 result.records.push(new Ext.grid.property.Property({
89 result.total = result.count = result.records.length;
90 return Ext.create('Ext.data.ResultSet', result);
94 isEditableValue: function(val){
95 return Ext.isPrimitive(val) || Ext.isDate(val);
102 // protected - should only be called by the grid. Use grid.setSource instead.
103 setSource : function(dataObject) {
106 me.source = dataObject;
109 me.proxy.data = dataObject;
112 me.fireEvent('datachanged', me);
116 getProperty : function(row) {
117 return Ext.isNumber(row) ? this.getAt(row) : this.getById(row);
121 setValue : function(prop, value, create){
123 rec = me.getRec(prop);
126 rec.set('value', value);
127 me.source[prop] = value;
129 // only create if specified.
130 me.source[prop] = value;
131 rec = new Ext.grid.property.Property({name: prop, value: value}, prop);
137 remove : function(prop) {
138 var rec = this.getRec(prop);
140 this.callParent([rec]);
141 delete this.source[prop];
146 getRec : function(prop) {
147 return this.getById(prop);
150 // protected - should only be called by the grid. Use grid.getSource instead.
151 getSource : function() {