| 1 |
define([ |
| 2 |
"dojo/_base/array", |
| 3 |
"dojo/_base/declare", |
| 4 |
"dojo/_base/lang", |
| 5 |
"dojo/date", |
| 6 |
"dojo/date/locale", |
| 7 |
"dojo/date/stamp" |
| 8 |
], function(array, declare, lang, ddate, datelocale, datestamp){ |
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
var slotMixin = { |
| 14 |
format: function(d){ |
| 15 |
return datelocale.format(d, {datePattern:this.pattern, selector:"date",locale: this.picker.lang}); |
| 16 |
} |
| 17 |
}; |
| 18 |
|
| 19 |
var yearSlotMixin = lang.mixin({ |
| 20 |
initLabels: function(){ |
| 21 |
this.labels = []; |
| 22 |
if(this.labelFrom !== this.labelTo){ |
| 23 |
var d = new Date(this.labelFrom, 0, 1); |
| 24 |
var i, idx; |
| 25 |
for(i = this.labelFrom, idx = 0; i <= this.labelTo; i++, idx++){ |
| 26 |
d.setFullYear(i); |
| 27 |
this.labels.push(this.format(d)); |
| 28 |
} |
| 29 |
} |
| 30 |
} |
| 31 |
}, slotMixin); |
| 32 |
|
| 33 |
var monthSlotMixin = lang.mixin({ |
| 34 |
initLabels: function(){ |
| 35 |
this.labels = []; |
| 36 |
|
| 37 |
var d = new Date(2000, 0, 16); |
| 38 |
for(var i = 0; i < 12; i++){ |
| 39 |
d.setMonth(i); |
| 40 |
this.labels.push(this.format(d)); |
| 41 |
} |
| 42 |
} |
| 43 |
}, slotMixin); |
| 44 |
|
| 45 |
var daySlotMixin = lang.mixin({ |
| 46 |
initLabels: function(){ |
| 47 |
this.labels = []; |
| 48 |
var d = new Date(2000, 0, 1); |
| 49 |
for(var i = 1; i <= 31; i++){ |
| 50 |
d.setDate(i); |
| 51 |
this.labels.push(this.format(d)); |
| 52 |
} |
| 53 |
} |
| 54 |
}, slotMixin); |
| 55 |
|
| 56 |
return declare("dojox.mobile._DatePickerMixin", null, { |
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
|
| 62 |
yearPattern: "yyyy", |
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
monthPattern: "MMM", |
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
dayPattern: "d", |
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
|
| 75 |
|
| 76 |
|
| 77 |
|
| 78 |
|
| 79 |
|
| 80 |
|
| 81 |
|
| 82 |
|
| 83 |
|
| 84 |
|
| 85 |
initSlots: function(){ |
| 86 |
|
| 87 |
|
| 88 |
var c = this.slotClasses, p = this.slotProps; |
| 89 |
c[0] = declare(c[0], yearSlotMixin); |
| 90 |
c[1] = declare(c[1], monthSlotMixin); |
| 91 |
c[2] = declare(c[2], daySlotMixin); |
| 92 |
p[2].picker = p[1].picker = p[0].picker = this; |
| 93 |
p[0].pattern = this.yearPattern; |
| 94 |
p[1].pattern = this.monthPattern; |
| 95 |
p[2].pattern = this.dayPattern; |
| 96 |
this.reorderSlots(); |
| 97 |
}, |
| 98 |
|
| 99 |
reorderSlots: function(){ |
| 100 |
|
| 101 |
|
| 102 |
if(this.slotOrder.length){ return; } |
| 103 |
var a = datelocale._parseInfo({locale: this.lang}).bundle["dateFormat-short"].toLowerCase().split(/[^ymd]+/, 3); |
| 104 |
this.slotOrder = array.map(a, function(pat){ |
| 105 |
return {y:0, m:1, d:2}[pat.charAt(0)]; |
| 106 |
}); |
| 107 |
}, |
| 108 |
|
| 109 |
reset: function(){ |
| 110 |
|
| 111 |
|
| 112 |
var now = new Date(); |
| 113 |
var v = array.map(this.slots, function(w){ return w.format(now); }); |
| 114 |
this.set("colors", v); |
| 115 |
this._disableEndDaysOfMonth(); |
| 116 |
if(this.value){ |
| 117 |
this.set("value", this.value); |
| 118 |
this.value = null; |
| 119 |
}else if(this.values){ |
| 120 |
this.set("values", this.values); |
| 121 |
this.values = null; |
| 122 |
}else{ |
| 123 |
this.set("values", v); |
| 124 |
} |
| 125 |
}, |
| 126 |
|
| 127 |
_onYearSet: function(){ |
| 128 |
|
| 129 |
|
| 130 |
|
| 131 |
|
| 132 |
var slot = this.slots[0]; |
| 133 |
var newValue = slot.get("value"); |
| 134 |
if(!(slot._previousValue && newValue == slot._previousValue)){ |
| 135 |
this._disableEndDaysOfMonth(); |
| 136 |
slot._previousValue = newValue; |
| 137 |
slot._set("value", newValue); |
| 138 |
this.onYearSet(); |
| 139 |
} |
| 140 |
}, |
| 141 |
|
| 142 |
onYearSet: function(){ |
| 143 |
|
| 144 |
|
| 145 |
}, |
| 146 |
|
| 147 |
_onMonthSet: function(){ |
| 148 |
|
| 149 |
|
| 150 |
|
| 151 |
|
| 152 |
var slot = this.slots[1]; |
| 153 |
var newValue = slot.get("value"); |
| 154 |
if(!(slot._previousValue && newValue == slot._previousValue)){ |
| 155 |
this._disableEndDaysOfMonth(); |
| 156 |
slot._previousValue = newValue; |
| 157 |
slot._set("value", newValue); |
| 158 |
this.onMonthSet(); |
| 159 |
} |
| 160 |
}, |
| 161 |
|
| 162 |
onMonthSet: function(){ |
| 163 |
|
| 164 |
|
| 165 |
}, |
| 166 |
|
| 167 |
_onDaySet: function(){ |
| 168 |
|
| 169 |
|
| 170 |
|
| 171 |
|
| 172 |
var slot = this.slots[2]; |
| 173 |
var newValue = slot.get("value"); |
| 174 |
if(!(slot._previousValue && newValue == slot._previousValue)){ |
| 175 |
if(!this._disableEndDaysOfMonth()){ |
| 176 |
|
| 177 |
|
| 178 |
|
| 179 |
|
| 180 |
slot._previousValue = newValue; |
| 181 |
slot._set("value", newValue); |
| 182 |
this.onDaySet(); |
| 183 |
} |
| 184 |
} |
| 185 |
}, |
| 186 |
|
| 187 |
onDaySet: function(){ |
| 188 |
|
| 189 |
|
| 190 |
}, |
| 191 |
|
| 192 |
_disableEndDaysOfMonth: function(){ |
| 193 |
|
| 194 |
|
| 195 |
|
| 196 |
|
| 197 |
|
| 198 |
var pat = this.slots[0].pattern + "/" + this.slots[1].pattern, |
| 199 |
v = this.get("values"), |
| 200 |
date = datelocale.parse(v[0] + "/" + v[1], {datePattern:pat, selector:"date",locale: this.lang}), |
| 201 |
daysInMonth = ddate.getDaysInMonth(date); |
| 202 |
var changedDay = false; |
| 203 |
if(daysInMonth < v[2]){ |
| 204 |
|
| 205 |
changedDay = true; |
| 206 |
this.slots[2]._spinToValue(daysInMonth, false); |
| 207 |
} |
| 208 |
this.disableValues(daysInMonth); |
| 209 |
return changedDay; |
| 210 |
}, |
| 211 |
|
| 212 |
_getDateAttr: function(){ |
| 213 |
|
| 214 |
|
| 215 |
|
| 216 |
|
| 217 |
var v = this.get("values"), |
| 218 |
s = this.slots, |
| 219 |
pat = s[0].pattern + "/" + s[1].pattern + "/" + s[2].pattern; |
| 220 |
return datelocale.parse(v[0] + "/" + v[1] + "/" + v[2], {datePattern:pat, selector:"date", locale: this.lang}); |
| 221 |
}, |
| 222 |
|
| 223 |
_setValuesAttr: function(values){ |
| 224 |
|
| 225 |
|
| 226 |
|
| 227 |
|
| 228 |
|
| 229 |
|
| 230 |
|
| 231 |
|
| 232 |
|
| 233 |
|
| 234 |
|
| 235 |
|
| 236 |
|
| 237 |
|
| 238 |
array.forEach(this.getSlots(), function(w, i){ |
| 239 |
var v = values[i]; |
| 240 |
if(typeof v == "number"){ |
| 241 |
var arr = [1970, 1, 1]; |
| 242 |
arr.splice(i, 1, v - 0); |
| 243 |
v = w.format(new Date(arr[0], arr[1] - 1, arr[2])); |
| 244 |
} |
| 245 |
w.set("value", v); |
| 246 |
}); |
| 247 |
}, |
| 248 |
|
| 249 |
_setValueAttr: function(value){ |
| 250 |
|
| 251 |
|
| 252 |
|
| 253 |
|
| 254 |
|
| 255 |
|
| 256 |
|
| 257 |
|
| 258 |
|
| 259 |
|
| 260 |
|
| 261 |
|
| 262 |
var date = datestamp.fromISOString(value); |
| 263 |
this.set("values", array.map(this.slots, function(w){ return w.format(date); })); |
| 264 |
}, |
| 265 |
|
| 266 |
_getValueAttr: function(){ |
| 267 |
|
| 268 |
|
| 269 |
|
| 270 |
|
| 271 |
|
| 272 |
|
| 273 |
return datestamp.toISOString(this.get("date"), { selector: "date" }); |
| 274 |
} |
| 275 |
}); |
| 276 |
}); |