]>
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=\"button presentation\" aria-hidden=\"true\"\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 // dijit/form/_DateTimeTextBox
17 new Date("X"); // workaround for #11279, new Date("") == NaN
19 var _DateTimeTextBox
= declare("dijit.form._DateTimeTextBox", [RangeBoundTextBox
, _HasDropDown
], {
21 // Base class for validating, serializable, range-bound date or time text box.
23 templateString
: template
,
25 // hasDownArrow: [const] Boolean
26 // Set this textbox to display a down arrow button, to open the drop down list.
29 // Set classes like dijitDownArrowButtonHover depending on mouse action over button node
31 "_buttonNode": "dijitDownArrowButton"
35 // constraints: _DateTimeTextBox.__Constraints
36 // Despite the name, this parameter specifies both constraints on the input
37 // (including starting/ending dates/times allowed) as well as
38 // formatting options like whether the date is displayed in long (ex: December 25, 2005)
39 // or short (ex: 12/25/2005) format. See `dijit/form/_DateTimeTextBox.__Constraints` for details.
43 // Override ValidationTextBox.pattern.... we use a reg-ex generating function rather
44 // than a straight regexp to deal with locale (plus formatting options too?)
45 pattern
: locale
.regexp
,
47 // datePackage: String
48 // JavaScript namespace to find calendar routines. If unspecified, uses Gregorian calendar routines
49 // at dojo/date and dojo/date/locale.
51 // TODO: for 2.0, replace datePackage with dateModule and dateLocalModule attributes specifying MIDs,
52 // or alternately just get rid of this completely and tell user to use module ID remapping
55 postMixInProperties: function(){
56 this.inherited(arguments
);
57 this._set("type", "text"); // in case type="date"|"time" was specified which messes up parse/format
60 // Override _FormWidget.compare() to work for dates/times
61 compare: function(/*Date*/ val1
, /*Date*/ val2
){
62 var isInvalid1
= this._isInvalidDate(val1
);
63 var isInvalid2
= this._isInvalidDate(val2
);
64 return isInvalid1
? (isInvalid2
? 0 : -1) : (isInvalid2
? 1 : date
.compare(val1
, val2
, this._selector
));
67 // flag to _HasDropDown to make drop down Calendar width == <input> width
70 format: function(/*Date*/ value
, /*locale.__FormatOptions*/ constraints
){
72 // Formats the value as a Date, according to specified locale (second argument)
75 if(!value
){ return ''; }
76 return this.dateLocaleModule
.format(value
, constraints
);
79 "parse": function(/*String*/ value
, /*locale.__FormatOptions*/ constraints
){
81 // Parses as string as a Date, according to constraints
85 return this.dateLocaleModule
.parse(value
, constraints
) || (this._isEmpty(value
) ? null : undefined); // Date
88 // Overrides ValidationTextBox.serialize() to serialize a date in canonical ISO format.
89 serialize: function(/*anything*/ val
, /*Object?*/ options
){
91 val
= val
.toGregorian();
93 return stamp
.toISOString(val
, options
);
96 // dropDownDefaultValue: Date
97 // The default value to focus in the popupClass widget when the textbox value is empty.
98 dropDownDefaultValue
: new Date(),
101 // The value of this widget as a JavaScript Date object. Use get("value") / set("value", val) to manipulate.
102 // When passed to the parser in markup, must be specified according to `dojo/date/stamp.fromISOString()`
103 value
: new Date(""), // value.toString()="NaN"
105 _blankValue
: null, // used by filter() when the textbox is blank
107 // popupClass: [protected extension] String
108 // Name of the popup widget class used to select a date/time.
109 // Subclasses should specify this.
110 popupClass
: "", // default is no popup = text only
113 // _selector: [protected extension] String
114 // Specifies constraints.selector passed to dojo.date functions, should be either
116 // Subclass must specify this.
119 constructor: function(params
/*===== , srcNodeRef =====*/){
121 // Create the widget.
122 // params: Object|null
123 // Hash of initialization parameters for widget, including scalar values (like title, duration etc.)
124 // and functions, typically callbacks like onClick.
125 // The hash can contain any of the widget's properties, excluding read-only properties.
126 // srcNodeRef: DOMNode|String?
127 // If a srcNodeRef (DOM node) is specified, replace srcNodeRef with my generated DOM tree
129 this.dateModule
= params
.datePackage
? lang
.getObject(params
.datePackage
, false) : date
;
130 this.dateClassObj
= this.dateModule
.Date
|| Date
;
131 this.dateLocaleModule
= params
.datePackage
? lang
.getObject(params
.datePackage
+".locale", false) : locale
;
132 this._set('pattern', this.dateLocaleModule
.regexp
);
133 this._invalidDate
= this.constructor.prototype.value
.toString();
136 buildRendering: function(){
137 this.inherited(arguments
);
139 if(!this.hasDownArrow
){
140 this._buttonNode
.style
.display
= "none";
143 // If hasDownArrow is false, we basically just want to treat the whole widget as the
145 if(!this.hasDownArrow
){
146 this._buttonNode
= this.domNode
;
147 this.baseClass
+= " dijitComboBoxOpenOnClick";
151 _setConstraintsAttr: function(/*Object*/ constraints
){
152 constraints
.selector
= this._selector
;
153 constraints
.fullYear
= true; // see #5465 - always format with 4-digit years
154 var fromISO
= stamp
.fromISOString
;
155 if(typeof constraints
.min
== "string"){ constraints
.min
= fromISO(constraints
.min
); }
156 if(typeof constraints
.max
== "string"){ constraints
.max
= fromISO(constraints
.max
); }
157 this.inherited(arguments
);
160 _isInvalidDate: function(/*Date*/ value
){
162 // Runs various tests on the value, checking for invalid conditions
165 return !value
|| isNaN(value
) || typeof value
!= "object" || value
.toString() == this._invalidDate
;
168 _setValueAttr: function(/*Date|String*/ value
, /*Boolean?*/ priorityChange
, /*String?*/ formattedValue
){
170 // Sets the date on this textbox. Note: value can be a JavaScript Date literal or a string to be parsed.
171 if(value
!== undefined){
172 if(typeof value
== "string"){
173 value
= stamp
.fromISOString(value
);
175 if(this._isInvalidDate(value
)){
178 if(value
instanceof Date
&& !(this.dateClassObj
instanceof Date
)){
179 value
= new this.dateClassObj(value
);
182 this.inherited(arguments
);
183 if(this.value
instanceof Date
){
184 this.filterString
= "";
187 this.dropDown
.set('value', value
, false);
191 _set: function(attr
, value
){
192 // Avoid spurious watch() notifications when value is changed to new Date object w/the same value
193 if(attr
== "value" && this.value
instanceof Date
&& this.compare(value
, this.value
) == 0){
196 this.inherited(arguments
);
199 _setDropDownDefaultValueAttr: function(/*Date*/ val
){
200 if(this._isInvalidDate(val
)){
201 // convert null setting into today's date, since there needs to be *some* default at all times.
202 val
= new this.dateClassObj();
204 this.dropDownDefaultValue
= val
;
207 openDropDown: function(/*Function*/ callback
){
208 // rebuild drop down every time, so that constraints get copied (#6002)
210 this.dropDown
.destroy();
212 var PopupProto
= lang
.isString(this.popupClass
) ? lang
.getObject(this.popupClass
, false) : this.popupClass
,
214 value
= this.get("value");
215 this.dropDown
= new PopupProto({
216 onChange: function(value
){
217 // this will cause InlineEditBox and other handlers to do stuff so make sure it's last
218 textBox
.set('value', value
, true);
220 id
: this.id
+ "_popup",
224 currentFocus
: !this._isInvalidDate(value
) ? value
: this.dropDownDefaultValue
,
225 constraints
: textBox
.constraints
,
226 filterString
: textBox
.filterString
, // for TimeTextBox, to filter times shown
227 datePackage
: textBox
.params
.datePackage
,
228 isDisabledDate: function(/*Date*/ date
){
230 // disables dates outside of the min/max of the _DateTimeTextBox
231 return !textBox
.rangeCheck(date
, textBox
.constraints
);
235 this.inherited(arguments
);
238 _getDisplayedValueAttr: function(){
239 return this.textbox
.value
;
242 _setDisplayedValueAttr: function(/*String*/ value
, /*Boolean?*/ priorityChange
){
243 this._setValueAttr(this.parse(value
, this.constraints
), priorityChange
, value
);
249 _DateTimeTextBox.__Constraints = declare([RangeBoundTextBox.__Constraints, locale.__FormatOptions], {
251 // Specifies both the rules on valid/invalid values (first/last date/time allowed),
252 // and also formatting options for how the date/time is displayed.
254 // To restrict to dates within 2004, displayed in a long format like "December 25, 2005":
255 // | {min:'2004-01-01',max:'2004-12-31', formatLength:'long'}
259 return _DateTimeTextBox
;