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.CalendarPanel"></div>/**
16 * @class Ext.calendar.CalendarPanel
18 * <p>This is the default container for Ext calendar views. It supports day, week and month views as well
19 * as a built-in event edit form. The only requirement for displaying a calendar is passing in a valid
20 * {@link #calendarStore} config containing records of type {@link Ext.calendar.EventRecord EventRecord}. In order
21 * to make the calendar interactive (enable editing, drag/drop, etc.) you can handle any of the various
22 * events fired by the underlying views and exposed through the CalendarPanel.</p>
23 * {@link #layoutConfig} option if needed.</p>
25 * @param {Object} config The config object
26 * @xtype calendarpanel
28 Ext.calendar.CalendarPanel = Ext.extend(Ext.Panel, {
29 <div id="cfg-Ext.calendar.CalendarPanel-showDayView"></div>/**
30 * @cfg {Boolean} showDayView
31 * True to include the day view (and toolbar button), false to hide them (defaults to true).
34 <div id="cfg-Ext.calendar.CalendarPanel-showWeekView"></div>/**
35 * @cfg {Boolean} showWeekView
36 * True to include the week view (and toolbar button), false to hide them (defaults to true).
39 <div id="cfg-Ext.calendar.CalendarPanel-showMonthView"></div>/**
40 * @cfg {Boolean} showMonthView
41 * True to include the month view (and toolbar button), false to hide them (defaults to true).
42 * If the day and week views are both hidden, the month view will show by default even if
43 * this config is false.
46 <div id="cfg-Ext.calendar.CalendarPanel-showNavBar"></div>/**
47 * @cfg {Boolean} showNavBar
48 * True to display the calendar navigation toolbar, false to hide it (defaults to true). Note that
49 * if you hide the default navigation toolbar you'll have to provide an alternate means of navigating the calendar.
52 <div id="cfg-Ext.calendar.CalendarPanel-todayText"></div>/**
53 * @cfg {String} todayText
54 * Alternate text to use for the 'Today' nav bar button.
57 <div id="cfg-Ext.calendar.CalendarPanel-showTodayText"></div>/**
58 * @cfg {Boolean} showTodayText
59 * True to show the value of {@link #todayText} instead of today's date in the calendar's current day box,
60 * false to display the day number(defaults to true).
63 <div id="cfg-Ext.calendar.CalendarPanel-showTime"></div>/**
64 * @cfg {Boolean} showTime
65 * True to display the current time next to the date in the calendar's current day box, false to not show it
69 <div id="cfg-Ext.calendar.CalendarPanel-dayText"></div>/**
70 * @cfg {String} dayText
71 * Alternate text to use for the 'Day' nav bar button.
74 <div id="cfg-Ext.calendar.CalendarPanel-weekText"></div>/**
75 * @cfg {String} weekText
76 * Alternate text to use for the 'Week' nav bar button.
79 <div id="cfg-Ext.calendar.CalendarPanel-monthText"></div>/**
80 * @cfg {String} monthText
81 * Alternate text to use for the 'Month' nav bar button.
87 layoutOnCardChange: true,
92 startDate: new Date(),
95 initComponent: function() {
97 cls: 'ext-cal-toolbar',
99 buttonAlign: 'center',
101 id: this.id + '-tb-prev',
102 handler: this.onPrevClick,
104 iconCls: 'x-tbar-page-prev'
110 if (this.showDayView) {
111 this.tbar.items.push({
112 id: this.id + '-tb-day',
114 handler: this.onDayClick,
116 toggleGroup: 'tb-views'
120 if (this.showWeekView) {
121 this.tbar.items.push({
122 id: this.id + '-tb-week',
124 handler: this.onWeekClick,
126 toggleGroup: 'tb-views'
130 if (this.showMonthView || this.viewCount == 0) {
131 this.tbar.items.push({
132 id: this.id + '-tb-month',
133 text: this.monthText,
134 handler: this.onMonthClick,
136 toggleGroup: 'tb-views'
139 this.showMonthView = true;
141 this.tbar.items.push({
142 id: this.id + '-tb-next',
143 handler: this.onNextClick,
145 iconCls: 'x-tbar-page-next'
147 this.tbar.items.push('->');
149 var idx = this.viewCount - 1;
150 this.activeItem = this.activeItem === undefined ? idx: (this.activeItem > idx ? idx: this.activeItem);
152 if (this.showNavBar === false) {
154 this.addClass('x-calendar-nonav');
157 Ext.calendar.CalendarPanel.superclass.initComponent.call(this);
160 <div id="event-Ext.calendar.CalendarPanel-eventadd"></div>/**
162 * Fires after a new event is added to the underlying store
163 * @param {Ext.calendar.CalendarPanel} this
164 * @param {Ext.calendar.EventRecord} rec The new {@link Ext.calendar.EventRecord record} that was added
167 <div id="event-Ext.calendar.CalendarPanel-eventupdate"></div>/**
169 * Fires after an existing event is updated
170 * @param {Ext.calendar.CalendarPanel} this
171 * @param {Ext.calendar.EventRecord} rec The new {@link Ext.calendar.EventRecord record} that was updated
174 <div id="event-Ext.calendar.CalendarPanel-eventdelete"></div>/**
176 * Fires after an event is removed from the underlying store
177 * @param {Ext.calendar.CalendarPanel} this
178 * @param {Ext.calendar.EventRecord} rec The new {@link Ext.calendar.EventRecord record} that was removed
181 <div id="event-Ext.calendar.CalendarPanel-eventcancel"></div>/**
183 * Fires after an event add/edit operation is canceled by the user and no store update took place
184 * @param {Ext.calendar.CalendarPanel} this
185 * @param {Ext.calendar.EventRecord} rec The new {@link Ext.calendar.EventRecord record} that was canceled
188 <div id="event-Ext.calendar.CalendarPanel-viewchange"></div>/**
190 * Fires after a different calendar view is activated (but not when the event edit form is activated)
191 * @param {Ext.calendar.CalendarPanel} this
192 * @param {Ext.CalendarView} view The view being activated (any valid {@link Ext.calendar.CalendarView CalendarView} subclass)
193 * @param {Object} info Extra information about the newly activated view. This is a plain object
194 * with following properties:<div class="mdetail-params"><ul>
195 * <li><b><code>activeDate</code></b> : <div class="sub-desc">The currently-selected date</div></li>
196 * <li><b><code>viewStart</code></b> : <div class="sub-desc">The first date in the new view range</div></li>
197 * <li><b><code>viewEnd</code></b> : <div class="sub-desc">The last date in the new view range</div></li>
203 // NOTE: CalendarPanel also relays the following events from contained views as if they originated from this:
205 <div id="event-Ext.calendar.CalendarPanel-eventsrendered"></div>/**
206 * @event eventsrendered
207 * Fires after events are finished rendering in the view
208 * @param {Ext.calendar.CalendarPanel} this
210 <div id="event-Ext.calendar.CalendarPanel-eventclick"></div>/**
212 * Fires after the user clicks on an event element
213 * @param {Ext.calendar.CalendarPanel} this
214 * @param {Ext.calendar.EventRecord} rec The {@link Ext.calendar.EventRecord record} for the event that was clicked on
215 * @param {HTMLNode} el The DOM node that was clicked on
217 <div id="event-Ext.calendar.CalendarPanel-eventover"></div>/**
219 * Fires anytime the mouse is over an event element
220 * @param {Ext.calendar.CalendarPanel} this
221 * @param {Ext.calendar.EventRecord} rec The {@link Ext.calendar.EventRecord record} for the event that the cursor is over
222 * @param {HTMLNode} el The DOM node that is being moused over
224 <div id="event-Ext.calendar.CalendarPanel-eventout"></div>/**
226 * Fires anytime the mouse exits an event element
227 * @param {Ext.calendar.CalendarPanel} this
228 * @param {Ext.calendar.EventRecord} rec The {@link Ext.calendar.EventRecord record} for the event that the cursor exited
229 * @param {HTMLNode} el The DOM node that was exited
231 <div id="event-Ext.calendar.CalendarPanel-datechange"></div>/**
233 * Fires after the start date of the view changes
234 * @param {Ext.calendar.CalendarPanel} this
235 * @param {Date} startDate The start date of the view (as explained in {@link #getStartDate}
236 * @param {Date} viewStart The first displayed date in the view
237 * @param {Date} viewEnd The last displayed date in the view
239 <div id="event-Ext.calendar.CalendarPanel-rangeselect"></div>/**
241 * Fires after the user drags on the calendar to select a range of dates/times in which to create an event
242 * @param {Ext.calendar.CalendarPanel} this
243 * @param {Object} dates An object containing the start (StartDate property) and end (EndDate property) dates selected
244 * @param {Function} callback A callback function that MUST be called after the event handling is complete so that
245 * the view is properly cleaned up (shim elements are persisted in the view while the user is prompted to handle the
246 * range selection). The callback is already created in the proper scope, so it simply needs to be executed as a standard
247 * function call (e.g., callback()).
249 <div id="event-Ext.calendar.CalendarPanel-eventmove"></div>/**
251 * Fires after an event element is dragged by the user and dropped in a new position
252 * @param {Ext.calendar.CalendarPanel} this
253 * @param {Ext.calendar.EventRecord} rec The {@link Ext.calendar.EventRecord record} for the event that was moved with
254 * updated start and end dates
256 <div id="event-Ext.calendar.CalendarPanel-initdrag"></div>/**
258 * Fires when a drag operation is initiated in the view
259 * @param {Ext.calendar.CalendarPanel} this
261 <div id="event-Ext.calendar.CalendarPanel-eventresize"></div>/**
263 * Fires after the user drags the resize handle of an event to resize it
264 * @param {Ext.calendar.CalendarPanel} this
265 * @param {Ext.calendar.EventRecord} rec The {@link Ext.calendar.EventRecord record} for the event that was resized
266 * containing the updated start and end dates
268 <div id="event-Ext.calendar.CalendarPanel-dayclick"></div>/**
270 * Fires after the user clicks within a day/week view container and not on an event element
271 * @param {Ext.calendar.CalendarPanel} this
272 * @param {Date} dt The date/time that was clicked on
273 * @param {Boolean} allday True if the day clicked on represents an all-day box, else false.
274 * @param {Ext.Element} el The Element that was clicked on
278 this.layout = 'card';
279 // do not allow override
280 if (this.showDayView) {
281 var day = Ext.apply({
284 showToday: this.showToday,
285 showTodayText: this.showTodayText,
286 showTime: this.showTime
290 day.id = this.id + '-day';
291 day.store = day.store || this.eventStore;
292 this.initEventRelay(day);
295 if (this.showWeekView) {
296 var wk = Ext.applyIf({
298 title: this.weekText,
299 showToday: this.showToday,
300 showTodayText: this.showTodayText,
301 showTime: this.showTime
305 wk.id = this.id + '-week';
306 wk.store = wk.store || this.eventStore;
307 this.initEventRelay(wk);
310 if (this.showMonthView) {
311 var month = Ext.applyIf({
313 title: this.monthText,
314 showToday: this.showToday,
315 showTodayText: this.showTodayText,
316 showTime: this.showTime,
319 fn: function(vw, dt) {
328 month.id = this.id + '-month';
329 month.store = month.store || this.eventStore;
330 this.initEventRelay(month);
334 this.add(Ext.applyIf({
335 xtype: 'eventeditform',
336 id: this.id + '-edit',
337 calendarStore: this.calendarStore,
345 fn: this.onEventUpdate
349 fn: this.onEventDelete
353 fn: this.onEventCancel
361 initEventRelay: function(cfg) {
362 cfg.listeners = cfg.listeners || {};
363 cfg.listeners.afterrender = {
365 // relay the view events so that app code only has to handle them in one place
366 this.relayEvents(c, ['eventsrendered', 'eventclick', 'eventover', 'eventout', 'dayclick',
367 'eventmove', 'datechange', 'rangeselect', 'eventdelete', 'eventresize', 'initdrag']);
375 afterRender: function() {
376 Ext.calendar.CalendarPanel.superclass.afterRender.call(this);
377 this.fireViewChange();
381 onLayout: function() {
382 Ext.calendar.CalendarPanel.superclass.onLayout.call(this);
383 if (!this.navInitComplete) {
384 this.updateNavState();
385 this.navInitComplete = true;
390 onEventAdd: function(form, rec) {
391 rec.data[Ext.calendar.EventMappings.IsNew.name] = false;
392 this.eventStore.add(rec);
394 this.fireEvent('eventadd', this, rec);
398 onEventUpdate: function(form, rec) {
401 this.fireEvent('eventupdate', this, rec);
405 onEventDelete: function(form, rec) {
406 this.eventStore.remove(rec);
408 this.fireEvent('eventdelete', this, rec);
412 onEventCancel: function(form, rec) {
414 this.fireEvent('eventcancel', this, rec);
417 <div id="method-Ext.calendar.CalendarPanel-showEditForm"></div>/**
418 * Shows the built-in event edit form for the passed in event record. This method automatically
419 * hides the calendar views and navigation toolbar. To return to the calendar, call {@link #hideEditForm}.
420 * @param {Ext.calendar.EventRecord} record The event record to edit
421 * @return {Ext.calendar.CalendarPanel} this
423 showEditForm: function(rec) {
424 this.preEditView = this.layout.activeItem.id;
425 this.setActiveView(this.id + '-edit');
426 this.layout.activeItem.loadRecord(rec);
430 <div id="method-Ext.calendar.CalendarPanel-hideEditForm"></div>/**
431 * Hides the built-in event edit form and returns to the previous calendar view. If the edit form is
432 * not currently visible this method has no effect.
433 * @return {Ext.calendar.CalendarPanel} this
435 hideEditForm: function() {
436 if (this.preEditView) {
437 this.setActiveView(this.preEditView);
438 delete this.preEditView;
444 setActiveView: function(id) {
448 if (id == this.id + '-edit') {
449 this.getTopToolbar().hide();
453 l.activeItem.refresh();
454 this.getTopToolbar().show();
455 this.updateNavState();
457 this.activeView = l.activeItem;
458 this.fireViewChange();
462 fireViewChange: function() {
464 view = this.layout.activeItem;
466 if (view.getViewBounds) {
467 vb = view.getViewBounds();
469 activeDate: view.getStartDate(),
474 this.fireEvent('viewchange', this, view, info);
478 updateNavState: function() {
479 if (this.showNavBar !== false) {
480 var item = this.layout.activeItem,
481 suffix = item.id.split(this.id + '-')[1];
483 var btn = Ext.getCmp(this.id + '-tb-' + suffix);
488 <div id="method-Ext.calendar.CalendarPanel-setStartDate"></div>/**
489 * Sets the start date for the currently-active calendar view.
492 setStartDate: function(dt) {
493 this.layout.activeItem.setStartDate(dt, true);
494 this.updateNavState();
495 this.fireViewChange();
499 showWeek: function(dt) {
500 this.setActiveView(this.id + '-week');
501 this.setStartDate(dt);
505 onPrevClick: function() {
506 this.startDate = this.layout.activeItem.movePrev();
507 this.updateNavState();
508 this.fireViewChange();
512 onNextClick: function() {
513 this.startDate = this.layout.activeItem.moveNext();
514 this.updateNavState();
515 this.fireViewChange();
519 onDayClick: function() {
520 this.setActiveView(this.id + '-day');
524 onWeekClick: function() {
525 this.setActiveView(this.id + '-week');
529 onMonthClick: function() {
530 this.setActiveView(this.id + '-month');
533 <div id="method-Ext.calendar.CalendarPanel-getActiveView"></div>/**
534 * Return the calendar view that is currently active, which will be a subclass of
535 * {@link Ext.calendar.CalendarView CalendarView}.
536 * @return {Ext.calendar.CalendarView} The active view
538 getActiveView: function() {
539 return this.layout.activeItem;
543 Ext.reg('calendarpanel', Ext.calendar.CalendarPanel);</pre>