| 1 |
define([ |
| 2 |
"dojo/_base/declare", |
| 3 |
"dojo/dom-class", |
| 4 |
"./_TimePickerMixin", |
| 5 |
"./ToolBarButton", |
| 6 |
"./ValuePicker", |
| 7 |
"./ValuePickerSlot" |
| 8 |
], function(declare, domClass, TimePickerMixin, ToolBarButton, ValuePicker, ValuePickerSlot){ |
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
return declare("dojox.mobile.ValuePickerTimePicker", [ValuePicker, TimePickerMixin], { |
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
readOnly: false, |
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
is24h: false, |
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
hourPlusBtnLabel: "", |
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
hourPlusBtnLabelRef: "", |
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
minutePlusBtnLabel: "", |
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
minutePlusBtnLabelRef: "", |
| 59 |
|
| 60 |
|
| 61 |
|
| 62 |
hourMinusBtnLabel: "", |
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
hourMinusBtnLabelRef: "", |
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
minuteMinusBtnLabel: "", |
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
minuteMinusBtnLabelRef: "", |
| 75 |
|
| 76 |
slotClasses: [ |
| 77 |
ValuePickerSlot, |
| 78 |
ValuePickerSlot |
| 79 |
], |
| 80 |
|
| 81 |
slotProps: [ |
| 82 |
{labelFrom:0, labelTo:23, style:{width:"72px"}}, |
| 83 |
{labelFrom:0, labelTo:59, zeroPad:2, style:{width:"72px"}} |
| 84 |
], |
| 85 |
|
| 86 |
buildRendering: function(){ |
| 87 |
var p = this.slotProps; |
| 88 |
p[0].readOnly = p[1].readOnly = this.readOnly; |
| 89 |
this._setBtnLabels(p); |
| 90 |
this.inherited(arguments); |
| 91 |
var items = this.slots[0].items; |
| 92 |
this._zero = items.slice(0, 1); |
| 93 |
this._pm = items.slice(13); |
| 94 |
|
| 95 |
domClass.add(this.domNode, "mblValuePickerTimePicker"); |
| 96 |
domClass.add(this.slots[0].domNode, "mblValuePickerTimePickerHourSlot"); |
| 97 |
domClass.add(this.slots[1].domNode, "mblValuePickerTimePickerMinuteSlot"); |
| 98 |
|
| 99 |
this.ampmButton = new ToolBarButton(); |
| 100 |
this.addChild(this.ampmButton); |
| 101 |
this._conn = [ |
| 102 |
this.connect(this.ampmButton, "onClick", "onBtnClick") |
| 103 |
]; |
| 104 |
this.set("is24h", this.is24h); |
| 105 |
}, |
| 106 |
|
| 107 |
to12h: function(a){ |
| 108 |
|
| 109 |
|
| 110 |
|
| 111 |
|
| 112 |
|
| 113 |
|
| 114 |
|
| 115 |
|
| 116 |
var h = a[0] - 0; |
| 117 |
var ampm = h < 12 ? "AM" : "PM"; |
| 118 |
if(h == 0){ |
| 119 |
h = 12; |
| 120 |
}else if(h > 12){ |
| 121 |
h = h - 12; |
| 122 |
} |
| 123 |
return [h + "", a[1], ampm]; |
| 124 |
}, |
| 125 |
|
| 126 |
to24h: function(a){ |
| 127 |
|
| 128 |
|
| 129 |
|
| 130 |
|
| 131 |
|
| 132 |
|
| 133 |
|
| 134 |
|
| 135 |
var h = a[0] - 0; |
| 136 |
if(a[2] == "AM"){ |
| 137 |
h = h == 12 ? 0 : h; |
| 138 |
}else{ |
| 139 |
h = h == 12 ? h : h + 12; |
| 140 |
} |
| 141 |
return [h + "", a[1]]; |
| 142 |
}, |
| 143 |
|
| 144 |
onBtnClick: function(){ |
| 145 |
|
| 146 |
|
| 147 |
var ampm = this.ampmButton.get("label") == "AM" ? "PM" : "AM"; |
| 148 |
var v = this.get("values12"); |
| 149 |
v[2] = ampm; |
| 150 |
this.set("values12", v); |
| 151 |
if(this.onValueChanged){ |
| 152 |
this.onValueChanged(this.slots[0]); |
| 153 |
} |
| 154 |
}, |
| 155 |
|
| 156 |
_setIs24hAttr: function(is24h){ |
| 157 |
|
| 158 |
|
| 159 |
var items = this.slots[0].items; |
| 160 |
if(is24h && items.length != 24){ |
| 161 |
this.slots[0].items = this._zero.concat(items).concat(this._pm); |
| 162 |
}else if(!is24h && items.length != 12){ |
| 163 |
items.splice(0, 1); |
| 164 |
items.splice(12); |
| 165 |
} |
| 166 |
var v = this.get("values"); |
| 167 |
this._set("is24h", is24h); |
| 168 |
this.ampmButton.domNode.style.display = is24h ? "none" : ""; |
| 169 |
this.set("values", v); |
| 170 |
}, |
| 171 |
|
| 172 |
_getValuesAttr: function(){ |
| 173 |
|
| 174 |
|
| 175 |
var v = this.inherited(arguments); |
| 176 |
return this.is24h ? v : this.to24h([v[0], v[1], this.ampmButton.get("label")]); |
| 177 |
}, |
| 178 |
|
| 179 |
_setValuesAttr: function(values){ |
| 180 |
|
| 181 |
|
| 182 |
|
| 183 |
|
| 184 |
if(this.is24h){ |
| 185 |
this.inherited(arguments); |
| 186 |
}else{ |
| 187 |
values = this.to12h(values); |
| 188 |
this.ampmButton.set("label", values[2]); |
| 189 |
this.inherited(arguments); |
| 190 |
} |
| 191 |
}, |
| 192 |
|
| 193 |
_getValues12Attr: function(){ |
| 194 |
|
| 195 |
|
| 196 |
return this.to12h(this._getValuesAttr()); |
| 197 |
}, |
| 198 |
|
| 199 |
_setValues12Attr: function(values){ |
| 200 |
|
| 201 |
|
| 202 |
|
| 203 |
|
| 204 |
this.set("values", this.to24h(values)); |
| 205 |
}, |
| 206 |
|
| 207 |
_setBtnLabels: function(slotProps){ |
| 208 |
slotProps[0].plusBtnLabel = this.hourPlusBtnLabel; |
| 209 |
slotProps[0].plusBtnLabelRef = this.hourPlusBtnLabelRef; |
| 210 |
slotProps[0].minusBtnLabel = this.hourMinusBtnLabel; |
| 211 |
slotProps[0].minusBtnLabelRef = this.hourMinusBtnLabelRef; |
| 212 |
slotProps[1].plusBtnLabel = this.minutePlusBtnLabel; |
| 213 |
slotProps[1].plusBtnLabelRef = this.minutePlusBtnLabelRef; |
| 214 |
slotProps[1].minusBtnLabel = this.minuteMinusBtnLabel; |
| 215 |
slotProps[1].minusBtnLabelRef = this.minuteMinusBtnLabelRef; |
| 216 |
} |
| 217 |
}); |
| 218 |
}); |