EventDetails.js
9.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
/**
* @class Ext.calendar.form.EventDetails
* @extends Ext.form.Panel
* <p>A custom form used for detailed editing of events.</p>
* <p>This is pretty much a standard form that is simply pre-configured for the options needed by the
* calendar components. It is also configured to automatically bind records of type {@link Ext.calendar.EventRecord}
* to and from the form.</p>
* <p>This form also provides custom events specific to the calendar so that other calendar components can be easily
* notified when an event has been edited via this component.</p>
* <p>The default configs are as follows:</p><pre><code>
fieldDefaults: {
msgTarget: 'side',
labelWidth: 65
},
title: 'Event Form',
titleTextAdd: 'Add Event',
titleTextEdit: 'Edit Event',
bodyStyle: 'background:transparent;padding:20px 20px 10px;',
border: false,
buttonAlign: 'center',
autoHeight: true,
cls: 'ext-evt-edit-form',
</code></pre>
* @constructor
* @param {Object} config The config object
*/
Ext.define('Ext.calendar.form.EventDetails', {
extend: 'Ext.form.Panel',
alias: 'widget.eventeditform',
requires: [
'Ext.calendar.form.field.DateRange',
'Ext.calendar.form.field.ReminderCombo',
'Ext.calendar.data.EventMappings',
'Ext.calendar.form.field.CalendarCombo'
],
fieldDefaults: {
msgTarget: 'side',
labelWidth: 65
},
title: 'Event Form',
titleTextAdd: 'Add Event',
titleTextEdit: 'Edit Event',
bodyStyle: 'background:transparent;padding:20px 20px 10px;',
border: false,
buttonAlign: 'center',
autoHeight: true,
// to allow for the notes field to autogrow
cls: 'ext-evt-edit-form',
// private properties:
newId: 10000,
layout: 'column',
// private
initComponent: function() {
this.addEvents({
/**
* @event eventadd
* Fires after a new event is added
* @param {Ext.calendar.form.EventDetails} this
* @param {Ext.calendar.EventRecord} rec The new {@link Ext.calendar.EventRecord record} that was added
*/
eventadd: true,
/**
* @event eventupdate
* Fires after an existing event is updated
* @param {Ext.calendar.form.EventDetails} this
* @param {Ext.calendar.EventRecord} rec The new {@link Ext.calendar.EventRecord record} that was updated
*/
eventupdate: true,
/**
* @event eventdelete
* Fires after an event is deleted
* @param {Ext.calendar.form.EventDetails} this
* @param {Ext.calendar.EventRecord} rec The new {@link Ext.calendar.EventRecord record} that was deleted
*/
eventdelete: true,
/**
* @event eventcancel
* Fires after an event add/edit operation is canceled by the user and no store update took place
* @param {Ext.calendar.form.EventDetails} this
* @param {Ext.calendar.EventRecord} rec The new {@link Ext.calendar.EventRecord record} that was canceled
*/
eventcancel: true
});
this.titleField = new Ext.form.Text({
fieldLabel: 'Title',
name: Ext.calendar.data.EventMappings.Title.name,
emptyText: 'Event Title',
allowBlank: false,
anchor: '90%'
});
this.dateRangeField = new Ext.calendar.form.field.DateRange({
fieldLabel: 'When',
singleLine: false,
anchor: '90%'
});
this.reminderField = new Ext.calendar.form.field.ReminderCombo({
name: 'Reminder',
anchor: '70%'
});
this.notesField = new Ext.form.TextArea({
fieldLabel: 'Notes',
name: Ext.calendar.data.EventMappings.Notes.name,
grow: true,
growMax: 150,
anchor: '100%'
});
this.locationField = new Ext.form.Text({
fieldLabel: 'Location',
name: Ext.calendar.data.EventMappings.Location.name,
anchor: '100%'
});
this.urlField = new Ext.form.Text({
fieldLabel: 'Web Link',
name: Ext.calendar.data.EventMappings.Url.name,
anchor: '100%'
});
var leftFields = [this.titleField, this.dateRangeField, this.reminderField],
rightFields = [this.notesField, this.locationField, this.urlField];
if (this.calendarStore) {
this.calendarField = new Ext.calendar.form.field.CalendarCombo({
store: this.calendarStore,
anchor: '70%',
name: Ext.calendar.data.EventMappings.CalendarId.name
});
leftFields.splice(2, 0, this.calendarField);
}
this.items = [{
id: 'left-col',
columnWidth: 0.65,
layout: 'anchor',
border: false,
items: leftFields
},
{
id: 'right-col',
columnWidth: 0.35,
layout: 'anchor',
border: false,
items: rightFields
}];
this.fbar = [{
cls: 'ext-del-btn',
itemId: this.id+'-del-btn',
text: 'Delete Event',
scope: this,
handler: this.onDelete,
minWidth: 150
},
{
text: 'Save',
scope: this,
handler: this.onSave
},
{
text: 'Cancel',
scope: this,
handler: this.onCancel
}];
this.callParent(arguments);
},
// inherited docs
loadRecord: function(rec){
this.form.reset().loadRecord.apply(this.form, arguments);
this.activeRecord = rec;
this.dateRangeField.setValue(rec.data);
if(this.calendarStore){
this.form.setValues({
'calendar': rec.data[Ext.calendar.data.EventMappings.CalendarId.name]
});
}
if (rec.phantom) {
this.setTitle(this.titleTextAdd);
this.down('#' + this.id + '-del-btn').hide();
}
else {
this.setTitle(this.titleTextEdit);
this.down('#' + this.id + '-del-btn').show();
}
this.titleField.focus();
},
// inherited docs
updateRecord: function(){
var dates = this.dateRangeField.getValue(),
M = Ext.calendar.data.EventMappings,
rec = this.activeRecord,
fs = rec.fields,
dirty = false;
rec.beginEdit();
//TODO: This block is copied directly from BasicForm.updateRecord.
// Unfortunately since that method internally calls begin/endEdit all
// updates happen and the record dirty status is reset internally to
// that call. We need the dirty status, plus currently the DateRangeField
// does not map directly to the record values, so for now we'll duplicate
// the setter logic here (we need to be able to pick up any custom-added
// fields generically). Need to revisit this later and come up with a better solution.
fs.each(function(f){
var field = this.form.findField(f.name);
if(field){
var value = field.getValue();
if (value.getGroupValue) {
value = value.getGroupValue();
}
else if (field.eachItem) {
value = [];
field.eachItem(function(item){
value.push(item.getValue());
});
}
rec.set(f.name, value);
}
}, this);
rec.set(M.StartDate.name, dates[0]);
rec.set(M.EndDate.name, dates[1]);
rec.set(M.IsAllDay.name, dates[2]);
dirty = rec.dirty;
rec.endEdit();
return dirty;
},
setStartDate: function(d) {
var me = this,
duration = me.dateRangeField.getDuration();
me.dateRangeField.setDT(d, 'start');
// Set the end time to keep the duration the same
me.dateRangeField.setDT(new Date(me.dateRangeField.getDT('start').getTime() + duration), 'end');
},
setEndDate: function(d) {
this.dateRangeField.setDT(d, 'end');
},
// private
onCancel: function() {
this.cleanup(true);
this.fireEvent('eventcancel', this, this.activeRecord);
},
// private
cleanup: function(hide) {
if (this.activeRecord && this.activeRecord.dirty) {
this.activeRecord.reject();
}
delete this.activeRecord;
if (this.form.isDirty()) {
this.form.reset();
}
},
// private
onSave: function(){
if(!this.form.isValid()){
return;
}
if(!this.updateRecord()){
this.onCancel();
return;
}
this.fireEvent(this.activeRecord.phantom ? 'eventadd' : 'eventupdate', this, this.activeRecord);
},
// private
onDelete: function() {
this.fireEvent('eventdelete', this, this.activeRecord);
}
});