]> git.wh0rd.org - tt-rss.git/blob - lib/dijit/form/_DateTimeTextBox.js.uncompressed.js
make precache_headlines_idle() start slower
[tt-rss.git] / lib / dijit / form / _DateTimeTextBox.js.uncompressed.js
1 require({cache:{
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=\"&#9660; \" 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=\"&#935; \" 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
9 "./RangeBoundTextBox",
10 "../_HasDropDown",
11 "dojo/text!./templates/DropDownBox.html"
12 ], function(date, locale, stamp, declare, lang, RangeBoundTextBox, _HasDropDown, template){
13
14 /*=====
15 var _HasDropDown = dijit._HasDropDown;
16 var RangeBoundTextBox = dijit.form.RangeBoundTextBox;
17 =====*/
18
19 // module:
20 // dijit/form/_DateTimeTextBox
21 // summary:
22 // Base class for validating, serializable, range-bound date or time text box.
23
24
25 new Date("X"); // workaround for #11279, new Date("") == NaN
26
27 /*=====
28 declare(
29 "dijit.form._DateTimeTextBox.__Constraints",
30 [RangeBoundTextBox.__Constraints, locale.__FormatOptions], {
31 // summary:
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.
34 // example:
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'}
37 });
38 =====*/
39
40 var _DateTimeTextBox = declare("dijit.form._DateTimeTextBox", [RangeBoundTextBox, _HasDropDown], {
41 // summary:
42 // Base class for validating, serializable, range-bound date or time text box.
43
44 templateString: template,
45
46 // hasDownArrow: [const] Boolean
47 // Set this textbox to display a down arrow button, to open the drop down list.
48 hasDownArrow: true,
49
50 // openOnClick: [const] Boolean
51 // Set to true to open drop down upon clicking anywhere on the textbox.
52 openOnClick: true,
53
54 /*=====
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.
60 constraints: {},
61 ======*/
62
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,
66
67 // datePackage: String
68 // JavaScript namespace to find calendar routines. Uses Gregorian calendar routines
69 // at dojo.date, by default.
70 datePackage: date,
71
72 postMixInProperties: function(){
73 this.inherited(arguments);
74 this._set("type", "text"); // in case type="date"|"time" was specified which messes up parse/format
75 },
76
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));
82 },
83
84 // flag to _HasDropDown to make drop down Calendar width == <input> width
85 forceWidth: true,
86
87 format: function(/*Date*/ value, /*dojo.date.locale.__FormatOptions*/ constraints){
88 // summary:
89 // Formats the value as a Date, according to specified locale (second argument)
90 // tags:
91 // protected
92 if(!value){ return ''; }
93 return this.dateLocaleModule.format(value, constraints);
94 },
95
96 "parse": function(/*String*/ value, /*dojo.date.locale.__FormatOptions*/ constraints){
97 // summary:
98 // Parses as string as a Date, according to constraints
99 // tags:
100 // protected
101
102 return this.dateLocaleModule.parse(value, constraints) || (this._isEmpty(value) ? null : undefined); // Date
103 },
104
105 // Overrides ValidationTextBox.serialize() to serialize a date in canonical ISO format.
106 serialize: function(/*anything*/ val, /*Object?*/ options){
107 if(val.toGregorian){
108 val = val.toGregorian();
109 }
110 return stamp.toISOString(val, options);
111 },
112
113 // dropDownDefaultValue: Date
114 // The default value to focus in the popupClass widget when the textbox value is empty.
115 dropDownDefaultValue : new Date(),
116
117 // value: 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"
121
122 _blankValue: null, // used by filter() when the textbox is blank
123
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
128
129
130 // _selector: [protected extension] String
131 // Specifies constraints.selector passed to dojo.date functions, should be either
132 // "date" or "time".
133 // Subclass must specify this.
134 _selector: "",
135
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
140 this.datePackage;
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();
145 },
146
147 buildRendering: function(){
148 this.inherited(arguments);
149
150 if(!this.hasDownArrow){
151 this._buttonNode.style.display = "none";
152 }
153
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";
160 }
161 },
162
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);
170 },
171
172 _isInvalidDate: function(/*Date*/ value){
173 // summary:
174 // Runs various tests on the value, checking for invalid conditions
175 // tags:
176 // private
177 return !value || isNaN(value) || typeof value != "object" || value.toString() == this._invalidDate;
178 },
179
180 _setValueAttr: function(/*Date|String*/ value, /*Boolean?*/ priorityChange, /*String?*/ formattedValue){
181 // summary:
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);
186 }
187 if(this._isInvalidDate(value)){
188 value = null;
189 }
190 if(value instanceof Date && !(this.dateClassObj instanceof Date)){
191 value = new this.dateClassObj(value);
192 }
193 }
194 this.inherited(arguments);
195 if(this.value instanceof Date){
196 this.filterString = "";
197 }
198 if(this.dropDown){
199 this.dropDown.set('value', value, false);
200 }
201 },
202
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){
206 return;
207 }
208 this.inherited(arguments);
209 },
210
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();
215 }
216 this.dropDownDefaultValue = val;
217 },
218
219 openDropDown: function(/*Function*/ callback){
220 // rebuild drop down every time, so that constraints get copied (#6002)
221 if(this.dropDown){
222 this.dropDown.destroy();
223 }
224 var PopupProto = lang.isString(this.popupClass) ? lang.getObject(this.popupClass, false) : this.popupClass,
225 textBox = this,
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);
231 },
232 id: this.id + "_popup",
233 dir: textBox.dir,
234 lang: textBox.lang,
235 value: value,
236 currentFocus: !this._isInvalidDate(value) ? value : this.dropDownDefaultValue,
237 constraints: textBox.constraints,
238 filterString: textBox.filterString, // for TimeTextBox, to filter times shown
239
240 datePackage: textBox.datePackage,
241
242 isDisabledDate: function(/*Date*/ date){
243 // summary:
244 // disables dates outside of the min/max of the _DateTimeTextBox
245 return !textBox.rangeCheck(date, textBox.constraints);
246 }
247 });
248
249 this.inherited(arguments);
250 },
251
252 _getDisplayedValueAttr: function(){
253 return this.textbox.value;
254 },
255
256 _setDisplayedValueAttr: function(/*String*/ value, /*Boolean?*/ priorityChange){
257 this._setValueAttr(this.parse(value, this.constraints), priorityChange, value);
258 }
259 });
260
261 return _DateTimeTextBox;
262 });