3 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
4 <title>The source code</title>
5 <link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />
6 <script type="text/javascript" src="../resources/prettify/prettify.js"></script>
8 <body onload="prettyPrint();">
9 <pre class="prettyprint lang-js">/*!
10 * Ext JS Library 3.3.1
11 * Copyright(c) 2006-2010 Sencha Inc.
12 * licensing@sencha.com
13 * http://www.sencha.com/license
15 <div id="cls-Ext.calendar.EventEditWindow"></div>/**
16 * @class Ext.calendar.EventEditWindow
18 * <p>A custom window containing a basic edit form used for quick editing of events.</p>
19 * <p>This window also provides custom events specific to the calendar so that other calendar components can be easily
20 * notified when an event has been edited via this component.</p>
22 * @param {Object} config The config object
24 Ext.calendar.EventEditWindow = function(config) {
29 bodyStyle: 'background:transparent;padding:5px 10px 10px;',
34 name: Ext.calendar.EventMappings.Title.name,
40 xtype: 'daterangefield',
47 if (config.calendarStore) {
48 this.calendarStore = config.calendarStore;
49 delete config.calendarStore;
51 formPanelCfg.items.push({
52 xtype: 'calendarpicker',
56 store: this.calendarStore
60 Ext.calendar.EventEditWindow.superclass.constructor.call(this, Ext.apply({
61 titleTextAdd: 'Add Event',
62 titleTextEdit: 'Edit Event',
70 savingMessage: 'Saving changes...',
71 deletingMessage: 'Deleting event...',
75 text: '<a href="#" id="tblink">Edit Details...</a>'
87 handler: this.onDelete,
94 handler: this.onCancel,
102 Ext.extend(Ext.calendar.EventEditWindow, Ext.Window, {
107 initComponent: function() {
108 Ext.calendar.EventEditWindow.superclass.initComponent.call(this);
110 this.formPanel = this.items.items[0];
113 <div id="event-Ext.calendar.EventEditWindow-eventadd"></div>/**
115 * Fires after a new event is added
116 * @param {Ext.calendar.EventEditWindow} this
117 * @param {Ext.calendar.EventRecord} rec The new {@link Ext.calendar.EventRecord record} that was added
120 <div id="event-Ext.calendar.EventEditWindow-eventupdate"></div>/**
122 * Fires after an existing event is updated
123 * @param {Ext.calendar.EventEditWindow} this
124 * @param {Ext.calendar.EventRecord} rec The new {@link Ext.calendar.EventRecord record} that was updated
127 <div id="event-Ext.calendar.EventEditWindow-eventdelete"></div>/**
129 * Fires after an event is deleted
130 * @param {Ext.calendar.EventEditWindow} this
131 * @param {Ext.calendar.EventRecord} rec The new {@link Ext.calendar.EventRecord record} that was deleted
134 <div id="event-Ext.calendar.EventEditWindow-eventcancel"></div>/**
136 * Fires after an event add/edit operation is canceled by the user and no store update took place
137 * @param {Ext.calendar.EventEditWindow} this
138 * @param {Ext.calendar.EventRecord} rec The new {@link Ext.calendar.EventRecord record} that was canceled
141 <div id="event-Ext.calendar.EventEditWindow-editdetails"></div>/**
143 * Fires when the user selects the option in this window to continue editing in the detailed edit form
144 * (by default, an instance of {@link Ext.calendar.EventEditForm}. Handling code should hide this window
145 * and transfer the current event record to the appropriate instance of the detailed form by showing it
146 * and calling {@link Ext.calendar.EventEditForm#loadRecord loadRecord}.
147 * @param {Ext.calendar.EventEditWindow} this
148 * @param {Ext.calendar.EventRecord} rec The {@link Ext.calendar.EventRecord record} that is currently being edited
155 afterRender: function() {
156 Ext.calendar.EventEditWindow.superclass.afterRender.call(this);
158 this.el.addClass('ext-cal-event-win');
160 Ext.get('tblink').on('click',
164 this.fireEvent('editdetails', this, this.activeRecord);
169 <div id="method-Ext.calendar.EventEditWindow-show"></div>/**
170 * Shows the window, rendering it first if necessary, or activates it and brings it to front if hidden.
171 * @param {Ext.data.Record/Object} o Either a {@link Ext.data.Record} if showing the form
172 * for an existing event in edit mode, or a plain object containing a StartDate property (and
173 * optionally an EndDate property) for showing the form in add mode.
174 * @param {String/Element} animateTarget (optional) The target element or id from which the window should
175 * animate while opening (defaults to null with no animation)
176 * @return {Ext.Window} this
178 show: function(o, animateTarget) {
179 // Work around the CSS day cell height hack needed for initial render in IE8/strict:
180 var anim = (Ext.isIE8 && Ext.isStrict) ? null: animateTarget;
182 Ext.calendar.EventEditWindow.superclass.show.call(this, anim,
184 Ext.getCmp('title').focus(false, 100);
186 Ext.getCmp('delete-btn')[o.data && o.data[Ext.calendar.EventMappings.EventId.name] ? 'show': 'hide']();
189 f = this.formPanel.form;
193 this.isAdd = !!rec.data[Ext.calendar.EventMappings.IsNew.name];
195 // Enable adding the default record that was passed in
196 // if it's new even if the user makes no changes
198 this.setTitle(this.titleTextAdd);
201 this.setTitle(this.titleTextEdit);
208 this.setTitle(this.titleTextAdd);
210 var M = Ext.calendar.EventMappings,
211 eventId = M.EventId.name,
212 start = o[M.StartDate.name],
213 end = o[M.EndDate.name] || start.add('h', 1);
215 rec = new Ext.calendar.EventRecord();
216 rec.data[M.EventId.name] = this.newId++;
217 rec.data[M.StartDate.name] = start;
218 rec.data[M.EndDate.name] = end;
219 rec.data[M.IsAllDay.name] = !!o[M.IsAllDay.name] || start.getDate() != end.clone().add(Date.MILLI, 1).getDate();
220 rec.data[M.IsNew.name] = true;
226 if (this.calendarStore) {
227 Ext.getCmp('calendar').setValue(rec.data[Ext.calendar.EventMappings.CalendarId.name]);
229 Ext.getCmp('date-range').setValue(rec.data);
230 this.activeRecord = rec;
236 roundTime: function(dt, incr) {
238 var m = parseInt(dt.getMinutes(), 10);
239 return dt.add('mi', incr - (m % incr));
243 onCancel: function() {
245 this.fireEvent('eventcancel', this);
249 cleanup: function(hide) {
250 if (this.activeRecord && this.activeRecord.dirty) {
251 this.activeRecord.reject();
253 delete this.activeRecord;
256 // Work around the CSS day cell height hack needed for initial render in IE8/strict:
257 //var anim = afterDelete || (Ext.isIE8 && Ext.isStrict) ? null : this.animateTarget;
263 updateRecord: function() {
264 var f = this.formPanel.form,
265 dates = Ext.getCmp('date-range').getValue(),
266 M = Ext.calendar.EventMappings;
268 f.updateRecord(this.activeRecord);
269 this.activeRecord.set(M.StartDate.name, dates[0]);
270 this.activeRecord.set(M.EndDate.name, dates[1]);
271 this.activeRecord.set(M.IsAllDay.name, dates[2]);
272 this.activeRecord.set(M.CalendarId.name, this.formPanel.form.findField('calendar').getValue());
277 if (!this.formPanel.form.isValid()) {
282 if (!this.activeRecord.dirty) {
287 this.fireEvent(this.isAdd ? 'eventadd': 'eventupdate', this, this.activeRecord);
291 onDelete: function() {
292 this.fireEvent('eventdelete', this, this.activeRecord);