/*! * Extensible 1.0-beta2 * Copyright(c) 2010-2011 Extensible, LLC * licensing@ext.ensible.com * http://ext.ensible.com */ /** * @class Ext.ensible.cal.CalendarMappings * @extends Object * A simple object that provides the field definitions for * {@link Ext.ensible.cal.CalendarRecord CalendarRecord}s so that they can be easily overridden. * *
There are several ways of overriding the default Calendar record mappings to customize how * Ext records are mapped to your back-end data model. If you only need to change a handful * of field properties you can directly modify the CalendarMappings object as needed and then * reconfigure it. The simplest approach is to only override specific field attributes:
*
var M = Ext.ensible.cal.CalendarMappings;
M.Title.mapping = 'cal_title';
M.Title.name = 'CalTitle';
Ext.ensible.cal.CalendarRecord.reconfigure();
*
* You can alternately override an entire field definition using object-literal syntax, or * provide your own custom field definitions (as in the following example). Note that if you do * this, you MUST include a complete field definition, including the type attribute * if the field is not the default type of string.
*
// Add a new field that does not exist in the default CalendarMappings:
Ext.ensible.cal.CalendarMappings.Owner = {
name: 'Owner',
mapping: 'owner',
type: 'string'
};
Ext.ensible.cal.CalendarRecord.reconfigure();
*
* If you are overriding a significant number of field definitions it may be more convenient * to simply redefine the entire EventMappings object from scratch. The following example * redefines the same fields that exist in the standard EventRecord object but the names and * mappings have all been customized. Note that the name of each field definition object * (e.g., 'EventId') should NOT be changed for the default EventMappings fields as it * is the key used to access the field data programmatically.
*
Ext.ensible.cal.CalendarMappings = {
CalendarId: {name:'CalendarId', mapping: 'id', type: 'int'},
Title: {name:'Title', mapping: 'title', type: 'string'},
Description: {name:'Description', mapping: 'desc', type: 'string'},
ColorId: {name:'ColorId', mapping: 'color', type: 'int'},
IsHidden: {name:'IsHidden', mapping: 'hidden', type: 'boolean'},
// We can also add some new fields that do not exist in the standard EventRecord:
Owner: {name: 'Owner', mapping: 'owner'}
};
// Don't forget to reconfigure!
Ext.ensible.cal.CalendarRecord.reconfigure();
*
* NOTE: Any record reconfiguration you want to perform must be done PRIOR to * initializing your data store, otherwise the changes will not be reflected in the store's records.
* *Another important note is that if you alter the default mapping for CalendarId, make sure to add * that mapping as the idProperty of your data reader, otherwise it won't recognize how to * access the data correctly and will treat existing records as phantoms. For example:
*
var reader = new Ext.data.JsonReader({
totalProperty: 'total',
successProperty: 'success',
root: 'data',
messageProperty: 'message',
// read the id property generically, regardless of the mapping:
idProperty: Ext.ensible.cal.CalendarMappings.CalendarId.mapping || 'id',
// this is also a handy way to configure your reader's fields generically:
fields: Ext.ensible.cal.CalendarRecord.prototype.fields.getRange()
});
*/
Ext.ensible.cal.CalendarMappings = {
CalendarId: {name:'CalendarId', mapping: 'id', type: 'int'},
Title: {name:'Title', mapping: 'title', type: 'string'},
Description: {name:'Description', mapping: 'desc', type: 'string'},
ColorId: {name:'ColorId', mapping: 'color', type: 'int'},
IsHidden: {name:'IsHidden', mapping: 'hidden', type: 'boolean'}
};