| 1 |
define([ |
| 2 |
"dojo/date", |
| 3 |
"dojo/date/locale", |
| 4 |
"dojo/date/stamp", |
| 5 |
"dojo/_base/declare", |
| 6 |
"dojo/_base/lang", |
| 7 |
"./RangeBoundTextBox", |
| 8 |
"../_HasDropDown", |
| 9 |
"dojo/text!./templates/DropDownBox.html" |
| 10 |
], function(date, locale, stamp, declare, lang, RangeBoundTextBox, _HasDropDown, template){ |
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
new Date("X"); |
| 16 |
|
| 17 |
var _DateTimeTextBox = declare("dijit.form._DateTimeTextBox", [RangeBoundTextBox, _HasDropDown], { |
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
templateString: template, |
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
hasDownArrow: true, |
| 26 |
|
| 27 |
|
| 28 |
cssStateNodes: { |
| 29 |
"_buttonNode": "dijitDownArrowButton" |
| 30 |
}, |
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
_unboundedConstraints: {}, |
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
pattern: locale.regexp, |
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
datePackage: "", |
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
postMixInProperties: function(){ |
| 57 |
this.inherited(arguments); |
| 58 |
this._set("type", "text"); |
| 59 |
}, |
| 60 |
|
| 61 |
|
| 62 |
compare: function( val1, val2){ |
| 63 |
var isInvalid1 = this._isInvalidDate(val1); |
| 64 |
var isInvalid2 = this._isInvalidDate(val2); |
| 65 |
if (isInvalid1 || isInvalid2){ |
| 66 |
return (isInvalid1 && isInvalid2) ? 0 : (!isInvalid1 ? 1 : -1); |
| 67 |
} |
| 68 |
|
| 69 |
|
| 70 |
var fval1 = this.format(val1, this._unboundedConstraints), |
| 71 |
fval2 = this.format(val2, this._unboundedConstraints), |
| 72 |
pval1 = this.parse(fval1, this._unboundedConstraints), |
| 73 |
pval2 = this.parse(fval2, this._unboundedConstraints); |
| 74 |
|
| 75 |
return fval1 == fval2 ? 0 : date.compare(pval1, pval2, this._selector); |
| 76 |
}, |
| 77 |
|
| 78 |
|
| 79 |
autoWidth: true, |
| 80 |
|
| 81 |
format: function( value, constraints){ |
| 82 |
|
| 83 |
|
| 84 |
|
| 85 |
|
| 86 |
if(!value){ return ''; } |
| 87 |
return this.dateLocaleModule.format(value, constraints); |
| 88 |
}, |
| 89 |
|
| 90 |
"parse": function( value, constraints){ |
| 91 |
|
| 92 |
|
| 93 |
|
| 94 |
|
| 95 |
|
| 96 |
return this.dateLocaleModule.parse(value, constraints) || (this._isEmpty(value) ? null : undefined); |
| 97 |
}, |
| 98 |
|
| 99 |
|
| 100 |
serialize: function( val, options){ |
| 101 |
if(val.toGregorian){ |
| 102 |
val = val.toGregorian(); |
| 103 |
} |
| 104 |
return stamp.toISOString(val, options); |
| 105 |
}, |
| 106 |
|
| 107 |
|
| 108 |
|
| 109 |
dropDownDefaultValue : new Date(), |
| 110 |
|
| 111 |
|
| 112 |
|
| 113 |
|
| 114 |
value: new Date(""), |
| 115 |
|
| 116 |
_blankValue: null, |
| 117 |
|
| 118 |
|
| 119 |
|
| 120 |
|
| 121 |
popupClass: "", |
| 122 |
|
| 123 |
|
| 124 |
|
| 125 |
|
| 126 |
|
| 127 |
|
| 128 |
_selector: "", |
| 129 |
|
| 130 |
constructor: function(params ){ |
| 131 |
|
| 132 |
|
| 133 |
|
| 134 |
|
| 135 |
|
| 136 |
|
| 137 |
|
| 138 |
|
| 139 |
|
| 140 |
params = params || {}; |
| 141 |
this.dateModule = params.datePackage ? lang.getObject(params.datePackage, false) : date; |
| 142 |
this.dateClassObj = this.dateModule.Date || Date; |
| 143 |
if(!(this.dateClassObj instanceof Date)){ |
| 144 |
this.value = new this.dateClassObj(this.value); |
| 145 |
} |
| 146 |
this.dateLocaleModule = params.datePackage ? lang.getObject(params.datePackage+".locale", false) : locale; |
| 147 |
this._set('pattern', this.dateLocaleModule.regexp); |
| 148 |
this._invalidDate = this.constructor.prototype.value.toString(); |
| 149 |
}, |
| 150 |
|
| 151 |
buildRendering: function(){ |
| 152 |
this.inherited(arguments); |
| 153 |
|
| 154 |
if(!this.hasDownArrow){ |
| 155 |
this._buttonNode.style.display = "none"; |
| 156 |
} |
| 157 |
|
| 158 |
|
| 159 |
|
| 160 |
if(!this.hasDownArrow){ |
| 161 |
this._buttonNode = this.domNode; |
| 162 |
this.baseClass += " dijitComboBoxOpenOnClick"; |
| 163 |
} |
| 164 |
}, |
| 165 |
|
| 166 |
_setConstraintsAttr: function( constraints){ |
| 167 |
constraints.selector = this._selector; |
| 168 |
constraints.fullYear = true; |
| 169 |
var fromISO = stamp.fromISOString; |
| 170 |
if(typeof constraints.min == "string"){ |
| 171 |
constraints.min = fromISO(constraints.min); |
| 172 |
if(!(this.dateClassObj instanceof Date)){ |
| 173 |
constraints.min = new this.dateClassObj(constraints.min); |
| 174 |
} |
| 175 |
} |
| 176 |
if(typeof constraints.max == "string"){ |
| 177 |
constraints.max = fromISO(constraints.max); |
| 178 |
if(!(this.dateClassObj instanceof Date)){ |
| 179 |
constraints.max = new this.dateClassObj(constraints.max); |
| 180 |
} |
| 181 |
} |
| 182 |
this.inherited(arguments); |
| 183 |
this._unboundedConstraints = lang.mixin({}, this.constraints, {min: null, max: null}); |
| 184 |
}, |
| 185 |
|
| 186 |
_isDefinitelyOutOfRange: function(){ |
| 187 |
var returnValue = this.inherited(arguments); |
| 188 |
var isOutOfRange = false; |
| 189 |
var inputDate; |
| 190 |
var inputYear; |
| 191 |
var inputYearMax; |
| 192 |
var inputYearMin; |
| 193 |
var maxDate; |
| 194 |
var minDate; |
| 195 |
|
| 196 |
if(returnValue && (this.constraints.min || this.constraints.max)){ |
| 197 |
var dateRegExp = new RegExp(this._lastRegExp); |
| 198 |
inputDate = dateRegExp.exec(this._lastInputEventValue); |
| 199 |
if (inputDate != null) { |
| 200 |
inputYear = inputDate[3]; |
| 201 |
|
| 202 |
if(this.constraints.min){ |
| 203 |
minDate = this.constraints.min instanceof Date ? |
| 204 |
this.constraints.min : new Date(String(this.constraints.min)); |
| 205 |
minYear = minDate.getFullYear(); |
| 206 |
inputYearMax = parseInt((inputYear + '9999').substr(0, 4), 10); |
| 207 |
isOutOfRange = inputYearMax < minYear; |
| 208 |
} |
| 209 |
|
| 210 |
if(!isOutOfRange && this.constraints.max){ |
| 211 |
maxDate = this.constraints.max instanceof Date ? |
| 212 |
this.constraints.max : new Date(String(this.constraints.max)); |
| 213 |
maxYear = maxDate.getFullYear(); |
| 214 |
inputYearMin = parseInt((inputYear + '0000').substr(0, 4), 10); |
| 215 |
isOutOfRange = inputYearMin > maxYear; |
| 216 |
} |
| 217 |
|
| 218 |
returnValue = isOutOfRange; |
| 219 |
} |
| 220 |
} |
| 221 |
|
| 222 |
return returnValue; |
| 223 |
}, |
| 224 |
|
| 225 |
_isInvalidDate: function( value){ |
| 226 |
|
| 227 |
|
| 228 |
|
| 229 |
|
| 230 |
return !value || isNaN(value) || typeof value != "object" || value.toString() == this._invalidDate; |
| 231 |
}, |
| 232 |
|
| 233 |
_setValueAttr: function( value, priorityChange, formattedValue){ |
| 234 |
|
| 235 |
|
| 236 |
if(value !== undefined){ |
| 237 |
if(typeof value == "string"){ |
| 238 |
value = stamp.fromISOString(value); |
| 239 |
} |
| 240 |
if(this._isInvalidDate(value)){ |
| 241 |
value = null; |
| 242 |
} |
| 243 |
if(value instanceof Date && !(this.dateClassObj instanceof Date)){ |
| 244 |
value = new this.dateClassObj(value); |
| 245 |
} |
| 246 |
} |
| 247 |
this.inherited(arguments, [value, priorityChange, formattedValue]); |
| 248 |
if(this.value instanceof Date){ |
| 249 |
this.filterString = ""; |
| 250 |
} |
| 251 |
|
| 252 |
|
| 253 |
|
| 254 |
if(priorityChange !== false && this.dropDown){ |
| 255 |
this.dropDown.set('value', value, false); |
| 256 |
} |
| 257 |
}, |
| 258 |
|
| 259 |
_set: function(attr, value){ |
| 260 |
|
| 261 |
if(attr == "value"){ |
| 262 |
if(value instanceof Date && !(this.dateClassObj instanceof Date)){ |
| 263 |
value = new this.dateClassObj(value); |
| 264 |
} |
| 265 |
var oldValue = this._get("value"); |
| 266 |
if(oldValue instanceof this.dateClassObj && this.compare(value, oldValue) == 0){ |
| 267 |
return; |
| 268 |
} |
| 269 |
} |
| 270 |
this.inherited(arguments); |
| 271 |
}, |
| 272 |
|
| 273 |
_setDropDownDefaultValueAttr: function( val){ |
| 274 |
if(this._isInvalidDate(val)){ |
| 275 |
|
| 276 |
val = new this.dateClassObj(); |
| 277 |
} |
| 278 |
this._set("dropDownDefaultValue", val); |
| 279 |
}, |
| 280 |
|
| 281 |
openDropDown: function( callback){ |
| 282 |
|
| 283 |
if(this.dropDown){ |
| 284 |
this.dropDown.destroy(); |
| 285 |
} |
| 286 |
var PopupProto = lang.isString(this.popupClass) ? lang.getObject(this.popupClass, false) : this.popupClass, |
| 287 |
textBox = this, |
| 288 |
value = this.get("value"); |
| 289 |
this.dropDown = new PopupProto({ |
| 290 |
onChange: function(value){ |
| 291 |
|
| 292 |
textBox.set('value', value, true); |
| 293 |
}, |
| 294 |
id: this.id + "_popup", |
| 295 |
dir: textBox.dir, |
| 296 |
lang: textBox.lang, |
| 297 |
value: value, |
| 298 |
textDir: textBox.textDir, |
| 299 |
currentFocus: !this._isInvalidDate(value) ? value : this.dropDownDefaultValue, |
| 300 |
constraints: textBox.constraints, |
| 301 |
filterString: textBox.filterString, |
| 302 |
datePackage: textBox.datePackage, |
| 303 |
isDisabledDate: function( date){ |
| 304 |
|
| 305 |
|
| 306 |
return !textBox.rangeCheck(date, textBox.constraints); |
| 307 |
} |
| 308 |
}); |
| 309 |
|
| 310 |
this.inherited(arguments); |
| 311 |
}, |
| 312 |
|
| 313 |
_getDisplayedValueAttr: function(){ |
| 314 |
return this.textbox.value; |
| 315 |
}, |
| 316 |
|
| 317 |
_setDisplayedValueAttr: function( value, priorityChange){ |
| 318 |
this._setValueAttr(this.parse(value, this.constraints), priorityChange, value); |
| 319 |
} |
| 320 |
}); |
| 321 |
|
| 322 |
|
| 323 |
|
| 324 |
|
| 325 |
|
| 326 |
|
| 327 |
|
| 328 |
|
| 329 |
|
| 330 |
|
| 331 |
|
| 332 |
|
| 333 |
|
| 334 |
return _DateTimeTextBox; |
| 335 |
}); |