Ext.define('Ext.calendar.data.MemoryEventStore', {
extend: 'Ext.data.Store',
model: 'Ext.calendar.data.EventModel',
requires: [
'Ext.data.proxy.Memory',
'Ext.data.reader.Json',
'Ext.data.writer.Json',
'Ext.calendar.data.EventModel',
'Ext.calendar.data.EventMappings'
],
proxy: {
type: 'memory',
reader: {
type: 'json',
root: 'evts'
},
writer: {
type: 'json'
}
},
constructor: function(config){
this.callParent(arguments);
this.sorters = this.sorters || [{
property: Ext.calendar.data.EventMappings.StartDate.name,
direction: 'ASC'
}];
this.idProperty = this.idProperty || Ext.calendar.data.EventMappings.EventId.mapping || 'id';
this.fields = Ext.calendar.data.EventModel.prototype.fields.getRange();
this.onCreateRecords = Ext.Function.createInterceptor(this.onCreateRecords, this.interceptCreateRecords);
this.initRecs();
},
interceptCreateRecords: function(records, operation, success) {
if (success) {
var i = 0,
rec,
len = records.length;
for (; i < len; i++) {
records[i].data[Ext.calendar.data.EventMappings.EventId.name] = records[i].id;
}
}
},
initRecs: function(){
this.each(function(rec){
rec.store = this;
rec.phantom = false;
}, this);
},
onProxyLoad: function(operation) {
var me = this,
records;
if (me.data && me.data.length > 0) {
me.totalCount = me.data.length;
records = me.data.items;
}
else {
var resultSet = operation.getResultSet(),
successful = operation.wasSuccessful();
records = operation.getRecords();
if (resultSet) {
me.totalCount = resultSet.total;
}
if (successful) {
me.loadRecords(records, operation);
}
}
me.loading = false;
me.fireEvent('load', me, records, successful);
}
});