]>
git.wh0rd.org - tt-rss.git/blob - lib/dijit/form/_DateTimeTextBox.js.uncompressed.js
2 'url:dijit/form/templates/DropDownBox.html':"<div class=\"dijit dijitReset dijitInline dijitLeft\"\n\tid=\"widget_${id}\"\n\trole=\"combobox\"\n\t><div class='dijitReset dijitRight dijitButtonNode dijitArrowButton dijitDownArrowButton dijitArrowButtonContainer'\n\t\tdata-dojo-attach-point=\"_buttonNode, _popupStateNode\" role=\"presentation\"\n\t\t><input class=\"dijitReset dijitInputField dijitArrowButtonInner\" value=\"▼ \" type=\"text\" tabIndex=\"-1\" readonly=\"readonly\" role=\"presentation\"\n\t\t\t${_buttonInputDisabled}\n\t/></div\n\t><div class='dijitReset dijitValidationContainer'\n\t\t><input class=\"dijitReset dijitInputField dijitValidationIcon dijitValidationInner\" value=\"Χ \" type=\"text\" tabIndex=\"-1\" readonly=\"readonly\" role=\"presentation\"\n\t/></div\n\t><div class=\"dijitReset dijitInputField dijitInputContainer\"\n\t\t><input class='dijitReset dijitInputInner' ${!nameAttrSetting} type=\"text\" autocomplete=\"off\"\n\t\t\tdata-dojo-attach-point=\"textbox,focusNode\" role=\"textbox\" aria-haspopup=\"true\"\n\t/></div\n></div>\n"}});
3 define("dijit/form/_DateTimeTextBox", [
4 "dojo/date", // date date.compare
5 "dojo/date/locale", // locale.regexp
6 "dojo/date/stamp", // stamp.fromISOString stamp.toISOString
7 "dojo/_base/declare", // declare
8 "dojo/_base/lang", // lang.getObject
11 "dojo/text!./templates/DropDownBox.html"
12 ], function(date
, locale
, stamp
, declare
, lang
, RangeBoundTextBox
, _HasDropDown
, template
){
15 var _HasDropDown = dijit._HasDropDown;
16 var RangeBoundTextBox = dijit.form.RangeBoundTextBox;
20 // dijit/form/_DateTimeTextBox
22 // Base class for validating, serializable, range-bound date or time text box.
25 new Date("X"); // workaround for #11279, new Date("") == NaN
29 "dijit.form._DateTimeTextBox.__Constraints",
30 [RangeBoundTextBox.__Constraints, locale.__FormatOptions], {
32 // Specifies both the rules on valid/invalid values (first/last date/time allowed),
33 // and also formatting options for how the date/time is displayed.
35 // To restrict to dates within 2004, displayed in a long format like "December 25, 2005":
36 // | {min:'2004-01-01',max:'2004-12-31', formatLength:'long'}
40 var _DateTimeTextBox
= declare("dijit.form._DateTimeTextBox", [RangeBoundTextBox
, _HasDropDown
], {
42 // Base class for validating, serializable, range-bound date or time text box.
44 templateString
: template
,
46 // hasDownArrow: [const] Boolean
47 // Set this textbox to display a down arrow button, to open the drop down list.
50 // openOnClick: [const] Boolean
51 // Set to true to open drop down upon clicking anywhere on the textbox.
55 // constraints: dijit.form._DateTimeTextBox.__Constraints
56 // Despite the name, this parameter specifies both constraints on the input
57 // (including starting/ending dates/times allowed) as well as
58 // formatting options like whether the date is displayed in long (ex: December 25, 2005)
59 // or short (ex: 12/25/2005) format. See `dijit.form._DateTimeTextBox.__Constraints` for details.
63 // Override ValidationTextBox.regExpGen().... we use a reg-ex generating function rather
64 // than a straight regexp to deal with locale (plus formatting options too?)
65 regExpGen
: locale
.regexp
,
67 // datePackage: String
68 // JavaScript namespace to find calendar routines. Uses Gregorian calendar routines
69 // at dojo.date, by default.
72 postMixInProperties: function(){
73 this.inherited(arguments
);
74 this._set("type", "text"); // in case type="date"|"time" was specified which messes up parse/format
77 // Override _FormWidget.compare() to work for dates/times
78 compare: function(/*Date*/ val1
, /*Date*/ val2
){
79 var isInvalid1
= this._isInvalidDate(val1
);
80 var isInvalid2
= this._isInvalidDate(val2
);
81 return isInvalid1
? (isInvalid2
? 0 : -1) : (isInvalid2
? 1 : date
.compare(val1
, val2
, this._selector
));
84 // flag to _HasDropDown to make drop down Calendar width == <input> width
87 format: function(/*Date*/ value
, /*dojo.date.locale.__FormatOptions*/ constraints
){
89 // Formats the value as a Date, according to specified locale (second argument)
92 if(!value
){ return ''; }
93 return this.dateLocaleModule
.format(value
, constraints
);
96 "parse": function(/*String*/ value
, /*dojo.date.locale.__FormatOptions*/ constraints
){
98 // Parses as string as a Date, according to constraints
102 return this.dateLocaleModule
.parse(value
, constraints
) || (this._isEmpty(value
) ? null : undefined); // Date
105 // Overrides ValidationTextBox.serialize() to serialize a date in canonical ISO format.
106 serialize: function(/*anything*/ val
, /*Object?*/ options
){
108 val
= val
.toGregorian();
110 return stamp
.toISOString(val
, options
);
113 // dropDownDefaultValue: Date
114 // The default value to focus in the popupClass widget when the textbox value is empty.
115 dropDownDefaultValue
: new Date(),
118 // The value of this widget as a JavaScript Date object. Use get("value") / set("value", val) to manipulate.
119 // When passed to the parser in markup, must be specified according to `dojo.date.stamp.fromISOString`
120 value
: new Date(""), // value.toString()="NaN"
122 _blankValue
: null, // used by filter() when the textbox is blank
124 // popupClass: [protected extension] String
125 // Name of the popup widget class used to select a date/time.
126 // Subclasses should specify this.
127 popupClass
: "", // default is no popup = text only
130 // _selector: [protected extension] String
131 // Specifies constraints.selector passed to dojo.date functions, should be either
133 // Subclass must specify this.
136 constructor: function(/*Object*/ args
){
137 this.datePackage
= args
.datePackage
|| this.datePackage
;
138 this.dateFuncObj
= typeof this.datePackage
== "string" ?
139 lang
.getObject(this.datePackage
, false) :// "string" part for back-compat, remove for 2.0
141 this.dateClassObj
= this.dateFuncObj
.Date
|| Date
;
142 this.dateLocaleModule
= lang
.getObject("locale", false, this.dateFuncObj
);
143 this.regExpGen
= this.dateLocaleModule
.regexp
;
144 this._invalidDate
= this.constructor.prototype.value
.toString();
147 buildRendering: function(){
148 this.inherited(arguments
);
150 if(!this.hasDownArrow
){
151 this._buttonNode
.style
.display
= "none";
154 // If openOnClick is true, we basically just want to treat the whole widget as the
155 // button. We need to do that also if the actual drop down button will be hidden,
156 // so that there's a mouse method for opening the drop down.
157 if(this.openOnClick
|| !this.hasDownArrow
){
158 this._buttonNode
= this.domNode
;
159 this.baseClass
+= " dijitComboBoxOpenOnClick";
163 _setConstraintsAttr: function(/*Object*/ constraints
){
164 constraints
.selector
= this._selector
;
165 constraints
.fullYear
= true; // see #5465 - always format with 4-digit years
166 var fromISO
= stamp
.fromISOString
;
167 if(typeof constraints
.min
== "string"){ constraints
.min
= fromISO(constraints
.min
); }
168 if(typeof constraints
.max
== "string"){ constraints
.max
= fromISO(constraints
.max
); }
169 this.inherited(arguments
);
172 _isInvalidDate: function(/*Date*/ value
){
174 // Runs various tests on the value, checking for invalid conditions
177 return !value
|| isNaN(value
) || typeof value
!= "object" || value
.toString() == this._invalidDate
;
180 _setValueAttr: function(/*Date|String*/ value
, /*Boolean?*/ priorityChange
, /*String?*/ formattedValue
){
182 // Sets the date on this textbox. Note: value can be a JavaScript Date literal or a string to be parsed.
183 if(value
!== undefined){
184 if(typeof value
== "string"){
185 value
= stamp
.fromISOString(value
);
187 if(this._isInvalidDate(value
)){
190 if(value
instanceof Date
&& !(this.dateClassObj
instanceof Date
)){
191 value
= new this.dateClassObj(value
);
194 this.inherited(arguments
);
195 if(this.value
instanceof Date
){
196 this.filterString
= "";
199 this.dropDown
.set('value', value
, false);
203 _set: function(attr
, value
){
204 // Avoid spurious watch() notifications when value is changed to new Date object w/the same value
205 if(attr
== "value" && this.value
instanceof Date
&& this.compare(value
, this.value
) == 0){
208 this.inherited(arguments
);
211 _setDropDownDefaultValueAttr: function(/*Date*/ val
){
212 if(this._isInvalidDate(val
)){
213 // convert null setting into today's date, since there needs to be *some* default at all times.
214 val
= new this.dateClassObj();
216 this.dropDownDefaultValue
= val
;
219 openDropDown: function(/*Function*/ callback
){
220 // rebuild drop down every time, so that constraints get copied (#6002)
222 this.dropDown
.destroy();
224 var PopupProto
= lang
.isString(this.popupClass
) ? lang
.getObject(this.popupClass
, false) : this.popupClass
,
226 value
= this.get("value");
227 this.dropDown
= new PopupProto({
228 onChange: function(value
){
229 // this will cause InlineEditBox and other handlers to do stuff so make sure it's last
230 textBox
.set('value', value
, true);
232 id
: this.id
+ "_popup",
236 currentFocus
: !this._isInvalidDate(value
) ? value
: this.dropDownDefaultValue
,
237 constraints
: textBox
.constraints
,
238 filterString
: textBox
.filterString
, // for TimeTextBox, to filter times shown
240 datePackage
: textBox
.datePackage
,
242 isDisabledDate: function(/*Date*/ date
){
244 // disables dates outside of the min/max of the _DateTimeTextBox
245 return !textBox
.rangeCheck(date
, textBox
.constraints
);
249 this.inherited(arguments
);
252 _getDisplayedValueAttr: function(){
253 return this.textbox
.value
;
256 _setDisplayedValueAttr: function(/*String*/ value
, /*Boolean?*/ priorityChange
){
257 this._setValueAttr(this.parse(value
, this.constraints
), priorityChange
, value
);
261 return _DateTimeTextBox
;