Upgrade to ExtJS 3.3.1 - Released 11/30/2010
[extjs.git] / examples / calendar / src / EventRecord.js
1 /*!
2  * Ext JS Library 3.3.1
3  * Copyright(c) 2006-2010 Sencha Inc.
4  * licensing@sencha.com
5  * http://www.sencha.com/license
6  */
7 /**
8  * @class Ext.calendar.EventMappings
9  * @extends Object
10  * A simple object that provides the field definitions for EventRecords so that they can be easily overridden.
11  */
12 Ext.calendar.EventMappings = {
13     EventId: {
14         name: 'EventId',
15         mapping: 'id',
16         type: 'int'
17     },
18     CalendarId: {
19         name: 'CalendarId',
20         mapping: 'cid',
21         type: 'int'
22     },
23     Title: {
24         name: 'Title',
25         mapping: 'title',
26         type: 'string'
27     },
28     StartDate: {
29         name: 'StartDate',
30         mapping: 'start',
31         type: 'date',
32         dateFormat: 'c'
33     },
34     EndDate: {
35         name: 'EndDate',
36         mapping: 'end',
37         type: 'date',
38         dateFormat: 'c'
39     },
40     Location: {
41         name: 'Location',
42         mapping: 'loc',
43         type: 'string'
44     },
45     Notes: {
46         name: 'Notes',
47         mapping: 'notes',
48         type: 'string'
49     },
50     Url: {
51         name: 'Url',
52         mapping: 'url',
53         type: 'string'
54     },
55     IsAllDay: {
56         name: 'IsAllDay',
57         mapping: 'ad',
58         type: 'boolean'
59     },
60     Reminder: {
61         name: 'Reminder',
62         mapping: 'rem',
63         type: 'string'
64     },
65     IsNew: {
66         name: 'IsNew',
67         mapping: 'n',
68         type: 'boolean'
69     }
70 };
71
72 /**
73  * @class Ext.calendar.EventRecord
74  * @extends Ext.data.Record
75  * <p>This is the {@link Ext.data.Record Record} specification for calendar event data used by the
76  * {@link Ext.calendar.CalendarPanel CalendarPanel}'s underlying store. It can be overridden as 
77  * necessary to customize the fields supported by events, although the existing column names should
78  * not be altered. If your model fields are named differently you should update the <b>mapping</b>
79  * configs accordingly.</p>
80  * <p>The only required fields when creating a new event record instance are StartDate and
81  * EndDate.  All other fields are either optional are will be defaulted if blank.</p>
82  * <p>Here is a basic example for how to create a new record of this type:<pre><code>
83 rec = new Ext.calendar.EventRecord({
84     StartDate: '2101-01-12 12:00:00',
85     EndDate: '2101-01-12 13:30:00',
86     Title: 'My cool event',
87     Notes: 'Some notes'
88 });
89 </code></pre>
90  * If you have overridden any of the record's data mappings via the Ext.calendar.EventMappings object
91  * you may need to set the values using this alternate syntax to ensure that the fields match up correctly:<pre><code>
92 var M = Ext.calendar.EventMappings;
93
94 rec = new Ext.calendar.EventRecord();
95 rec.data[M.StartDate.name] = '2101-01-12 12:00:00';
96 rec.data[M.EndDate.name] = '2101-01-12 13:30:00';
97 rec.data[M.Title.name] = 'My cool event';
98 rec.data[M.Notes.name] = 'Some notes';
99 </code></pre>
100  * @constructor
101  * @param {Object} data (Optional) An object, the properties of which provide values for the new Record's
102  * fields. If not specified the {@link Ext.data.Field#defaultValue defaultValue}
103  * for each field will be assigned.
104  * @param {Object} id (Optional) The id of the Record. The id is used by the
105  * {@link Ext.data.Store} object which owns the Record to index its collection
106  * of Records (therefore this id should be unique within each store). If an
107  * id is not specified a {@link #phantom}
108  * Record will be created with an {@link #Record.id automatically generated id}.
109  */
110  (function() {
111     var M = Ext.calendar.EventMappings;
112
113     Ext.calendar.EventRecord = Ext.data.Record.create([
114     M.EventId,
115     M.CalendarId,
116     M.Title,
117     M.StartDate,
118     M.EndDate,
119     M.Location,
120     M.Notes,
121     M.Url,
122     M.IsAllDay,
123     M.Reminder,
124     M.IsNew
125     ]);
126
127     /**
128      * Reconfigures the default record definition based on the current Ext.calendar.EventMappings object
129      */
130     Ext.calendar.EventRecord.reconfigure = function() {
131         Ext.calendar.EventRecord = Ext.data.Record.create([
132         M.EventId,
133         M.CalendarId,
134         M.Title,
135         M.StartDate,
136         M.EndDate,
137         M.Location,
138         M.Notes,
139         M.Url,
140         M.IsAllDay,
141         M.Reminder,
142         M.IsNew
143         ]);
144     };
145 })();