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.MonthView"></div>/**
\r
16 * @class Ext.calendar.MonthView
\r
17 * @extends Ext.calendar.CalendarView
\r
18 * <p>Displays a calendar view by month. This class does not usually need ot be used directly as you can
\r
19 * use a {@link Ext.calendar.CalendarPanel CalendarPanel} to manage multiple calendar views at once including
\r
20 * the month view.</p>
\r
22 * @param {Object} config The config object
\r
24 Ext.calendar.MonthView = Ext.extend(Ext.calendar.CalendarView, {
\r
25 <div id="cfg-Ext.calendar.MonthView-showTime"></div>/**
\r
26 * @cfg {Boolean} showTime
\r
27 * True to display the current time in today's box in the calendar, false to not display it (defautls to true)
\r
30 <div id="cfg-Ext.calendar.MonthView-showTodayText"></div>/**
\r
31 * @cfg {Boolean} showTodayText
\r
32 * True to display the {@link #todayText} string in today's box in the calendar, false to not display it (defautls to true)
\r
34 showTodayText: true,
\r
35 <div id="cfg-Ext.calendar.MonthView-todayText"></div>/**
\r
36 * @cfg {String} todayText
\r
37 * The text to display in the current day's box in the calendar when {@link #showTodayText} is true (defaults to 'Today')
\r
40 <div id="cfg-Ext.calendar.MonthView-showHeader"></div>/**
\r
41 * @cfg {Boolean} showHeader
\r
42 * True to display a header beneath the navigation bar containing the week names above each week's column, false not to
\r
43 * show it and instead display the week names in the first row of days in the calendar (defaults to false).
\r
46 <div id="cfg-Ext.calendar.MonthView-showWeekLinks"></div>/**
\r
47 * @cfg {Boolean} showWeekLinks
\r
48 * True to display an extra column before the first day in the calendar that links to the {@link Ext.calendar.WeekView view}
\r
49 * for each individual week, false to not show it (defaults to false). If true, the week links can also contain the week
\r
50 * number depending on the value of {@link #showWeekNumbers}.
\r
52 showWeekLinks: false,
\r
53 <div id="cfg-Ext.calendar.MonthView-showWeekNumbers"></div>/**
\r
54 * @cfg {Boolean} showWeekNumbers
\r
55 * 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
56 * Note that if {@link #showWeekLinks} is false this config will have no affect even if true.
\r
58 showWeekNumbers: false,
\r
59 <div id="cfg-Ext.calendar.MonthView-weekLinkOverClass"></div>/**
\r
60 * @cfg {String} weekLinkOverClass
\r
61 * The CSS class name applied when the mouse moves over a week link element (only applies when {@link #showWeekLinks} is true,
\r
62 * defaults to 'ext-week-link-over').
\r
64 weekLinkOverClass: 'ext-week-link-over',
\r
66 //private properties -- do not override:
\r
67 daySelector: '.ext-cal-day',
\r
68 moreSelector: '.ext-cal-ev-more',
\r
69 weekLinkSelector: '.ext-cal-week-link',
\r
71 // defaults to auto by month
\r
73 moreElIdDelimiter: '-more-',
\r
74 weekLinkIdDelimiter: 'ext-cal-week-',
\r
77 initComponent: function() {
\r
78 Ext.calendar.MonthView.superclass.initComponent.call(this);
\r
80 <div id="event-Ext.calendar.MonthView-dayclick"></div>/**
\r
82 * Fires after the user clicks within the view container and not on an event element
\r
83 * @param {Ext.calendar.MonthView} this
\r
84 * @param {Date} dt The date/time that was clicked on
\r
85 * @param {Boolean} allday True if the day clicked on represents an all-day box, else false. Clicks within the
\r
86 * MonthView always return true for this param.
\r
87 * @param {Ext.Element} el The Element that was clicked on
\r
90 <div id="event-Ext.calendar.MonthView-weekclick"></div>/**
\r
92 * Fires after the user clicks within a week link (when {@link #showWeekLinks is true)
\r
93 * @param {Ext.calendar.MonthView} this
\r
94 * @param {Date} dt The start date of the week that was clicked on
\r
105 initDD: function() {
\r
108 createText: this.ddCreateEventText,
\r
109 moveText: this.ddMoveEventText,
\r
110 ddGroup: 'MonthViewDD'
\r
113 this.dragZone = new Ext.calendar.DragZone(this.el, cfg);
\r
114 this.dropZone = new Ext.calendar.DropZone(this.el, cfg);
\r
118 onDestroy: function() {
\r
119 Ext.destroy(this.ddSelector);
\r
120 Ext.destroy(this.dragZone);
\r
121 Ext.destroy(this.dropZone);
\r
122 Ext.calendar.MonthView.superclass.onDestroy.call(this);
\r
126 afterRender: function() {
\r
128 this.tpl = new Ext.calendar.MonthViewTemplate({
\r
130 showTodayText: this.showTodayText,
\r
131 todayText: this.todayText,
\r
132 showTime: this.showTime,
\r
133 showHeader: this.showHeader,
\r
134 showWeekLinks: this.showWeekLinks,
\r
135 showWeekNumbers: this.showWeekNumbers
\r
138 this.tpl.compile();
\r
139 this.addClass('ext-cal-monthview ext-cal-ct');
\r
141 Ext.calendar.MonthView.superclass.afterRender.call(this);
\r
145 onResize: function() {
\r
146 if (this.monitorResize) {
\r
147 this.maxEventsPerDay = this.getMaxEventsPerDay();
\r
153 forceSize: function() {
\r
154 // Compensate for the week link gutter width if visible
\r
155 if (this.showWeekLinks && this.el && this.el.child) {
\r
156 var hd = this.el.select('.ext-cal-hd-days-tbl'),
\r
157 bgTbl = this.el.select('.ext-cal-bg-tbl'),
\r
158 evTbl = this.el.select('.ext-cal-evt-tbl'),
\r
159 wkLinkW = this.el.child('.ext-cal-week-link').getWidth(),
\r
160 w = this.el.getWidth() - wkLinkW;
\r
166 Ext.calendar.MonthView.superclass.forceSize.call(this);
\r
170 initClock: function() {
\r
171 if (Ext.fly(this.id + '-clock') !== null) {
\r
172 this.prevClockDay = new Date().getDay();
\r
173 if (this.clockTask) {
\r
174 Ext.TaskMgr.stop(this.clockTask);
\r
176 this.clockTask = Ext.TaskMgr.start({
\r
178 var el = Ext.fly(this.id + '-clock'),
\r
181 if (t.getDay() == this.prevClockDay) {
\r
183 el.update(t.format('g:i a'));
\r
187 this.prevClockDay = t.getDay();
\r
198 getEventBodyMarkup: function() {
\r
199 if (!this.eventBodyMarkup) {
\r
200 this.eventBodyMarkup = ['{Title}',
\r
201 '<tpl if="_isReminder">',
\r
202 '<i class="ext-cal-ic ext-cal-ic-rem"> </i>',
\r
204 '<tpl if="_isRecurring">',
\r
205 '<i class="ext-cal-ic ext-cal-ic-rcr"> </i>',
\r
207 '<tpl if="spanLeft">',
\r
208 '<i class="ext-cal-spl"> </i>',
\r
210 '<tpl if="spanRight">',
\r
211 '<i class="ext-cal-spr"> </i>',
\r
215 return this.eventBodyMarkup;
\r
219 getEventTemplate: function() {
\r
220 if (!this.eventTpl) {
\r
222 body = this.getEventBodyMarkup();
\r
224 tpl = !(Ext.isIE || Ext.isOpera) ?
\r
226 '<div id="{_elId}" class="{_selectorCls} {_colorCls} {values.spanCls} ext-cal-evt ext-cal-evr">',
\r
230 : new Ext.XTemplate(
\r
231 '<tpl if="_renderAsAllDay">',
\r
232 '<div id="{_elId}" class="{_selectorCls} {values.spanCls} {_colorCls} ext-cal-evt ext-cal-evo">',
\r
233 '<div class="ext-cal-evm">',
\r
234 '<div class="ext-cal-evi">',
\r
236 '<tpl if="!_renderAsAllDay">',
\r
237 '<div id="{_elId}" class="{_selectorCls} {_colorCls} ext-cal-evt ext-cal-evr">',
\r
240 '<tpl if="_renderAsAllDay">',
\r
247 this.eventTpl = tpl;
\r
249 return this.eventTpl;
\r
253 getTemplateEventData: function(evt) {
\r
254 var M = Ext.calendar.EventMappings,
\r
255 selector = this.getEventSelectorCls(evt[M.EventId.name]),
\r
256 title = evt[M.Title.name];
\r
258 return Ext.applyIf({
\r
259 _selectorCls: selector,
\r
260 _colorCls: 'ext-color-' + (evt[M.CalendarId.name] ?
\r
261 evt[M.CalendarId.name] : 'default') + (evt._renderAsAllDay ? '-ad': ''),
\r
262 _elId: selector + '-' + evt._weekIndex,
\r
263 _isRecurring: evt.Recurrence && evt.Recurrence != '',
\r
264 _isReminder: evt[M.Reminder.name] && evt[M.Reminder.name] != '',
\r
265 Title: (evt[M.IsAllDay.name] ? '': evt[M.StartDate.name].format('g:ia ')) + (!title || title.length == 0 ? '(No title)': title)
\r
271 refresh: function() {
\r
272 if (this.detailPanel) {
\r
273 this.detailPanel.hide();
\r
275 Ext.calendar.MonthView.superclass.refresh.call(this);
\r
277 if (this.showTime !== false) {
\r
283 renderItems: function() {
\r
284 Ext.calendar.WeekEventRenderer.render({
\r
285 eventGrid: this.allDayOnly ? this.allDayGrid: this.eventGrid,
\r
286 viewStart: this.viewStart,
\r
287 tpl: this.getEventTemplate(),
\r
288 maxEventsPerDay: this.maxEventsPerDay,
\r
290 templateDataFn: this.getTemplateEventData.createDelegate(this),
\r
291 evtMaxCount: this.evtMaxCount,
\r
292 weekCount: this.weekCount,
\r
293 dayCount: this.dayCount
\r
295 this.fireEvent('eventsrendered', this);
\r
299 getDayEl: function(dt) {
\r
300 return Ext.get(this.getDayId(dt));
\r
304 getDayId: function(dt) {
\r
305 if (Ext.isDate(dt)) {
\r
306 dt = dt.format('Ymd');
\r
308 return this.id + this.dayElIdDelimiter + dt;
\r
312 getWeekIndex: function(dt) {
\r
313 var el = this.getDayEl(dt).up('.ext-cal-wk-ct');
\r
314 return parseInt(el.id.split('-wk-')[1], 10);
\r
318 getDaySize: function(contentOnly) {
\r
319 var box = this.el.getBox(),
\r
320 w = box.width / this.dayCount,
\r
321 h = box.height / this.getWeekCount();
\r
324 var hd = this.el.select('.ext-cal-dtitle').first().parent('tr');
\r
325 h = hd ? h - hd.getHeight(true) : h;
\r
334 getEventHeight: function() {
\r
335 if (!this.eventHeight) {
\r
336 var evt = this.el.select('.ext-cal-evt').first();
\r
337 this.eventHeight = evt ? evt.parent('tr').getHeight() : 18;
\r
339 return this.eventHeight;
\r
343 getMaxEventsPerDay: function() {
\r
344 var dayHeight = this.getDaySize(true).height,
\r
345 h = this.getEventHeight(),
\r
346 max = Math.max(Math.floor((dayHeight - h) / h), 0);
\r
352 getDayAt: function(x, y) {
\r
353 var box = this.el.getBox(),
\r
354 daySize = this.getDaySize(),
\r
355 dayL = Math.floor(((x - box.x) / daySize.width)),
\r
356 dayT = Math.floor(((y - box.y) / daySize.height)),
\r
357 days = (dayT * 7) + dayL,
\r
358 dt = this.viewStart.add(Date.DAY, days);
\r
361 el: this.getDayEl(dt)
\r
366 moveNext: function() {
\r
367 return this.moveMonths(1);
\r
371 movePrev: function() {
\r
372 return this.moveMonths( - 1);
\r
376 onInitDrag: function() {
\r
377 Ext.calendar.MonthView.superclass.onInitDrag.call(this);
\r
378 Ext.select(this.daySelector).removeClass(this.dayOverClass);
\r
379 if (this.detailPanel) {
\r
380 this.detailPanel.hide();
\r
385 onMoreClick: function(dt) {
\r
386 if (!this.detailPanel) {
\r
387 this.detailPanel = new Ext.Panel({
\r
388 id: this.id + '-details-panel',
\r
389 title: dt.format('F j'),
\r
392 renderTo: Ext.getBody(),
\r
395 handler: function(e, t, p) {
\r
400 xtype: 'monthdaydetailview',
\r
401 id: this.id + '-details-view',
\r
406 'eventsrendered': this.onDetailViewUpdated.createDelegate(this)
\r
412 this.detailPanel.setTitle(dt.format('F j'));
\r
414 this.detailPanel.getComponent(this.id + '-details-view').update(dt);
\r
418 onDetailViewUpdated: function(view, dt, numEvents) {
\r
419 var p = this.detailPanel,
\r
420 frameH = p.getFrameHeight(),
\r
421 evtH = this.getEventHeight(),
\r
422 bodyH = frameH + (numEvents * evtH) + 3,
\r
423 dayEl = this.getDayEl(dt),
\r
424 box = dayEl.getBox();
\r
427 p.setHeight(bodyH);
\r
428 p.setWidth(Math.max(box.width, 220));
\r
430 p.getPositionEl().alignTo(dayEl, 't-t?');
\r
434 onHide: function() {
\r
435 Ext.calendar.MonthView.superclass.onHide.call(this);
\r
436 if (this.detailPanel) {
\r
437 this.detailPanel.hide();
\r
442 onClick: function(e, t) {
\r
443 if (this.detailPanel) {
\r
444 this.detailPanel.hide();
\r
446 if (Ext.calendar.MonthView.superclass.onClick.apply(this, arguments)) {
\r
447 // The superclass handled the click already so exit
\r
450 if (this.dropZone) {
\r
451 this.dropZone.clearShims();
\r
453 var el = e.getTarget(this.weekLinkSelector, 3),
\r
457 dt = el.id.split(this.weekLinkIdDelimiter)[1];
\r
458 this.fireEvent('weekclick', this, Date.parseDate(dt, 'Ymd'));
\r
461 el = e.getTarget(this.moreSelector, 3);
\r
463 dt = el.id.split(this.moreElIdDelimiter)[1];
\r
464 this.onMoreClick(Date.parseDate(dt, 'Ymd'));
\r
467 el = e.getTarget('td', 3);
\r
469 if (el.id && el.id.indexOf(this.dayElIdDelimiter) > -1) {
\r
470 parts = el.id.split(this.dayElIdDelimiter);
\r
471 dt = parts[parts.length - 1];
\r
473 this.fireEvent('dayclick', this, Date.parseDate(dt, 'Ymd'), false, Ext.get(this.getDayId(dt)));
\r
480 handleDayMouseEvent: function(e, t, type) {
\r
481 var el = e.getTarget(this.weekLinkSelector, 3, true);
\r
483 el[type == 'over' ? 'addClass': 'removeClass'](this.weekLinkOverClass);
\r
486 Ext.calendar.MonthView.superclass.handleDayMouseEvent.apply(this, arguments);
\r
490 Ext.reg('monthview', Ext.calendar.MonthView);
\r