3 * Copyright(c) 2006-2010 Ext JS, Inc.
5 * http://www.extjs.com/license
8 * @class Ext.calendar.MonthView
\r
9 * @extends Ext.calendar.CalendarView
\r
10 * <p>Displays a calendar view by month. This class does not usually need ot be used directly as you can
\r
11 * use a {@link Ext.calendar.CalendarPanel CalendarPanel} to manage multiple calendar views at once including
\r
12 * the month view.</p>
\r
14 * @param {Object} config The config object
\r
16 Ext.calendar.MonthView = Ext.extend(Ext.calendar.CalendarView, {
\r
18 * @cfg {Boolean} showTime
\r
19 * True to display the current time in today's box in the calendar, false to not display it (defautls to true)
\r
23 * @cfg {Boolean} showTodayText
\r
24 * True to display the {@link #todayText} string in today's box in the calendar, false to not display it (defautls to true)
\r
26 showTodayText: true,
\r
28 * @cfg {String} todayText
\r
29 * The text to display in the current day's box in the calendar when {@link #showTodayText} is true (defaults to 'Today')
\r
33 * @cfg {Boolean} showHeader
\r
34 * True to display a header beneath the navigation bar containing the week names above each week's column, false not to
\r
35 * show it and instead display the week names in the first row of days in the calendar (defaults to false).
\r
39 * @cfg {Boolean} showWeekLinks
\r
40 * True to display an extra column before the first day in the calendar that links to the {@link Ext.calendar.WeekView view}
\r
41 * for each individual week, false to not show it (defaults to false). If true, the week links can also contain the week
\r
42 * number depending on the value of {@link #showWeekNumbers}.
\r
44 showWeekLinks: false,
\r
46 * @cfg {Boolean} showWeekNumbers
\r
47 * True to show the week number for each week in the calendar in the week link column, false to show nothing (defaults to false).
\r
48 * Note that if {@link #showWeekLinks} is false this config will have no affect even if true.
\r
50 showWeekNumbers: false,
\r
52 * @cfg {String} weekLinkOverClass
\r
53 * The CSS class name applied when the mouse moves over a week link element (only applies when {@link #showWeekLinks} is true,
\r
54 * defaults to 'ext-week-link-over').
\r
56 weekLinkOverClass: 'ext-week-link-over',
\r
58 //private properties -- do not override:
\r
59 daySelector: '.ext-cal-day',
\r
60 moreSelector: '.ext-cal-ev-more',
\r
61 weekLinkSelector: '.ext-cal-week-link',
\r
63 // defaults to auto by month
\r
65 moreElIdDelimiter: '-more-',
\r
66 weekLinkIdDelimiter: 'ext-cal-week-',
\r
69 initComponent: function() {
\r
70 Ext.calendar.MonthView.superclass.initComponent.call(this);
\r
74 * Fires after the user clicks within the view container and not on an event element
\r
75 * @param {Ext.calendar.MonthView} this
\r
76 * @param {Date} dt The date/time that was clicked on
\r
77 * @param {Boolean} allday True if the day clicked on represents an all-day box, else false. Clicks within the
\r
78 * MonthView always return true for this param.
\r
79 * @param {Ext.Element} el The Element that was clicked on
\r
84 * Fires after the user clicks within a week link (when {@link #showWeekLinks is true)
\r
85 * @param {Ext.calendar.MonthView} this
\r
86 * @param {Date} dt The start date of the week that was clicked on
\r
97 initDD: function() {
\r
100 createText: this.ddCreateEventText,
\r
101 moveText: this.ddMoveEventText,
\r
102 ddGroup: 'MonthViewDD'
\r
105 this.dragZone = new Ext.calendar.DragZone(this.el, cfg);
\r
106 this.dropZone = new Ext.calendar.DropZone(this.el, cfg);
\r
110 onDestroy: function() {
\r
111 Ext.destroy(this.ddSelector);
\r
112 Ext.destroy(this.dragZone);
\r
113 Ext.destroy(this.dropZone);
\r
114 Ext.calendar.MonthView.superclass.onDestroy.call(this);
\r
118 afterRender: function() {
\r
120 this.tpl = new Ext.calendar.MonthViewTemplate({
\r
122 showTodayText: this.showTodayText,
\r
123 todayText: this.todayText,
\r
124 showTime: this.showTime,
\r
125 showHeader: this.showHeader,
\r
126 showWeekLinks: this.showWeekLinks,
\r
127 showWeekNumbers: this.showWeekNumbers
\r
130 this.tpl.compile();
\r
131 this.addClass('ext-cal-monthview ext-cal-ct');
\r
133 Ext.calendar.MonthView.superclass.afterRender.call(this);
\r
137 onResize: function() {
\r
138 if (this.monitorResize) {
\r
139 this.maxEventsPerDay = this.getMaxEventsPerDay();
\r
145 forceSize: function() {
\r
146 // Compensate for the week link gutter width if visible
\r
147 if (this.showWeekLinks && this.el && this.el.child) {
\r
148 var hd = this.el.select('.ext-cal-hd-days-tbl'),
\r
149 bgTbl = this.el.select('.ext-cal-bg-tbl'),
\r
150 evTbl = this.el.select('.ext-cal-evt-tbl'),
\r
151 wkLinkW = this.el.child('.ext-cal-week-link').getWidth(),
\r
152 w = this.el.getWidth() - wkLinkW;
\r
158 Ext.calendar.MonthView.superclass.forceSize.call(this);
\r
162 initClock: function() {
\r
163 if (Ext.fly(this.id + '-clock') !== null) {
\r
164 this.prevClockDay = new Date().getDay();
\r
165 if (this.clockTask) {
\r
166 Ext.TaskMgr.stop(this.clockTask);
\r
168 this.clockTask = Ext.TaskMgr.start({
\r
170 var el = Ext.fly(this.id + '-clock'),
\r
173 if (t.getDay() == this.prevClockDay) {
\r
175 el.update(t.format('g:i a'));
\r
179 this.prevClockDay = t.getDay();
\r
190 getEventBodyMarkup: function() {
\r
191 if (!this.eventBodyMarkup) {
\r
192 this.eventBodyMarkup = ['{Title}',
\r
193 '<tpl if="_isReminder">',
\r
194 '<i class="ext-cal-ic ext-cal-ic-rem"> </i>',
\r
196 '<tpl if="_isRecurring">',
\r
197 '<i class="ext-cal-ic ext-cal-ic-rcr"> </i>',
\r
199 '<tpl if="spanLeft">',
\r
200 '<i class="ext-cal-spl"> </i>',
\r
202 '<tpl if="spanRight">',
\r
203 '<i class="ext-cal-spr"> </i>',
\r
207 return this.eventBodyMarkup;
\r
211 getEventTemplate: function() {
\r
212 if (!this.eventTpl) {
\r
214 body = this.getEventBodyMarkup();
\r
216 tpl = !(Ext.isIE || Ext.isOpera) ?
\r
218 '<div id="{_elId}" class="{_selectorCls} {_colorCls} {values.spanCls} ext-cal-evt ext-cal-evr">',
\r
222 : new Ext.XTemplate(
\r
223 '<tpl if="_renderAsAllDay">',
\r
224 '<div id="{_elId}" class="{_selectorCls} {values.spanCls} {_colorCls} ext-cal-evt ext-cal-evo">',
\r
225 '<div class="ext-cal-evm">',
\r
226 '<div class="ext-cal-evi">',
\r
228 '<tpl if="!_renderAsAllDay">',
\r
229 '<div id="{_elId}" class="{_selectorCls} {_colorCls} ext-cal-evt ext-cal-evr">',
\r
232 '<tpl if="_renderAsAllDay">',
\r
239 this.eventTpl = tpl;
\r
241 return this.eventTpl;
\r
245 getTemplateEventData: function(evt) {
\r
246 var M = Ext.calendar.EventMappings,
\r
247 selector = this.getEventSelectorCls(evt[M.EventId.name]),
\r
248 title = evt[M.Title.name];
\r
250 return Ext.applyIf({
\r
251 _selectorCls: selector,
\r
252 _colorCls: 'ext-color-' + (evt[M.CalendarId.name] ?
\r
253 evt[M.CalendarId.name] : 'default') + (evt._renderAsAllDay ? '-ad': ''),
\r
254 _elId: selector + '-' + evt._weekIndex,
\r
255 _isRecurring: evt.Recurrence && evt.Recurrence != '',
\r
256 _isReminder: evt[M.Reminder.name] && evt[M.Reminder.name] != '',
\r
257 Title: (evt[M.IsAllDay.name] ? '': evt[M.StartDate.name].format('g:ia ')) + (!title || title.length == 0 ? '(No title)': title)
\r
263 refresh: function() {
\r
264 if (this.detailPanel) {
\r
265 this.detailPanel.hide();
\r
267 Ext.calendar.MonthView.superclass.refresh.call(this);
\r
269 if (this.showTime !== false) {
\r
275 renderItems: function() {
\r
276 Ext.calendar.WeekEventRenderer.render({
\r
277 eventGrid: this.allDayOnly ? this.allDayGrid: this.eventGrid,
\r
278 viewStart: this.viewStart,
\r
279 tpl: this.getEventTemplate(),
\r
280 maxEventsPerDay: this.maxEventsPerDay,
\r
282 templateDataFn: this.getTemplateEventData.createDelegate(this),
\r
283 evtMaxCount: this.evtMaxCount,
\r
284 weekCount: this.weekCount,
\r
285 dayCount: this.dayCount
\r
287 this.fireEvent('eventsrendered', this);
\r
291 getDayEl: function(dt) {
\r
292 return Ext.get(this.getDayId(dt));
\r
296 getDayId: function(dt) {
\r
297 if (Ext.isDate(dt)) {
\r
298 dt = dt.format('Ymd');
\r
300 return this.id + this.dayElIdDelimiter + dt;
\r
304 getWeekIndex: function(dt) {
\r
305 var el = this.getDayEl(dt).up('.ext-cal-wk-ct');
\r
306 return parseInt(el.id.split('-wk-')[1], 10);
\r
310 getDaySize: function(contentOnly) {
\r
311 var box = this.el.getBox(),
\r
312 w = box.width / this.dayCount,
\r
313 h = box.height / this.getWeekCount();
\r
316 var hd = this.el.select('.ext-cal-dtitle').first().parent('tr');
\r
317 h = hd ? h - hd.getHeight(true) : h;
\r
326 getEventHeight: function() {
\r
327 if (!this.eventHeight) {
\r
328 var evt = this.el.select('.ext-cal-evt').first();
\r
329 this.eventHeight = evt ? evt.parent('tr').getHeight() : 18;
\r
331 return this.eventHeight;
\r
335 getMaxEventsPerDay: function() {
\r
336 var dayHeight = this.getDaySize(true).height,
\r
337 h = this.getEventHeight(),
\r
338 max = Math.max(Math.floor((dayHeight - h) / h), 0);
\r
344 getDayAt: function(x, y) {
\r
345 var box = this.el.getBox(),
\r
346 daySize = this.getDaySize(),
\r
347 dayL = Math.floor(((x - box.x) / daySize.width)),
\r
348 dayT = Math.floor(((y - box.y) / daySize.height)),
\r
349 days = (dayT * 7) + dayL,
\r
350 dt = this.viewStart.add(Date.DAY, days);
\r
353 el: this.getDayEl(dt)
\r
358 moveNext: function() {
\r
359 return this.moveMonths(1);
\r
363 movePrev: function() {
\r
364 return this.moveMonths( - 1);
\r
368 onInitDrag: function() {
\r
369 Ext.calendar.MonthView.superclass.onInitDrag.call(this);
\r
370 Ext.select(this.daySelector).removeClass(this.dayOverClass);
\r
371 if (this.detailPanel) {
\r
372 this.detailPanel.hide();
\r
377 onMoreClick: function(dt) {
\r
378 if (!this.detailPanel) {
\r
379 this.detailPanel = new Ext.Panel({
\r
380 id: this.id + '-details-panel',
\r
381 title: dt.format('F j'),
\r
384 renderTo: Ext.getBody(),
\r
387 handler: function(e, t, p) {
\r
392 xtype: 'monthdaydetailview',
\r
393 id: this.id + '-details-view',
\r
398 'eventsrendered': this.onDetailViewUpdated.createDelegate(this)
\r
404 this.detailPanel.setTitle(dt.format('F j'));
\r
406 this.detailPanel.getComponent(this.id + '-details-view').update(dt);
\r
410 onDetailViewUpdated: function(view, dt, numEvents) {
\r
411 var p = this.detailPanel,
\r
412 frameH = p.getFrameHeight(),
\r
413 evtH = this.getEventHeight(),
\r
414 bodyH = frameH + (numEvents * evtH) + 3,
\r
415 dayEl = this.getDayEl(dt),
\r
416 box = dayEl.getBox();
\r
419 p.setHeight(bodyH);
\r
420 p.setWidth(Math.max(box.width, 220));
\r
422 p.getPositionEl().alignTo(dayEl, 't-t?');
\r
426 onHide: function() {
\r
427 Ext.calendar.MonthView.superclass.onHide.call(this);
\r
428 if (this.detailPanel) {
\r
429 this.detailPanel.hide();
\r
434 onClick: function(e, t) {
\r
435 if (this.detailPanel) {
\r
436 this.detailPanel.hide();
\r
438 if (Ext.calendar.MonthView.superclass.onClick.apply(this, arguments)) {
\r
439 // The superclass handled the click already so exit
\r
442 if (this.dropZone) {
\r
443 this.dropZone.clearShims();
\r
445 var el = e.getTarget(this.weekLinkSelector, 3),
\r
449 dt = el.id.split(this.weekLinkIdDelimiter)[1];
\r
450 this.fireEvent('weekclick', this, Date.parseDate(dt, 'Ymd'));
\r
453 el = e.getTarget(this.moreSelector, 3);
\r
455 dt = el.id.split(this.moreElIdDelimiter)[1];
\r
456 this.onMoreClick(Date.parseDate(dt, 'Ymd'));
\r
459 el = e.getTarget('td', 3);
\r
461 if (el.id && el.id.indexOf(this.dayElIdDelimiter) > -1) {
\r
462 parts = el.id.split(this.dayElIdDelimiter);
\r
463 dt = parts[parts.length - 1];
\r
465 this.fireEvent('dayclick', this, Date.parseDate(dt, 'Ymd'), false, Ext.get(this.getDayId(dt)));
\r
472 handleDayMouseEvent: function(e, t, type) {
\r
473 var el = e.getTarget(this.weekLinkSelector, 3, true);
\r
475 el[type == 'over' ? 'addClass': 'removeClass'](this.weekLinkOverClass);
\r
478 Ext.calendar.MonthView.superclass.handleDayMouseEvent.apply(this, arguments);
\r
482 Ext.reg('monthview', Ext.calendar.MonthView);
\r