<!DOCTYPE html>
|
<html>
|
<head>
|
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
<title>The source code</title>
|
<link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />
|
<script type="text/javascript" src="../resources/prettify/prettify.js"></script>
|
<style type="text/css">
|
.highlight { display: block; background-color: #ddd; }
|
</style>
|
<script type="text/javascript">
|
function highlight() {
|
document.getElementById(location.hash.replace(/#/, "")).className = "highlight";
|
}
|
</script>
|
</head>
|
<body onload="prettyPrint(); highlight();">
|
<pre class="prettyprint lang-js"><span id='Ext-grid-property-Store'>/**
|
</span> * 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',
|
|
<span id='Ext-grid-property-Store-cfg-sortOnLoad'> sortOnLoad: false,
|
</span>
|
uses: ['Ext.data.reader.Reader', 'Ext.data.proxy.Proxy', 'Ext.data.ResultSet', 'Ext.grid.property.Property'],
|
|
<span id='Ext-grid-property-Store-method-constructor'> /**
|
</span> * 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()
|
}]);
|
},
|
|
<span id='Ext-grid-property-Store-method-getProxy'> // Return a singleton, customized Proxy object which configures itself with a custom Reader
|
</span> 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;
|
},
|
|
<span id='Ext-grid-property-Store-method-getReader'> // Return a singleton, customized Reader object which reads Ext.grid.property.Property records from an object.
|
</span> 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;
|
},
|
|
<span id='Ext-grid-property-Store-method-setSource'> // @protected
|
</span> // 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);
|
},
|
|
<span id='Ext-grid-property-Store-method-getProperty'> // @private
|
</span> getProperty : function(row) {
|
return Ext.isNumber(row) ? this.getAt(row) : this.getById(row);
|
},
|
|
<span id='Ext-grid-property-Store-method-setValue'> // @private
|
</span> 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);
|
}
|
},
|
|
<span id='Ext-grid-property-Store-method-remove'> // @private
|
</span> remove : function(prop) {
|
var rec = this.getRec(prop);
|
if (rec) {
|
this.callParent([rec]);
|
delete this.source[prop];
|
}
|
},
|
|
<span id='Ext-grid-property-Store-method-getRec'> // @private
|
</span> getRec : function(prop) {
|
return this.getById(prop);
|
},
|
|
<span id='Ext-grid-property-Store-method-getSource'> // @protected
|
</span> // Should only be called by the grid. Use grid.getSource instead.
|
getSource : function() {
|
return this.source;
|
}
|
});</pre>
|
</body>
|
</html>
|