Store.js
5.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
/*
This file is part of Ext JS 4.2
Copyright (c) 2011-2013 Sencha Inc
Contact: http://www.sencha.com/contact
GNU General Public License Usage
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.
If you are unsure which license is appropriate for your use, please contact the sales department
at http://www.sencha.com/contact.
Build date: 2013-05-16 14:36:50 (f9be68accb407158ba2b1be2c226a6ce1f649314)
*/
/**
* A custom {@link Ext.data.Store} for the {@link Ext.grid.property.Grid}. This class handles the mapping
* between the custom data source objects supported by the grid and the {@link Ext.grid.property.Property} format
* used by the {@link Ext.data.Store} base class.
*/
Ext.define('Ext.grid.property.Store', {
extend: 'Ext.data.Store',
alternateClassName: 'Ext.grid.PropertyStore',
sortOnLoad: false,
uses: ['Ext.data.reader.Reader', 'Ext.data.proxy.Proxy', 'Ext.data.ResultSet', 'Ext.grid.property.Property'],
/**
* Creates new property store.
* @param {Ext.grid.Panel} grid The grid this store will be bound to
* @param {Object} source The source data config object
*/
constructor : function(grid, source){
var me = this;
me.grid = grid;
me.source = source;
me.callParent([{
data: source,
model: Ext.grid.property.Property,
proxy: me.getProxy()
}]);
},
// Return a singleton, customized Proxy object which configures itself with a custom Reader
getProxy: function() {
if (!this.proxy) {
Ext.grid.property.Store.prototype.proxy = new Ext.data.proxy.Memory({
model: Ext.grid.property.Property,
reader: this.getReader()
});
}
return this.proxy;
},
// Return a singleton, customized Reader object which reads Ext.grid.property.Property records from an object.
getReader: function() {
if (!this.reader) {
Ext.grid.property.Store.prototype.reader = new Ext.data.reader.Reader({
model: Ext.grid.property.Property,
buildExtractors: Ext.emptyFn,
read: function(dataObject) {
return this.readRecords(dataObject);
},
readRecords: function(dataObject) {
var val,
propName,
result = {
records: [],
success: true
};
for (propName in dataObject) {
if (dataObject.hasOwnProperty(propName)) {
val = dataObject[propName];
if (this.isEditableValue(val)) {
result.records.push(new Ext.grid.property.Property({
name: propName,
value: val
}, propName));
}
}
}
result.total = result.count = result.records.length;
return new Ext.data.ResultSet(result);
},
// @private
isEditableValue: function(val){
return Ext.isPrimitive(val) || Ext.isDate(val) || val === null;
}
});
}
return this.reader;
},
// @protected
// Should only be called by the grid. Use grid.setSource instead.
setSource : function(dataObject) {
var me = this;
me.source = dataObject;
me.suspendEvents();
me.removeAll();
me.proxy.data = dataObject;
me.load();
me.resumeEvents();
me.fireEvent('datachanged', me);
me.fireEvent('refresh', me);
},
// @private
getProperty : function(row) {
return Ext.isNumber(row) ? this.getAt(row) : this.getById(row);
},
// @private
setValue : function(prop, value, create){
var me = this,
rec = me.getRec(prop);
if (rec) {
rec.set('value', value);
me.source[prop] = value;
} else if (create) {
// only create if specified.
me.source[prop] = value;
rec = new Ext.grid.property.Property({name: prop, value: value}, prop);
me.add(rec);
}
},
// @private
remove : function(prop) {
var rec = this.getRec(prop);
if (rec) {
this.callParent([rec]);
delete this.source[prop];
}
},
// @private
getRec : function(prop) {
return this.getById(prop);
},
// @protected
// Should only be called by the grid. Use grid.getSource instead.
getSource : function() {
return this.source;
}
});