Alien-Web-ExtJS-V3
view release on metacpan or search on metacpan
share/docs/source/DataReader.html view on Meta::CPAN
this.recordType = Ext.isArray(recordType) ?
Ext.data.Record.create(recordType) : recordType;
// if recordType defined make sure extraction functions are defined
if (this.recordType){
this.buildExtractors();
}
};
Ext.data.DataReader.prototype = {
<span id='Ext-data-DataReader-cfg-messageProperty'> /**
</span> * @cfg {String} messageProperty [undefined] Optional name of a property within a server-response that represents a user-feedback message.
*/
<span id='Ext-data-DataReader-method-getTotal'> /**
</span> * Abstract method created in extension's buildExtractors impl.
*/
getTotal: Ext.emptyFn,
<span id='Ext-data-DataReader-method-getRoot'> /**
</span> * Abstract method created in extension's buildExtractors impl.
*/
getRoot: Ext.emptyFn,
<span id='Ext-data-DataReader-method-getMessage'> /**
</span> * Abstract method created in extension's buildExtractors impl.
*/
getMessage: Ext.emptyFn,
<span id='Ext-data-DataReader-method-getSuccess'> /**
</span> * Abstract method created in extension's buildExtractors impl.
*/
getSuccess: Ext.emptyFn,
<span id='Ext-data-DataReader-method-getId'> /**
</span> * Abstract method created in extension's buildExtractors impl.
*/
getId: Ext.emptyFn,
<span id='Ext-data-DataReader-method-buildExtractors'> /**
</span> * Abstract method, overridden in DataReader extensions such as {@link Ext.data.JsonReader} and {@link Ext.data.XmlReader}
*/
buildExtractors : Ext.emptyFn,
<span id='Ext-data-DataReader-method-extractValues'> /**
</span> * Abstract method overridden in DataReader extensions such as {@link Ext.data.JsonReader} and {@link Ext.data.XmlReader}
*/
extractValues : Ext.emptyFn,
<span id='Ext-data-DataReader-method-realize'> /**
</span> * Used for un-phantoming a record after a successful database insert. Sets the records pk along with new data from server.
* You <b>must</b> return at least the database pk using the idProperty defined in your DataReader configuration. The incoming
* data from server will be merged with the data in the local record.
* In addition, you <b>must</b> return record-data from the server in the same order received.
* Will perform a commit as well, un-marking dirty-fields. Store's "update" event will be suppressed.
* @param {Record/Record[]} record The phantom record to be realized.
* @param {Object/Object[]} data The new record data to apply. Must include the primary-key from database defined in idProperty field.
*/
realize: function(rs, data){
if (Ext.isArray(rs)) {
for (var i = rs.length - 1; i >= 0; i--) {
// recurse
if (Ext.isArray(data)) {
this.realize(rs.splice(i,1).shift(), data.splice(i,1).shift());
}
else {
// weird...rs is an array but data isn't?? recurse but just send in the whole invalid data object.
// the else clause below will detect !this.isData and throw exception.
this.realize(rs.splice(i,1).shift(), data);
}
}
}
else {
// If rs is NOT an array but data IS, see if data contains just 1 record. If so extract it and carry on.
if (Ext.isArray(data) && data.length == 1) {
data = data.shift();
}
if (!this.isData(data)) {
// TODO: Let exception-handler choose to commit or not rather than blindly rs.commit() here.
//rs.commit();
throw new Ext.data.DataReader.Error('realize', rs);
}
rs.phantom = false; // <-- That's what it's all about
rs._phid = rs.id; // <-- copy phantom-id -> _phid, so we can remap in Store#onCreateRecords
rs.id = this.getId(data);
rs.data = data;
rs.commit();
rs.store.reMap(rs);
}
},
<span id='Ext-data-DataReader-method-update'> /**
</span> * Used for updating a non-phantom or "real" record's data with fresh data from server after remote-save.
* If returning data from multiple-records after a batch-update, you <b>must</b> return record-data from the server in
* the same order received. Will perform a commit as well, un-marking dirty-fields. Store's "update" event will be
* suppressed as the record receives fresh new data-hash
* @param {Record/Record[]} rs
* @param {Object/Object[]} data
*/
update : function(rs, data) {
if (Ext.isArray(rs)) {
for (var i=rs.length-1; i >= 0; i--) {
if (Ext.isArray(data)) {
this.update(rs.splice(i,1).shift(), data.splice(i,1).shift());
}
else {
// weird...rs is an array but data isn't?? recurse but just send in the whole data object.
// the else clause below will detect !this.isData and throw exception.
this.update(rs.splice(i,1).shift(), data);
}
}
}
else {
// If rs is NOT an array but data IS, see if data contains just 1 record. If so extract it and carry on.
if (Ext.isArray(data) && data.length == 1) {
data = data.shift();
}
if (this.isData(data)) {
rs.data = Ext.apply(rs.data, data);
}
rs.commit();
}
},
<span id='Ext-data-DataReader-method-extractData'> /**
</span> * returns extracted, type-cast rows of data. Iterates to call #extractValues for each row
* @param {Object[]/Object} data-root from server response
* @param {Boolean} returnRecords [false] Set true to return instances of Ext.data.Record
* @private
*/
extractData : function(root, returnRecords) {
// A bit ugly this, too bad the Record's raw data couldn't be saved in a common property named "raw" or something.
var rawName = (this instanceof Ext.data.JsonReader) ? 'json' : 'node';
var rs = [];
// Had to add Check for XmlReader, #isData returns true if root is an Xml-object. Want to check in order to re-factor
// #extractData into DataReader base, since the implementations are almost identical for JsonReader, XmlReader
if (this.isData(root) && !(this instanceof Ext.data.XmlReader)) {
root = [root];
}
var f = this.recordType.prototype.fields,
fi = f.items,
fl = f.length,
rs = [];
if (returnRecords === true) {
var Record = this.recordType;
for (var i = 0; i < root.length; i++) {
var n = root[i];
var record = new Record(this.extractValues(n, fi, fl), this.getId(n));
record[rawName] = n; // <-- There's implementation of ugly bit, setting the raw record-data.
rs.push(record);
}
}
else {
for (var i = 0; i < root.length; i++) {
var data = this.extractValues(root[i], fi, fl);
data[this.meta.idProperty] = this.getId(root[i]);
rs.push(data);
}
}
return rs;
},
<span id='Ext-data-DataReader-method-isData'> /**
</span> * Returns true if the supplied data-hash <b>looks</b> and quacks like data. Checks to see if it has a key
* corresponding to idProperty defined in your DataReader config containing non-empty pk.
* @param {Object} data
( run in 0.936 second using v1.01-cache-2.11-cpan-adec679a428 )