1 | define([ |
---|
2 | "dojo/_base/declare", |
---|
3 | "dojo/dom-class", |
---|
4 | "dojo/date", |
---|
5 | "dojo/date/locale", |
---|
6 | "./SpinWheel", |
---|
7 | "./SpinWheelSlot" |
---|
8 | ], function(declare, domClass, ddate, datelocale, SpinWheel, SpinWheelSlot){ |
---|
9 | |
---|
10 | /*===== |
---|
11 | var SpinWheel = dojox.mobile.SpinWheel; |
---|
12 | var SpinWheelSlot = dojox.mobile.SpinWheelSlot; |
---|
13 | =====*/ |
---|
14 | |
---|
15 | // module: |
---|
16 | // dojox/mobile/SpinWheelDatePicker |
---|
17 | // summary: |
---|
18 | // A SpinWheel-based date picker widget. |
---|
19 | |
---|
20 | //TODO: the api doc parser seems to fail if the 1st arg for declare (=class name) is missing.. |
---|
21 | var SpinWheelYearSlot = declare(/*===== "dojox.mobile.SpinWheelYearSlot", =====*/ SpinWheelSlot, { |
---|
22 | buildRendering: function(){ |
---|
23 | this.labels = []; |
---|
24 | if(this.labelFrom !== this.labelTo){ |
---|
25 | var dtA = new Date(this.labelFrom, 0, 1); |
---|
26 | var i, idx; |
---|
27 | for(i = this.labelFrom, idx = 0; i <= this.labelTo; i++, idx++){ |
---|
28 | dtA.setFullYear(i); |
---|
29 | this.labels.push(datelocale.format(dtA, {datePattern:"yyyy", selector:"date"})); |
---|
30 | } |
---|
31 | } |
---|
32 | this.inherited(arguments); |
---|
33 | } |
---|
34 | }); |
---|
35 | |
---|
36 | var SpinWheelMonthSlot = declare(/*===== "dojox.mobile.SpinWheelMonthSlot", =====*/ SpinWheelSlot, { |
---|
37 | buildRendering: function(){ |
---|
38 | this.labels = []; |
---|
39 | var dtA = new Date(2000, 0, 1); |
---|
40 | var monthStr; |
---|
41 | for(var i = 0; i < 12; i++){ |
---|
42 | dtA.setMonth(i); |
---|
43 | monthStr = datelocale.format(dtA, {datePattern:"MMM", selector:"date"}); |
---|
44 | this.labels.push(monthStr); |
---|
45 | } |
---|
46 | this.inherited(arguments); |
---|
47 | } |
---|
48 | }); |
---|
49 | |
---|
50 | var SpinWheelDaySlot = declare(/*===== "dojox.mobile.SpinWheelDaySlot", =====*/ SpinWheelSlot, { |
---|
51 | }); |
---|
52 | |
---|
53 | return declare("dojox.mobile.SpinWheelDatePicker", SpinWheel, { |
---|
54 | // summary: |
---|
55 | // A SpinWheel-based date picker widget. |
---|
56 | // description: |
---|
57 | // SpinWheelDatePicker is a date picker widget. It is a subclass of |
---|
58 | // dojox.mobile.SpinWheel. It has the year, month, and day slots. |
---|
59 | |
---|
60 | slotClasses: [ |
---|
61 | SpinWheelYearSlot, |
---|
62 | SpinWheelMonthSlot, |
---|
63 | SpinWheelDaySlot |
---|
64 | ], |
---|
65 | slotProps: [ |
---|
66 | {labelFrom:1970, labelTo:2038}, |
---|
67 | {}, |
---|
68 | {labelFrom:1, labelTo:31} |
---|
69 | ], |
---|
70 | |
---|
71 | buildRendering: function(){ |
---|
72 | this.inherited(arguments); |
---|
73 | domClass.add(this.domNode, "mblSpinWheelDatePicker"); |
---|
74 | this.connect(this.slots[1], "onFlickAnimationEnd", "onMonthSet"); |
---|
75 | this.connect(this.slots[2], "onFlickAnimationEnd", "onDaySet"); |
---|
76 | }, |
---|
77 | |
---|
78 | reset: function(){ |
---|
79 | // summary: |
---|
80 | // Goes to today. |
---|
81 | var slots = this.slots; |
---|
82 | var now = new Date(); |
---|
83 | var monthStr = datelocale.format(now, {datePattern:"MMM", selector:"date"}); |
---|
84 | this.setValue([now.getFullYear(), monthStr, now.getDate()]); |
---|
85 | }, |
---|
86 | |
---|
87 | onMonthSet: function(){ |
---|
88 | // summary: |
---|
89 | // A handler called when the month value is changed. |
---|
90 | var daysInMonth = this.onDaySet(); |
---|
91 | var disableValuesTable = {28:[29,30,31], 29:[30,31], 30:[31], 31:[]}; |
---|
92 | this.slots[2].disableValues(disableValuesTable[daysInMonth]); |
---|
93 | }, |
---|
94 | |
---|
95 | onDaySet: function(){ |
---|
96 | // summary: |
---|
97 | // A handler called when the day value is changed. |
---|
98 | var y = this.slots[0].getValue(); |
---|
99 | var m = this.slots[1].getValue(); |
---|
100 | var newMonth = datelocale.parse(y+"/"+m, {datePattern:'yyyy/MMM', selector:'date'}); |
---|
101 | var daysInMonth = ddate.getDaysInMonth(newMonth); |
---|
102 | var d = this.slots[2].getValue(); |
---|
103 | if(daysInMonth < d){ |
---|
104 | this.slots[2].setValue(daysInMonth); |
---|
105 | } |
---|
106 | return daysInMonth; |
---|
107 | } |
---|
108 | }); |
---|
109 | }); |
---|