1 | dojo.provide("dojox.widget.CalendarViews"); |
---|
2 | dojo.experimental("dojox.widget.CalendarViews"); |
---|
3 | |
---|
4 | dojo.require("dojox.widget.Calendar"); |
---|
5 | |
---|
6 | dojo.declare("dojox.widget._CalendarMonth", null, { |
---|
7 | // summary: Mixin class for adding a view listing all 12 months of the year to the |
---|
8 | // dojox.widget._CalendarBase |
---|
9 | |
---|
10 | |
---|
11 | constructor: function(){ |
---|
12 | // summary: Adds a dojox.widget._CalendarMonthView view to the calendar widget. |
---|
13 | this._addView(dojox.widget._CalendarMonthView); |
---|
14 | } |
---|
15 | }); |
---|
16 | |
---|
17 | dojo.declare("dojox.widget._CalendarMonthView", [dojox.widget._CalendarView, dijit._Templated], { |
---|
18 | // summary: A Calendar view listing the 12 months of the year |
---|
19 | |
---|
20 | // templateString: String |
---|
21 | // The template to be used to construct the widget. |
---|
22 | templateString: dojo.cache("dojox.widget","Calendar/CalendarMonth.html"), |
---|
23 | |
---|
24 | // datePart: String |
---|
25 | // Specifies how much to increment the displayed date when the user |
---|
26 | // clicks the array button to increment of decrement the view. |
---|
27 | datePart: "year", |
---|
28 | |
---|
29 | // headerClass: String |
---|
30 | // Specifies the CSS class to apply to the header node for this view. |
---|
31 | headerClass: "dojoxCalendarMonthHeader", |
---|
32 | |
---|
33 | postCreate: function(){ |
---|
34 | // summary: Constructs the view |
---|
35 | this.cloneClass(".dojoxCalendarMonthTemplate", 3); |
---|
36 | this.cloneClass(".dojoxCalendarMonthGroupTemplate", 2); |
---|
37 | this._populateMonths(); |
---|
38 | |
---|
39 | // Add visual effects to the view, if any have been mixed in |
---|
40 | this.addFx(".dojoxCalendarMonthLabel", this.domNode); |
---|
41 | }, |
---|
42 | |
---|
43 | _setValueAttr: function(value){ |
---|
44 | this.header.innerHTML = value.getFullYear(); |
---|
45 | }, |
---|
46 | |
---|
47 | _getMonthNames: dojox.widget._CalendarMonthYearView.prototype._getMonthNames, |
---|
48 | |
---|
49 | _populateMonths: dojox.widget._CalendarMonthYearView.prototype._populateMonths, |
---|
50 | |
---|
51 | onClick: function(evt){ |
---|
52 | // summary: Handles clicks on month names |
---|
53 | if(!dojo.hasClass(evt.target, "dojoxCalendarMonthLabel")){dojo.stopEvent(evt); return;} |
---|
54 | var parentNode = evt.target.parentNode; |
---|
55 | var month = parentNode.cellIndex + (parentNode.parentNode.rowIndex * 4); |
---|
56 | var date = this.get("value"); |
---|
57 | |
---|
58 | // Seeing a really strange bug in FF3.6 where this has to be called twice |
---|
59 | // in order to take affect |
---|
60 | date.setMonth(month); |
---|
61 | date.setMonth(month); |
---|
62 | this.onValueSelected(date, month); |
---|
63 | } |
---|
64 | }); |
---|
65 | |
---|
66 | dojo.declare("dojox.widget._CalendarYear", null, { |
---|
67 | // summary: Mixin class for adding a view listing 12 years to the |
---|
68 | // dojox.widget._CalendarBase |
---|
69 | parent: null, |
---|
70 | |
---|
71 | constructor: function(){ |
---|
72 | // summary: Adds a dojox.widget._CalendarYearView view to the |
---|
73 | // dojo.widget._CalendarBase widget. |
---|
74 | this._addView(dojox.widget._CalendarYearView); |
---|
75 | } |
---|
76 | }); |
---|
77 | |
---|
78 | dojo.declare("dojox.widget._CalendarYearView", [dojox.widget._CalendarView, dijit._Templated], { |
---|
79 | // summary: A Calendar view listing 12 years |
---|
80 | |
---|
81 | // templateString: String |
---|
82 | // The template to be used to construct the widget. |
---|
83 | templateString: dojo.cache("dojox.widget","Calendar/CalendarYear.html"), |
---|
84 | |
---|
85 | displayedYears: 6, |
---|
86 | |
---|
87 | postCreate: function(){ |
---|
88 | // summary: Constructs the view |
---|
89 | this.cloneClass(".dojoxCalendarYearTemplate", 3); |
---|
90 | this.cloneClass(".dojoxCalendarYearGroupTemplate", 2); |
---|
91 | this._populateYears(); |
---|
92 | this.addFx(".dojoxCalendarYearLabel", this.domNode); |
---|
93 | }, |
---|
94 | |
---|
95 | _setValueAttr: function(value){ |
---|
96 | this._populateYears(value.getFullYear()); |
---|
97 | }, |
---|
98 | |
---|
99 | _populateYears: dojox.widget._CalendarMonthYearView.prototype._populateYears, |
---|
100 | |
---|
101 | adjustDate: function(date, amount){ |
---|
102 | // summary: Adjusts the value of a date. It moves it by 12 years each time. |
---|
103 | return dojo.date.add(date, "year", amount * 12); |
---|
104 | }, |
---|
105 | |
---|
106 | onClick: function(evt){ |
---|
107 | // summary: Handles clicks on year values. |
---|
108 | if(!dojo.hasClass(evt.target, "dojoxCalendarYearLabel")){dojo.stopEvent(evt); return;} |
---|
109 | var year = Number(evt.target.innerHTML); |
---|
110 | var date = this.get("value"); |
---|
111 | date.setYear(year); |
---|
112 | this.onValueSelected(date, year); |
---|
113 | } |
---|
114 | }); |
---|
115 | |
---|
116 | |
---|
117 | dojo.declare("dojox.widget.Calendar3Pane", |
---|
118 | [dojox.widget._CalendarBase, |
---|
119 | dojox.widget._CalendarDay, |
---|
120 | dojox.widget._CalendarMonth, |
---|
121 | dojox.widget._CalendarYear], { |
---|
122 | // summary: The Calendar includes day, month and year views. |
---|
123 | // No visual effects are included. |
---|
124 | } |
---|
125 | ); |
---|
126 | |
---|
127 | dojo.declare("dojox.widget.MonthlyCalendar", |
---|
128 | [dojox.widget._CalendarBase, |
---|
129 | dojox.widget._CalendarMonth], { |
---|
130 | // summary: A calendar with only a month view. |
---|
131 | _makeDate: function(value){ |
---|
132 | var now = new Date(); |
---|
133 | now.setMonth(value); |
---|
134 | return now; |
---|
135 | } |
---|
136 | } |
---|
137 | ); |
---|
138 | dojo.declare("dojox.widget.YearlyCalendar", |
---|
139 | [dojox.widget._CalendarBase, |
---|
140 | dojox.widget._CalendarYear], { |
---|
141 | // summary: A calendar with only a year view. |
---|
142 | _makeDate: function(value){ |
---|
143 | var now = new Date(); |
---|
144 | now.setFullYear(value); |
---|
145 | return now; |
---|
146 | } |
---|
147 | } |
---|
148 | ); |
---|