]> git.wh0rd.org Git - tt-rss.git/blob - lib/dijit/form/_DateTimeTextBox.js.uncompressed.js
b950012882e5f0dc50a39dbfb960ddaff36575a6
[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=\"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=\"&#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         // module:
15         //              dijit/form/_DateTimeTextBox
16
17         new Date("X"); // workaround for #11279, new Date("") == NaN
18
19         var _DateTimeTextBox = declare("dijit.form._DateTimeTextBox", [RangeBoundTextBox, _HasDropDown], {
20                 // summary:
21                 //              Base class for validating, serializable, range-bound date or time text box.
22
23                 templateString: template,
24
25                 // hasDownArrow: [const] Boolean
26                 //              Set this textbox to display a down arrow button, to open the drop down list.
27                 hasDownArrow: true,
28
29                 // Set classes like dijitDownArrowButtonHover depending on mouse action over button node
30                 cssStateNodes: {
31                         "_buttonNode": "dijitDownArrowButton"
32                 },
33
34                 /*=====
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.
40                 constraints: {},
41                 ======*/
42
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,
46
47                 // datePackage: String
48                 //              JavaScript namespace to find calendar routines.  If unspecified, uses Gregorian calendar routines
49                 //              at dojo/date and dojo/date/locale.
50                 datePackage: "",
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
53                 //              via require
54
55                 postMixInProperties: function(){
56                         this.inherited(arguments);
57                         this._set("type", "text"); // in case type="date"|"time" was specified which messes up parse/format
58                 },
59
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));
65                 },
66
67                 // flag to _HasDropDown to make drop down Calendar width == <input> width
68                 forceWidth: true,
69
70                 format: function(/*Date*/ value, /*locale.__FormatOptions*/ constraints){
71                         // summary:
72                         //              Formats the value as a Date, according to specified locale (second argument)
73                         // tags:
74                         //              protected
75                         if(!value){ return ''; }
76                         return this.dateLocaleModule.format(value, constraints);
77                 },
78
79                 "parse": function(/*String*/ value, /*locale.__FormatOptions*/ constraints){
80                         // summary:
81                         //              Parses as string as a Date, according to constraints
82                         // tags:
83                         //              protected
84
85                         return this.dateLocaleModule.parse(value, constraints) || (this._isEmpty(value) ? null : undefined);     // Date
86                 },
87
88                 // Overrides ValidationTextBox.serialize() to serialize a date in canonical ISO format.
89                 serialize: function(/*anything*/ val, /*Object?*/ options){
90                         if(val.toGregorian){
91                                 val = val.toGregorian();
92                         }
93                         return stamp.toISOString(val, options);
94                 },
95
96                 // dropDownDefaultValue: Date
97                 //              The default value to focus in the popupClass widget when the textbox value is empty.
98                 dropDownDefaultValue : new Date(),
99
100                 // value: 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"
104
105                 _blankValue: null,      // used by filter() when the textbox is blank
106
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
111
112
113                 // _selector: [protected extension] String
114                 //              Specifies constraints.selector passed to dojo.date functions, should be either
115                 //              "date" or "time".
116                 //              Subclass must specify this.
117                 _selector: "",
118
119                 constructor: function(params /*===== , srcNodeRef =====*/){
120                         // summary:
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
128
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();
134                 },
135
136                 buildRendering: function(){
137                         this.inherited(arguments);
138
139                         if(!this.hasDownArrow){
140                                 this._buttonNode.style.display = "none";
141                         }
142
143                         // If hasDownArrow is false, we basically just want to treat the whole widget as the
144                         // button.
145                         if(!this.hasDownArrow){
146                                 this._buttonNode = this.domNode;
147                                 this.baseClass += " dijitComboBoxOpenOnClick";
148                         }
149                 },
150
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);
158                 },
159
160                 _isInvalidDate: function(/*Date*/ value){
161                         // summary:
162                         //              Runs various tests on the value, checking for invalid conditions
163                         // tags:
164                         //              private
165                         return !value || isNaN(value) || typeof value != "object" || value.toString() == this._invalidDate;
166                 },
167
168                 _setValueAttr: function(/*Date|String*/ value, /*Boolean?*/ priorityChange, /*String?*/ formattedValue){
169                         // summary:
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);
174                                 }
175                                 if(this._isInvalidDate(value)){
176                                         value = null;
177                                 }
178                                 if(value instanceof Date && !(this.dateClassObj instanceof Date)){
179                                         value = new this.dateClassObj(value);
180                                 }
181                         }
182                         this.inherited(arguments);
183                         if(this.value instanceof Date){
184                                 this.filterString = "";
185                         }
186                         if(this.dropDown){
187                                 this.dropDown.set('value', value, false);
188                         }
189                 },
190
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){
194                                 return;
195                         }
196                         this.inherited(arguments);
197                 },
198
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();
203                         }
204                         this.dropDownDefaultValue = val;
205                 },
206
207                 openDropDown: function(/*Function*/ callback){
208                         // rebuild drop down every time, so that constraints get copied (#6002)
209                         if(this.dropDown){
210                                 this.dropDown.destroy();
211                         }
212                         var PopupProto = lang.isString(this.popupClass) ? lang.getObject(this.popupClass, false) : this.popupClass,
213                                 textBox = this,
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);
219                                 },
220                                 id: this.id + "_popup",
221                                 dir: textBox.dir,
222                                 lang: textBox.lang,
223                                 value: value,
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){
229                                         // summary:
230                                         //              disables dates outside of the min/max of the _DateTimeTextBox
231                                         return !textBox.rangeCheck(date, textBox.constraints);
232                                 }
233                         });
234
235                         this.inherited(arguments);
236                 },
237
238                 _getDisplayedValueAttr: function(){
239                         return this.textbox.value;
240                 },
241
242                 _setDisplayedValueAttr: function(/*String*/ value, /*Boolean?*/ priorityChange){
243                         this._setValueAttr(this.parse(value, this.constraints), priorityChange, value);
244                 }
245         });
246
247
248         /*=====
249          _DateTimeTextBox.__Constraints = declare([RangeBoundTextBox.__Constraints, locale.__FormatOptions], {
250                  // summary:
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.
253                  // example:
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'}
256          });
257          =====*/
258
259         return _DateTimeTextBox;
260 });