@componyx/ui 0.0.0-stage → 1.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/AppSkin/AppSkin.css +1268 -0
- package/AppSkin/AppSkin.js +2748 -0
- package/AppSkin/Themes/Default.css +241 -0
- package/Base/Base.js +3407 -0
- package/Base/ComponentIcons.css +66 -0
- package/Base/Font/ComponentIcons.woff +0 -0
- package/Base/Font/UI.woff +0 -0
- package/Base/Library.js +8432 -0
- package/Base/NavigationManager.js +462 -0
- package/Base/ResponsiveTemplates.js +371 -0
- package/Base/Sanitizer.js +288 -0
- package/Base/Themes/Default.css +255 -0
- package/Base/UI.css +618 -0
- package/Base/UIResourcePath.js +6 -0
- package/Bindary/Bindary.js +2011 -0
- package/Bindary/Modules/Connection.js +216 -0
- package/Bindary/Modules/Core.js +854 -0
- package/Bindary/Modules/DataUpdater.js +351 -0
- package/Bindary/Modules/ExpressionEngine.js +347 -0
- package/Bindary/Modules/ProxyManager.js +482 -0
- package/Bindary/Modules/Renderer.js +605 -0
- package/Bindary/Modules/Router.js +291 -0
- package/Bindary/Modules/Scroller.js +89 -0
- package/Bindary/Modules/Template.js +1273 -0
- package/BookmarkSpy/BookmarkSpy.js +430 -0
- package/Box/Box.css +36 -0
- package/Box/Box.js +1685 -0
- package/Button/Button.css +470 -0
- package/Button/Button.js +1398 -0
- package/Button/Themes/Default.css +200 -0
- package/Carousel/Carousel.css +273 -0
- package/Carousel/Carousel.js +607 -0
- package/ColorButton/ColorButton.css +39 -0
- package/ColorButton/ColorButton.js +336 -0
- package/ColorPicker/ColorPicker.css +359 -0
- package/ColorPicker/ColorPicker.js +972 -0
- package/ComboBox/ComboBox.css +357 -0
- package/ComboBox/ComboBox.js +2342 -0
- package/ComboBox/Themes/Default.css +23 -0
- package/DataPager/DataPager.css +72 -0
- package/DataPager/DataPager.js +674 -0
- package/DatePicker/DatePicker.css +227 -0
- package/DatePicker/DatePicker.js +1531 -0
- package/DatePicker/Themes/Default.css +26 -0
- package/Dialog/Dialog.css +106 -0
- package/Dialog/Dialog.js +572 -0
- package/Dialog/Themes/Default.css +10 -0
- package/Editor/Data/Emoji.json +8285 -0
- package/Editor/Data/Special.json +1042 -0
- package/Editor/Editor.css +1562 -0
- package/Editor/Editor.js +4058 -0
- package/Editor/Font/Editor.woff +0 -0
- package/Editor/Modules/ComponentFactory.js +565 -0
- package/Editor/Modules/ContentManager.js +748 -0
- package/Editor/Modules/DialogManager.js +1234 -0
- package/Editor/Modules/EventManager.js +458 -0
- package/Editor/Modules/Format.js +950 -0
- package/Editor/Modules/History.js +191 -0
- package/Editor/Modules/LayoutState.js +379 -0
- package/Editor/Modules/ListManager.js +296 -0
- package/Editor/Modules/MenuManager.js +388 -0
- package/Editor/Modules/NodeManager.js +681 -0
- package/Editor/Modules/ParagraphButtons.js +122 -0
- package/Editor/Modules/Resizer.js +176 -0
- package/Editor/Modules/SelectionRange.js +564 -0
- package/Editor/Modules/SourceViewBuilder.js +212 -0
- package/Editor/Modules/SymbolPicker.js +208 -0
- package/Editor/Modules/Table.js +2327 -0
- package/Editor/Modules/TableDialog.js +757 -0
- package/Editor/Modules/Toolbar.js +375 -0
- package/Editor/Modules/TooltipMenu.js +125 -0
- package/Editor/Modules/Utility.js +131 -0
- package/Editor/Themes/Default.css +204 -0
- package/FileUpload/FileUpload.css +156 -0
- package/FileUpload/FileUpload.js +898 -0
- package/FileUpload/Themes/Default.css +17 -0
- package/Form/Form.css +1934 -0
- package/Form/Form.js +4943 -0
- package/Form/Modules/ActionManager.js +368 -0
- package/Form/Modules/BuildPanelManager.js +319 -0
- package/Form/Modules/ComponentFactory.js +468 -0
- package/Form/Modules/ComponentPanel.js +265 -0
- package/Form/Modules/ConfigPanelManager.js +685 -0
- package/Form/Modules/DataObserver.js +717 -0
- package/Form/Modules/Databinder.js +602 -0
- package/Form/Modules/Draggable.js +756 -0
- package/Form/Modules/OptionsPanel.js +342 -0
- package/Form/Modules/Renderer.js +1889 -0
- package/Form/Modules/RuleEngine.js +585 -0
- package/Form/Modules/RulesPanel.js +1158 -0
- package/Form/Modules/Types.js +1709 -0
- package/Form/Modules/ValidationManager.js +194 -0
- package/Form/Themes/Default.css +216 -0
- package/FormField/FormField.css +468 -0
- package/FormField/FormField.js +576 -0
- package/FormField/Themes/Default.css +99 -0
- package/Grid/Grid.css +544 -0
- package/Grid/Grid.js +3761 -0
- package/Grid/Themes/Default.css +43 -0
- package/LICENSE +126 -0
- package/MaskedTextBox/MaskedTextBox.css +28 -0
- package/MaskedTextBox/MaskedTextBox.js +642 -0
- package/MaskedTextBox/Themes/Default.css +6 -0
- package/Menu/Menu.css +328 -0
- package/Menu/Menu.js +2386 -0
- package/Menu/Themes/Default.css +24 -0
- package/NumericBox/NumericBox.css +120 -0
- package/NumericBox/NumericBox.js +984 -0
- package/PanelBar/PanelBar.css +123 -0
- package/PanelBar/PanelBar.js +505 -0
- package/PanelBar/Themes/Default.css +51 -0
- package/PieChart/PieChart.css +95 -0
- package/PieChart/PieChart.js +820 -0
- package/PieChart/Themes/Default.css +9 -0
- package/README.md +178 -3
- package/Slider/Slider.css +348 -0
- package/Slider/Slider.js +1306 -0
- package/Slider/Themes/Default.css +44 -0
- package/TabStrip/TabStrip.css +52 -0
- package/TabStrip/TabStrip.js +362 -0
- package/TabStrip/Themes/Default.css +35 -0
- package/TimePicker/Themes/Default.css +30 -0
- package/TimePicker/TimePicker.css +253 -0
- package/TimePicker/TimePicker.js +1485 -0
- package/TooltipManager/Themes/Default.css +21 -0
- package/TooltipManager/TooltipManager.css +227 -0
- package/TooltipManager/TooltipManager.js +791 -0
- package/Validator/Validator.css +54 -0
- package/Validator/Validator.js +2508 -0
- package/componyx.html-data.json +619 -0
- package/index.js +27 -0
- package/package.json +43 -4
- package/types/AppSkin.d.ts +842 -0
- package/types/Base.d.ts +1034 -0
- package/types/Bindary.d.ts +1196 -0
- package/types/BookmarkSpy.d.ts +112 -0
- package/types/Box.d.ts +374 -0
- package/types/Button.d.ts +455 -0
- package/types/Carousel.d.ts +136 -0
- package/types/ColorButton.d.ts +120 -0
- package/types/ColorPicker.d.ts +225 -0
- package/types/ComboBox.d.ts +507 -0
- package/types/DataPager.d.ts +152 -0
- package/types/DatePicker.d.ts +354 -0
- package/types/Dialog.d.ts +160 -0
- package/types/Editor.d.ts +1289 -0
- package/types/FileUpload.d.ts +206 -0
- package/types/Form.d.ts +3078 -0
- package/types/FormField.d.ts +204 -0
- package/types/Grid.d.ts +911 -0
- package/types/Library.d.ts +1899 -0
- package/types/MaskedTextBox.d.ts +91 -0
- package/types/Menu.d.ts +577 -0
- package/types/NumericBox.d.ts +310 -0
- package/types/PanelBar.d.ts +223 -0
- package/types/PieChart.d.ts +224 -0
- package/types/ResponsiveTemplates.d.ts +108 -0
- package/types/Slider.d.ts +227 -0
- package/types/TabStrip.d.ts +185 -0
- package/types/TimePicker.d.ts +265 -0
- package/types/TooltipManager.d.ts +178 -0
- package/types/UI.d.ts +29 -0
- package/types/Validator.d.ts +653 -0
- package/types/index.d.ts +59 -0
- package/ui.css +11783 -0
- package/ui.js +79477 -0
- package/ui.min.css +138 -0
- package/ui.min.js +264 -0
- package/ui.min.js.map +1 -0
|
@@ -0,0 +1,1531 @@
|
|
|
1
|
+
/*! Componyx.UI | (c) E.H. Daanen / Componyx | BUSL-1.1 | componyx.com/license */
|
|
2
|
+
import '../Base/Base.js';
|
|
3
|
+
import '../Base/Library.js';
|
|
4
|
+
import '../Dialog/Dialog.js';
|
|
5
|
+
import '../Button/Button.js';
|
|
6
|
+
import '../NumericBox/NumericBox.js';
|
|
7
|
+
|
|
8
|
+
(function (window)
|
|
9
|
+
{
|
|
10
|
+
/**
|
|
11
|
+
* DatePicker class.
|
|
12
|
+
* @class
|
|
13
|
+
* @memberof componyx.UI
|
|
14
|
+
* @augments componyx.UI.base.Component
|
|
15
|
+
* @mixes componyx.UI.base.methods
|
|
16
|
+
* @param {String} id The id of the component.
|
|
17
|
+
* @param {Object|HTMLElement} properties The properties used to initialize the component or the container element.
|
|
18
|
+
* @returns {Object} An instance of the component.
|
|
19
|
+
* @property {String} cssClassNumericBox - Gets or sets the css class of the numericbox.
|
|
20
|
+
* @property {String} cssClassDay - Gets or sets the css class of the day input.
|
|
21
|
+
* @property {String} cssClassMonth - Gets or sets the css class of the month input.
|
|
22
|
+
* @property {String} cssClassYear - Gets or sets the css class of the year input.
|
|
23
|
+
* @property {String} cssClassPicker - Gets or sets the css class of the picker button.
|
|
24
|
+
* @property {String} cssClassCalendar - Gets or sets the css class of the calendar dialog.
|
|
25
|
+
* @property {String} cssClassPrevMonth - Gets or sets the css class of the prev month button.
|
|
26
|
+
* @property {String} cssClassNextMonth - Gets or sets the css class of the next month button.
|
|
27
|
+
* @property {String} cssClassHeaderLabel - Gets or sets the css class of the calendar header label.
|
|
28
|
+
* @property {String} cssClassWeekNumber - Gets or sets the css class of the week number cell in the calendar.
|
|
29
|
+
* @property {String} cssClassCurrentWeek - Gets or sets the css class of the current week row in the calendar.
|
|
30
|
+
* @property {String} cssClassToday - Gets or sets the css class of the current day cell in the calendar.
|
|
31
|
+
* @property {String} cssClassInactive - Gets or sets the css class of an inactive day cell in the calendar.
|
|
32
|
+
* @property {String} dateFormat - Gets or sets the input format for dates. Default: MM/dd/yyyy.
|
|
33
|
+
* @property {componyx.UI.DatePicker.FirstDayOfWeekOption} firstDayOfWeek - Gets or sets the first day of the week.
|
|
34
|
+
* @property {Boolean} today - Gets or sets a value indicating whether today should be used as initial selected date.
|
|
35
|
+
* @property {String} dayPlaceholder - Gets or sets the placeholder which is visible when the day input box has no value. Default: DD.
|
|
36
|
+
* @property {String} monthPlaceholder - Gets or sets the placeholder which is visible when the month input box has no value. Default: MM.
|
|
37
|
+
* @property {String} yearPlaceholder - Gets or sets the placeholder which is visible when the year input box has no value. Default: YYYY.
|
|
38
|
+
* @property {componyx.UI.DatePicker.ViewModeOption} viewMode - Gets or sets the view mode in which the date picker is rendered.
|
|
39
|
+
* @property {Boolean} weekNumbers - Gets or sets a value indicating if week numbers are displayed in the calendar.
|
|
40
|
+
* @property {Boolean} readOnly - Gets or sets a value indicating whether the date picker is readonly.
|
|
41
|
+
* @property {Boolean} disabled - Gets or sets a value indicating whether the date picker is disabled.
|
|
42
|
+
* @property {Boolean} calendarDayLeadingZero - Gets or sets a value indicating whether a calendar day has a leading zero.
|
|
43
|
+
* @property {Boolean} autoFocus - Gets or sets a value indicating whether focus on an input field is automaticly moved to the next field while typing.
|
|
44
|
+
* @property {String[]} months - Gets or sets the month names as List of StringValue objects.
|
|
45
|
+
* @property {String[]} days - Gets or sets the day names as List of StringValue objects.
|
|
46
|
+
* @property {String} name - Gets or sets the hidden input field name which contains the selected date in the specified date format.
|
|
47
|
+
* @property {String|Date} value - Gets or sets the initial date value.
|
|
48
|
+
* @property {String|Date} minValue - Gets or sets the minimum allowed date value.
|
|
49
|
+
* @property {String|Date} maxValue - Gets or sets the maximum allowed date value.
|
|
50
|
+
* @property {String[]|Date[]} allowedDates - Gets or sets a list of allowed calendar dates. Separate two date strings with a space to specify allowed range. When allowed dates are set, date input fields are rendered in readonly mode.
|
|
51
|
+
* @property {Boolean} disallowDates - Gets or sets a value indicating if the dates specified in the dates property are disallowed instead of the default allowed.
|
|
52
|
+
* @property {String} pickerButtonId - Gets or sets the id of the picker button from which the settings are cloned.
|
|
53
|
+
* @property {String} dayNumericBoxId - Gets or sets the id of the day numeric box from which the settings are cloned.
|
|
54
|
+
* @property {String} monthNumericBoxId - Gets or sets the id of the month numeric box from which the settings are cloned.
|
|
55
|
+
* @property {String} yearNumericBoxId - Gets or sets the id of the year numeric box from which the settings are cloned.
|
|
56
|
+
* @property {String} calendarMonthNumericBoxId - Gets or sets the id of the month numeric box in the calendar from which the settings are cloned.
|
|
57
|
+
* @property {String} calendarYearNumericBoxId - Gets or sets the id of the year numeric box in the calendar from which the settings are cloned.
|
|
58
|
+
* @property {String} dialogId - Gets or sets the id of the dialog from which the settings are cloned.
|
|
59
|
+
* @property {String} hiddenInputId - Gets or sets the id of the hidden input from which the settings are cloned. The hidden input contains the date in the configured date-format when a valid date is given.
|
|
60
|
+
*/
|
|
61
|
+
componyx.UI.DatePicker = function DatePicker(id, properties)
|
|
62
|
+
{
|
|
63
|
+
// define private properties
|
|
64
|
+
var _instance = this,
|
|
65
|
+
_hidden,
|
|
66
|
+
_today = new Date(),
|
|
67
|
+
_date = null,
|
|
68
|
+
_calendarDate = null,
|
|
69
|
+
_dayInput = null,
|
|
70
|
+
_monthInput = null,
|
|
71
|
+
_yearInput = null,
|
|
72
|
+
_pickerButton = null,
|
|
73
|
+
_calendarDialog = null,
|
|
74
|
+
_calendarMonthInput = null,
|
|
75
|
+
_calendarYearInput = null,
|
|
76
|
+
_day = null,
|
|
77
|
+
_tabFocus,
|
|
78
|
+
_dayButtons = [];
|
|
79
|
+
$base.static.ThemeOption;
|
|
80
|
+
var _firstDayOfWeekOption = componyx.UI.DatePicker.FirstDayOfWeekOption,
|
|
81
|
+
_viewModeOption = componyx.UI.DatePicker.ViewModeOption,
|
|
82
|
+
_classOption =
|
|
83
|
+
{
|
|
84
|
+
NUMERICBOX: 'numeric-box',
|
|
85
|
+
DAY: 'day',
|
|
86
|
+
MONTH: 'month',
|
|
87
|
+
YEAR: 'year',
|
|
88
|
+
LAST: ' last',
|
|
89
|
+
PICKER: 'button picker',
|
|
90
|
+
CALENDAR: 'dialog calendar',
|
|
91
|
+
PREVMONTH: 'button prev',
|
|
92
|
+
NEXTMONTH: 'button next',
|
|
93
|
+
HEADERLABEL: 'header-label',
|
|
94
|
+
WEEKNUMBER: 'week-number',
|
|
95
|
+
CURRENTWEEK: 'current-week',
|
|
96
|
+
TODAY: 'today',
|
|
97
|
+
INACTIVE: 'inactive'
|
|
98
|
+
};
|
|
99
|
+
|
|
100
|
+
// define public properties
|
|
101
|
+
this.cssClassNumericBox = '';
|
|
102
|
+
this.cssClassDay = '';
|
|
103
|
+
this.cssClassMonth = '';
|
|
104
|
+
this.cssClassYear = '';
|
|
105
|
+
this.cssClassPicker = '';
|
|
106
|
+
this.cssClassCalendar = '';
|
|
107
|
+
this.cssClassPrevMonth = '';
|
|
108
|
+
this.cssClassNextMonth = '';
|
|
109
|
+
this.cssClassHeaderLabel = '';
|
|
110
|
+
this.cssClassWeekNumber = '';
|
|
111
|
+
this.cssClassCurrentWeek = '';
|
|
112
|
+
this.cssClassToday = '';
|
|
113
|
+
this.cssClassInactive = '';
|
|
114
|
+
this.dateFormat = 'MM/dd/yyyy';
|
|
115
|
+
this.firstDayOfWeek = _firstDayOfWeekOption.SUNDAY;
|
|
116
|
+
this.today = false;
|
|
117
|
+
this.dayPlaceholder = 'DD';
|
|
118
|
+
this.monthPlaceholder = 'MM';
|
|
119
|
+
this.yearPlaceholder = 'YYYY';
|
|
120
|
+
this.viewMode = _viewModeOption.INPUT_CALENDAR_POPUP;
|
|
121
|
+
this.weekNumbers = true;
|
|
122
|
+
this.readOnly = false;
|
|
123
|
+
this.disabled = false;
|
|
124
|
+
this.calendarDayLeadingZero = false;
|
|
125
|
+
this.autoFocus = true;
|
|
126
|
+
this.months = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'];
|
|
127
|
+
this.days = ['su', 'mo', 'tu', 'we', 'th', 'fr', 'sa'];
|
|
128
|
+
this.name = '';
|
|
129
|
+
this.value = null;
|
|
130
|
+
this.minValue = null;
|
|
131
|
+
this.maxValue = null;
|
|
132
|
+
this.allowedDates = [];
|
|
133
|
+
this.disallowDates = false;
|
|
134
|
+
this.pickerButtonId = null;
|
|
135
|
+
this.dayNumericBoxId = null;
|
|
136
|
+
this.monthNumericBoxId = null;
|
|
137
|
+
this.yearNumericBoxId = null;
|
|
138
|
+
this.calendarMonthNumericBoxId = null;
|
|
139
|
+
this.calendarYearNumericBoxId = null;
|
|
140
|
+
this.dialogId = null;
|
|
141
|
+
this.hiddenInputId = null;
|
|
142
|
+
|
|
143
|
+
/**
|
|
144
|
+
* @class
|
|
145
|
+
* @augments componyx.UI.base.Events
|
|
146
|
+
* @memberof componyx.UI.DatePicker
|
|
147
|
+
* @property {componyx.UI.base.Event} onFocus - Event which fires when the date picker is focused.
|
|
148
|
+
* @property {componyx.UI.base.Event} onBlur - Event which fires when the date picker is blurred.
|
|
149
|
+
* @property {componyx.UI.base.Event} onChanged - Event which fires when the date has changed. @see {@link componyx.UI.DatePicker.ChangedEventArgs}
|
|
150
|
+
* @property {componyx.UI.base.Event} onCalendarWeekRender - Event which fires when a calendar week is rendered. @see {@link componyx.UI.DatePicker.CalendarRenderEventArgs}
|
|
151
|
+
* @property {componyx.UI.base.Event} onCalendarDayRender - Event which fires when a calendar day is rendered. @see {@link componyx.UI.DatePicker.CalendarRenderEventArgs}
|
|
152
|
+
* @see {@link componyx.UI.base.Events}
|
|
153
|
+
*/
|
|
154
|
+
function DatePickerEvents(events)
|
|
155
|
+
{
|
|
156
|
+
Object.assign(this, events);
|
|
157
|
+
|
|
158
|
+
this.onFocus = $base.static.createEvent('onFocus');
|
|
159
|
+
this.onBlur = $base.static.createEvent('onBlur');
|
|
160
|
+
this.onChanged = $base.static.createEvent('onChanged');
|
|
161
|
+
this.onCalendarWeekRender = $base.static.createEvent('onCalendarWeekRender');
|
|
162
|
+
this.onCalendarDayRender = $base.static.createEvent('onCalendarDayRender');
|
|
163
|
+
}
|
|
164
|
+
/**
|
|
165
|
+
* DatePicker events
|
|
166
|
+
* @type {componyx.UI.DatePicker.DatePickerEvents}
|
|
167
|
+
*/
|
|
168
|
+
this.events = new DatePickerEvents(this.events);
|
|
169
|
+
|
|
170
|
+
/**
|
|
171
|
+
* DatePicker changed event arguments.
|
|
172
|
+
* @typedef {Object} ChangedEventArgs
|
|
173
|
+
* @memberof componyx.UI.DatePicker
|
|
174
|
+
* @property {Date|null} date - The selected date, or null when the date was cleared.
|
|
175
|
+
*/
|
|
176
|
+
|
|
177
|
+
/**
|
|
178
|
+
* DatePicker calendar render event arguments (week and day).
|
|
179
|
+
* @typedef {Object} CalendarRenderEventArgs
|
|
180
|
+
* @memberof componyx.UI.DatePicker
|
|
181
|
+
* @property {HTMLTableRowElement} row - The table row of the calendar week.
|
|
182
|
+
* @property {HTMLTableCellElement} [cell] - The table cell of the calendar day (onCalendarDayRender only).
|
|
183
|
+
* @property {componyx.UI.Button} [button] - The button of the calendar day (onCalendarDayRender only).
|
|
184
|
+
* @property {Date} date - The date of the first day shown in the week row (week render) or the date of the day (day render).
|
|
185
|
+
*/
|
|
186
|
+
|
|
187
|
+
// inherit base instance members
|
|
188
|
+
$base.Component.apply(this, [id, properties]);
|
|
189
|
+
|
|
190
|
+
/**
|
|
191
|
+
* Resets all inputs to the initial value.
|
|
192
|
+
* @param {Boolean} [fireEvent=false] A value indicating if the onChanged event is fired.
|
|
193
|
+
*/
|
|
194
|
+
this.reset = function (fireEvent)
|
|
195
|
+
{
|
|
196
|
+
reset(($lib.isEmpty(fireEvent)) ? false : fireEvent);
|
|
197
|
+
};
|
|
198
|
+
|
|
199
|
+
/**
|
|
200
|
+
* Clears all input values.
|
|
201
|
+
* @param {Boolean} [fireEvent=false] A value indicating if the onChanged event is fired.
|
|
202
|
+
*/
|
|
203
|
+
this.clear = function (fireEvent)
|
|
204
|
+
{
|
|
205
|
+
clear(($lib.isEmpty(fireEvent)) ? false : fireEvent);
|
|
206
|
+
};
|
|
207
|
+
|
|
208
|
+
/**
|
|
209
|
+
* Selects the text of the first input field of the datepicker.
|
|
210
|
+
*/
|
|
211
|
+
this.select = function ()
|
|
212
|
+
{
|
|
213
|
+
select();
|
|
214
|
+
};
|
|
215
|
+
|
|
216
|
+
/**
|
|
217
|
+
* Gets the day numeric box.
|
|
218
|
+
* @returns {componyx.UI.NumericBox} The numeric box instance.
|
|
219
|
+
*/
|
|
220
|
+
this.getDayNumericBox = function ()
|
|
221
|
+
{
|
|
222
|
+
return $UI.store[_instance.id + '_D'];
|
|
223
|
+
};
|
|
224
|
+
|
|
225
|
+
/**
|
|
226
|
+
* Gets the month numeric box.
|
|
227
|
+
* @returns {componyx.UI.NumericBox} The numeric box instance.
|
|
228
|
+
*/
|
|
229
|
+
this.getMonthNumericBox = function ()
|
|
230
|
+
{
|
|
231
|
+
return $UI.store[_instance.id + '_M'];
|
|
232
|
+
};
|
|
233
|
+
|
|
234
|
+
/**
|
|
235
|
+
* Gets the year numeric box.
|
|
236
|
+
* @returns {componyx.UI.NumericBox} The numeric box instance.
|
|
237
|
+
*/
|
|
238
|
+
this.getYearNumericBox = function ()
|
|
239
|
+
{
|
|
240
|
+
return $UI.store[_instance.id + '_Y'];
|
|
241
|
+
};
|
|
242
|
+
|
|
243
|
+
/**
|
|
244
|
+
* Gets the calendar month numeric box.
|
|
245
|
+
* @returns {componyx.UI.NumericBox} The numeric box instance.
|
|
246
|
+
*/
|
|
247
|
+
this.getCalendarMonthNumericBox = function ()
|
|
248
|
+
{
|
|
249
|
+
return (_calendarDialog) ? $UI.store[_calendarDialog.id + '_M'] : null;
|
|
250
|
+
};
|
|
251
|
+
|
|
252
|
+
/**
|
|
253
|
+
* Gets the calendar year numeric box.
|
|
254
|
+
* @returns {componyx.UI.NumericBox} The numeric box instance.
|
|
255
|
+
*/
|
|
256
|
+
this.getCalendarYearNumericBox = function ()
|
|
257
|
+
{
|
|
258
|
+
return (_calendarDialog) ? $UI.store[_calendarDialog.id + '_Y'] : null;
|
|
259
|
+
};
|
|
260
|
+
|
|
261
|
+
/**
|
|
262
|
+
* Shows the calendar.
|
|
263
|
+
*/
|
|
264
|
+
this.showCalendar = function ()
|
|
265
|
+
{
|
|
266
|
+
showCalendar();
|
|
267
|
+
};
|
|
268
|
+
|
|
269
|
+
/**
|
|
270
|
+
* Hides the calendar.
|
|
271
|
+
*/
|
|
272
|
+
this.hideCalendar = function ()
|
|
273
|
+
{
|
|
274
|
+
hideCalendar();
|
|
275
|
+
};
|
|
276
|
+
|
|
277
|
+
/**
|
|
278
|
+
* Gets the selected date.
|
|
279
|
+
* @returns {Date} The selected date.
|
|
280
|
+
*/
|
|
281
|
+
this.getDate = function ()
|
|
282
|
+
{
|
|
283
|
+
return getDate();
|
|
284
|
+
};
|
|
285
|
+
|
|
286
|
+
/**
|
|
287
|
+
* Sets the date.
|
|
288
|
+
* @param {Date} date The date object.
|
|
289
|
+
* @param {Boolean} [fireEvent=false] A value indicating if the onChanged event is fired.
|
|
290
|
+
*/
|
|
291
|
+
this.setDate = function (date, fireEvent)
|
|
292
|
+
{
|
|
293
|
+
setDate(date, ($lib.isEmpty(fireEvent)) ? false : fireEvent);
|
|
294
|
+
};
|
|
295
|
+
|
|
296
|
+
/**
|
|
297
|
+
* Sets the date.
|
|
298
|
+
* @param {String} value The date value in the specified date format.
|
|
299
|
+
* @param {Boolean} [fireEvent=false] A value indicating if the onChanged event is fired.
|
|
300
|
+
*/
|
|
301
|
+
this.setValue = function (value, fireEvent)
|
|
302
|
+
{
|
|
303
|
+
setDate(value || null, ($lib.isEmpty(fireEvent)) ? false : fireEvent);
|
|
304
|
+
};
|
|
305
|
+
|
|
306
|
+
/**
|
|
307
|
+
* Gets the input field value which holds the date in the specified date format.
|
|
308
|
+
* @returns {String} The selected date value in the specified date format.
|
|
309
|
+
*/
|
|
310
|
+
this.getValue = function ()
|
|
311
|
+
{
|
|
312
|
+
return getValue();
|
|
313
|
+
};
|
|
314
|
+
|
|
315
|
+
/**
|
|
316
|
+
* Gets the input field value as ISO8601 string.
|
|
317
|
+
* @returns {String} The selected date value as ISO8601 string.
|
|
318
|
+
*/
|
|
319
|
+
this.getISOValue = function ()
|
|
320
|
+
{
|
|
321
|
+
const dt = this.getDate();
|
|
322
|
+
|
|
323
|
+
if (!dt)
|
|
324
|
+
return null;
|
|
325
|
+
|
|
326
|
+
return $lib.formatDate(dt, 'yyyy-MM-dd');
|
|
327
|
+
};
|
|
328
|
+
|
|
329
|
+
/**
|
|
330
|
+
* Defines the template for the input separator.
|
|
331
|
+
* @param {HTMLElement|HTMLElement[]|DocumentFragment|String} content The content of the template.
|
|
332
|
+
*/
|
|
333
|
+
this.setSeparatorTemplate = function (content)
|
|
334
|
+
{
|
|
335
|
+
_instance.addTemplate('Separator', content, true);
|
|
336
|
+
};
|
|
337
|
+
|
|
338
|
+
/**
|
|
339
|
+
* Gets a value indicating if the specified date is allowed.
|
|
340
|
+
* @param {Date|String} date The date to check.
|
|
341
|
+
* @returns {Boolean} A value indicating if the date is allowed.
|
|
342
|
+
*/
|
|
343
|
+
this.isAllowedDate = function (date)
|
|
344
|
+
{
|
|
345
|
+
return isAllowedDate(date);
|
|
346
|
+
};
|
|
347
|
+
|
|
348
|
+
/**
|
|
349
|
+
* Renders the component
|
|
350
|
+
*/
|
|
351
|
+
this.render = function ()
|
|
352
|
+
{
|
|
353
|
+
if (_instance.renderState != $base.static.RenderState.RENDERING)
|
|
354
|
+
{
|
|
355
|
+
// call base render and return
|
|
356
|
+
$base.methods.render.call(_instance, preRender, 'date-picker');
|
|
357
|
+
return;
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
// render logic after loading resources
|
|
361
|
+
draw();
|
|
362
|
+
};
|
|
363
|
+
|
|
364
|
+
/**
|
|
365
|
+
* Executes the post render procedure.
|
|
366
|
+
*/
|
|
367
|
+
this.postRender = function ()
|
|
368
|
+
{
|
|
369
|
+
if (_instance.renderState == $base.static.RenderState.RENDERED)
|
|
370
|
+
return;
|
|
371
|
+
|
|
372
|
+
if (_instance.viewMode == _viewModeOption.INPUT_CALENDAR_STATIC || _instance.viewMode == _viewModeOption.CALENDAR)
|
|
373
|
+
showCalendar();
|
|
374
|
+
|
|
375
|
+
if (_instance.viewMode == _viewModeOption.INPUT_CALENDAR_POPUP)
|
|
376
|
+
{
|
|
377
|
+
setInputEvent(_dayInput.getInput());
|
|
378
|
+
setInputEvent(_monthInput.getInput());
|
|
379
|
+
setInputEvent(_yearInput.getInput());
|
|
380
|
+
}
|
|
381
|
+
|
|
382
|
+
$base.methods.postRender.call(_instance);
|
|
383
|
+
};
|
|
384
|
+
|
|
385
|
+
/**
|
|
386
|
+
* Destroys the component.
|
|
387
|
+
* @see {@link componyx.UI.base.methods#destroy}
|
|
388
|
+
*/
|
|
389
|
+
this.destroy = function (...args)
|
|
390
|
+
{
|
|
391
|
+
dispose();
|
|
392
|
+
$base.methods.destroy.call(this, ...args);
|
|
393
|
+
};
|
|
394
|
+
|
|
395
|
+
function preRender()
|
|
396
|
+
{
|
|
397
|
+
// initialize script and css
|
|
398
|
+
var scripts = ['Button', 'NumericBox'];
|
|
399
|
+
|
|
400
|
+
if (_instance.viewMode != _viewModeOption.INPUT)
|
|
401
|
+
scripts.push('Dialog');
|
|
402
|
+
|
|
403
|
+
return ['DatePicker', scripts];
|
|
404
|
+
}
|
|
405
|
+
|
|
406
|
+
function setInputEvent(input)
|
|
407
|
+
{
|
|
408
|
+
$lib.on(input, 'keyup', inputKeyUp);
|
|
409
|
+
}
|
|
410
|
+
|
|
411
|
+
function draw()
|
|
412
|
+
{
|
|
413
|
+
var format = _instance.dateFormat.toLowerCase(),
|
|
414
|
+
splitChar = format.match(/[^\w]/)[0];
|
|
415
|
+
|
|
416
|
+
_hidden = _instance.createSyncedInput(_instance.hiddenInputId, function ()
|
|
417
|
+
{
|
|
418
|
+
setDate(this.value);
|
|
419
|
+
});
|
|
420
|
+
|
|
421
|
+
initDates();
|
|
422
|
+
|
|
423
|
+
if (($lib.touch && _instance.autoTouchConfig && isPopup()) || !$lib.isEmpty(_instance.allowedDates))
|
|
424
|
+
_instance.readOnly = true;
|
|
425
|
+
|
|
426
|
+
if (_instance.viewMode < 3)
|
|
427
|
+
{
|
|
428
|
+
addInput(format);
|
|
429
|
+
format = format.substring(format.indexOf(splitChar) + 1);
|
|
430
|
+
_instance.applyTemplate(_instance.element, 'Separator');
|
|
431
|
+
addInput(format);
|
|
432
|
+
format = format.substring(format.indexOf(splitChar) + 1);
|
|
433
|
+
_instance.applyTemplate(_instance.element, 'Separator');
|
|
434
|
+
addInput(format);
|
|
435
|
+
}
|
|
436
|
+
|
|
437
|
+
setValue();
|
|
438
|
+
|
|
439
|
+
if (!$lib.isEmpty(_date))
|
|
440
|
+
_day = _date.getDate();
|
|
441
|
+
|
|
442
|
+
if (isPopup())
|
|
443
|
+
{
|
|
444
|
+
createPicker();
|
|
445
|
+
$lib.on(window, 'keyup', checkTabFocus);
|
|
446
|
+
}
|
|
447
|
+
|
|
448
|
+
if (_instance.viewMode != _viewModeOption.INPUT)
|
|
449
|
+
createCalendar();
|
|
450
|
+
|
|
451
|
+
_instance.renderChildren();
|
|
452
|
+
}
|
|
453
|
+
|
|
454
|
+
function initDates()
|
|
455
|
+
{
|
|
456
|
+
var allowedDates = _instance.allowedDates;
|
|
457
|
+
|
|
458
|
+
_date = _instance.value = _instance.value || _hidden.value;
|
|
459
|
+
|
|
460
|
+
if (!$lib.isEmpty(_date))
|
|
461
|
+
_date = convertDate(_date);
|
|
462
|
+
else if (_instance.today)
|
|
463
|
+
_date = _today;
|
|
464
|
+
|
|
465
|
+
_instance.minValue = convertDate(_instance.minValue);
|
|
466
|
+
_instance.maxValue = convertDate(_instance.maxValue);
|
|
467
|
+
|
|
468
|
+
$lib.each(allowedDates, function (date, index)
|
|
469
|
+
{
|
|
470
|
+
if (date.indexOf(' ') > -1) // min-max
|
|
471
|
+
allowedDates[index] = [convertDate(date.split(' ')[0]), convertDate(date.split(' ')[1])];
|
|
472
|
+
else
|
|
473
|
+
allowedDates[index] = [convertDate(date)];
|
|
474
|
+
});
|
|
475
|
+
}
|
|
476
|
+
|
|
477
|
+
function convertDate(date)
|
|
478
|
+
{
|
|
479
|
+
if (typeof date !== 'string') return date;
|
|
480
|
+
else if (/^\d{4}-\d{2}-\d{2}/.test(date)) // iso string date
|
|
481
|
+
return new Date(date);
|
|
482
|
+
else
|
|
483
|
+
return $lib.parseDate(date, _instance.dateFormat);
|
|
484
|
+
}
|
|
485
|
+
|
|
486
|
+
function addInput(format)
|
|
487
|
+
{
|
|
488
|
+
if (format.indexOf('d') == 0)
|
|
489
|
+
createDayInput(_instance.element);
|
|
490
|
+
if (format.indexOf('m') == 0)
|
|
491
|
+
createMonthInput(_instance.element);
|
|
492
|
+
if (format.indexOf('y') == 0)
|
|
493
|
+
createYearInput(_instance.element);
|
|
494
|
+
}
|
|
495
|
+
|
|
496
|
+
function createDayInput(container)
|
|
497
|
+
{
|
|
498
|
+
var format = _instance.dateFormat.toLowerCase(),
|
|
499
|
+
last = (format.indexOf('d') > (format.indexOf('m') + format.indexOf('y'))) ? true : false;
|
|
500
|
+
|
|
501
|
+
_dayInput = createInput(container, _instance.id + '_D', _instance.dayNumericBoxId);
|
|
502
|
+
_dayInput.id = _instance.id + '_D';
|
|
503
|
+
_dayInput.cssClass += ' ' + (_instance.cssClassDay || _classOption.DAY) + ((last) ? _classOption.LAST : '');
|
|
504
|
+
_dayInput.placeholder = _instance.dayPlaceholder || '';
|
|
505
|
+
_dayInput.maxLength = 2;
|
|
506
|
+
_dayInput.minValue = 1;
|
|
507
|
+
_dayInput.maxValue = 31;
|
|
508
|
+
_dayInput.readOnly = _instance.readOnly;
|
|
509
|
+
_dayInput.disabled = _instance.disabled;
|
|
510
|
+
_dayInput.selectOnFocus = (_instance.autoFocus) ? true : _dayInput.selectOnFocus;
|
|
511
|
+
_dayInput.showButtons = (last && $lib.isEmpty(_instance.allowedDates));
|
|
512
|
+
_dayInput.leadingZeros = hasLeadingZero('dd');
|
|
513
|
+
_dayInput.digitPadLeftValue = (_dayInput.leadingZeros) ? "00" : null;
|
|
514
|
+
_dayInput.value = (_date) ? addNil(_date.getDate(), hasLeadingZero('dd')) : '';
|
|
515
|
+
_dayInput.events.onChange.priorityAdd(dayInputChange);
|
|
516
|
+
_dayInput.events.onChanged.priorityAdd(valueChanged, [false]);
|
|
517
|
+
_dayInput.events.onIncrement.priorityAdd(incrementDay);
|
|
518
|
+
_dayInput.events.onDecrement.priorityAdd(decrementDay);
|
|
519
|
+
}
|
|
520
|
+
|
|
521
|
+
function createMonthInput(container, calendar)
|
|
522
|
+
{
|
|
523
|
+
_instance.cssClassMonth || _classOption.MONTH;
|
|
524
|
+
var id = (calendar) ? _calendarDialog.id + '_M' : _instance.id + '_M',
|
|
525
|
+
input = createInput(container, id, (calendar) ? _instance.calendarMonthNumericBoxId : _instance.monthNumericBoxId, calendar),
|
|
526
|
+
format = _instance.dateFormat.toLowerCase(),
|
|
527
|
+
last = (format.indexOf('m') > (format.indexOf('d') + format.indexOf('y'))) ? true : false;
|
|
528
|
+
|
|
529
|
+
input.id = (calendar) ? _calendarDialog.id + '_M' : _instance.id + '_M';
|
|
530
|
+
input.cssClass += ' ' + (_instance.cssClassMonth || _classOption.MONTH) + ((last) ? _classOption.LAST : '');
|
|
531
|
+
input.placeholder = _instance.monthPlaceholder || '';
|
|
532
|
+
input.maxLength = 2;
|
|
533
|
+
input.minValue = 1;
|
|
534
|
+
input.maxValue = 12;
|
|
535
|
+
input.readOnly = (!calendar && _instance.readOnly) ? true : input.readOnly;
|
|
536
|
+
input.disabled = _instance.disabled;
|
|
537
|
+
input.selectOnFocus = (_instance.autoFocus) ? true : input.selectOnFocus;
|
|
538
|
+
input.showButtons = (last && $lib.isEmpty(_instance.allowedDates));
|
|
539
|
+
input.leadingZeros = hasLeadingZero('mm');
|
|
540
|
+
input.digitPadLeftValue = (input.leadingZeros) ? "00" : null;
|
|
541
|
+
input.value = (_date) ? addNil(_date.getMonth() + 1, hasLeadingZero('mm')) : '';
|
|
542
|
+
input.events.onChanged.priorityAdd(valueChanged, [calendar]);
|
|
543
|
+
input.events.onIncrement.priorityAdd(incrementMonth.bind(_instance, calendar));
|
|
544
|
+
input.events.onDecrement.priorityAdd(decrementMonth.bind(_instance, calendar));
|
|
545
|
+
|
|
546
|
+
if (!calendar)
|
|
547
|
+
{
|
|
548
|
+
_monthInput = input;
|
|
549
|
+
_monthInput.events.onChange.priorityAdd(monthInputChange);
|
|
550
|
+
}
|
|
551
|
+
else
|
|
552
|
+
{
|
|
553
|
+
input.events.onChange.priorityAdd(moveFocus, ['m', calendar]);
|
|
554
|
+
input.showButtons = (format.indexOf('m') > format.indexOf('y')) ? true : false;
|
|
555
|
+
input.focusGroupId = _instance.id + '_C';
|
|
556
|
+
_calendarMonthInput = input;
|
|
557
|
+
}
|
|
558
|
+
}
|
|
559
|
+
|
|
560
|
+
function createYearInput(container, calendar)
|
|
561
|
+
{
|
|
562
|
+
_instance.cssClassYear || _classOption.YEAR;
|
|
563
|
+
var id = (calendar) ? _calendarDialog.id + '_Y' : _instance.id + '_Y',
|
|
564
|
+
input = createInput(container, id, (calendar) ? _instance.calendarYearNumericBoxId : _instance.yearNumericBoxId, calendar),
|
|
565
|
+
format = _instance.dateFormat.toLowerCase(),
|
|
566
|
+
last = (format.indexOf('y') > (format.indexOf('d') + format.indexOf('m'))) ? true : false;
|
|
567
|
+
|
|
568
|
+
input.cssClass += ' ' + (_instance.cssClassYear || _classOption.YEAR) + ((last) ? _classOption.LAST : '');
|
|
569
|
+
input.placeholder = _instance.yearPlaceholder || '';
|
|
570
|
+
input.maxLength = 4;
|
|
571
|
+
input.minValue = 1800;
|
|
572
|
+
input.maxValue = 9999;
|
|
573
|
+
input.readOnly = (!calendar && _instance.readOnly) ? true : input.readOnly;
|
|
574
|
+
input.disabled = _instance.disabled;
|
|
575
|
+
input.selectOnFocus = (_instance.autoFocus) ? true : input.selectOnFocus;
|
|
576
|
+
input.showButtons = (last && $lib.isEmpty(_instance.allowedDates));
|
|
577
|
+
input.value = (_date) ? _date.getFullYear() : '';
|
|
578
|
+
|
|
579
|
+
if (!calendar)
|
|
580
|
+
{
|
|
581
|
+
_yearInput = input;
|
|
582
|
+
input.events.onChange.priorityAdd(yearInputChange);
|
|
583
|
+
input.events.onIncrement.priorityAdd(yearInputChange);
|
|
584
|
+
input.events.onDecrement.priorityAdd(yearInputChange);
|
|
585
|
+
}
|
|
586
|
+
else
|
|
587
|
+
{
|
|
588
|
+
_calendarYearInput = input;
|
|
589
|
+
input.events.onChange.priorityAdd(moveFocus, ['y', calendar]);
|
|
590
|
+
input.showButtons = (format.indexOf('y') > format.indexOf('m')) ? true : false;
|
|
591
|
+
input.focusGroupId = _instance.id + '_C';
|
|
592
|
+
}
|
|
593
|
+
|
|
594
|
+
input.events.onIncrement.priorityAdd(valueChanged, [calendar]);
|
|
595
|
+
input.events.onDecrement.priorityAdd(valueChanged, [calendar]);
|
|
596
|
+
input.events.onChanged.priorityAdd(valueChanged, [calendar]);
|
|
597
|
+
}
|
|
598
|
+
|
|
599
|
+
function createInput(container, id, numericBoxId, calendar)
|
|
600
|
+
{
|
|
601
|
+
var input = $UI.createComponent(componyx.UI.NumericBox, { id: id, containerElement: container });
|
|
602
|
+
|
|
603
|
+
input.clone($UI.store[numericBoxId], _instance);
|
|
604
|
+
input.showing = true;
|
|
605
|
+
input.cssClass = input.cssClass || _instance.cssClassNumericBox || _classOption.NUMERICBOX;
|
|
606
|
+
input.focusGroupId = _instance.id;
|
|
607
|
+
input.focusableButtons = false;
|
|
608
|
+
input.events.onPostRender.priorityAdd(() => { _instance.isReady.apply(_instance); }, null);
|
|
609
|
+
|
|
610
|
+
if (!calendar && _instance.viewMode == _viewModeOption.INPUT_CALENDAR_POPUP && !_instance.disabled)
|
|
611
|
+
{
|
|
612
|
+
input.events.onClick.priorityAdd(function ()
|
|
613
|
+
{
|
|
614
|
+
_tabFocus = false;
|
|
615
|
+
showCalendar();
|
|
616
|
+
});
|
|
617
|
+
|
|
618
|
+
input.events.onFocus.priorityAdd(function ()
|
|
619
|
+
{
|
|
620
|
+
_tabFocus = true;
|
|
621
|
+
});
|
|
622
|
+
}
|
|
623
|
+
|
|
624
|
+
input.delegateFocusEvents(_instance);
|
|
625
|
+
|
|
626
|
+
return input;
|
|
627
|
+
}
|
|
628
|
+
|
|
629
|
+
function checkTabFocus(e)
|
|
630
|
+
{
|
|
631
|
+
if (_tabFocus && e.key == 'Tab')
|
|
632
|
+
showCalendar();
|
|
633
|
+
|
|
634
|
+
_tabFocus = false;
|
|
635
|
+
|
|
636
|
+
$lib.defer(function ()
|
|
637
|
+
{
|
|
638
|
+
const active = _instance.element.ownerDocument.activeElement;
|
|
639
|
+
if (!_instance.element.contains(active) && _calendarDialog)
|
|
640
|
+
{
|
|
641
|
+
_calendarDialog.hide();
|
|
642
|
+
}
|
|
643
|
+
}.bind(_instance));
|
|
644
|
+
}
|
|
645
|
+
|
|
646
|
+
function hasLeadingZero(part)
|
|
647
|
+
{
|
|
648
|
+
return _instance.dateFormat.toLowerCase().indexOf(part) > -1;
|
|
649
|
+
}
|
|
650
|
+
|
|
651
|
+
function addNil(val, leadingZero)
|
|
652
|
+
{
|
|
653
|
+
val = val.toString();
|
|
654
|
+
|
|
655
|
+
if (!leadingZero)
|
|
656
|
+
return val;
|
|
657
|
+
|
|
658
|
+
return (val.length != 2) ? '0' + val : val;
|
|
659
|
+
}
|
|
660
|
+
|
|
661
|
+
function moveFocus(type, calendar, input, args)
|
|
662
|
+
{
|
|
663
|
+
var keyCode = (args.event) ? args.event.key : null;
|
|
664
|
+
|
|
665
|
+
if (!_instance.autoFocus || !keyCode || keyCode == 'ArrowUp' || keyCode == 'ArrowDown')
|
|
666
|
+
return;
|
|
667
|
+
|
|
668
|
+
var format = _instance.dateFormat.toLowerCase(),
|
|
669
|
+
splitChar = format.match(/[^\w]/)[0];
|
|
670
|
+
|
|
671
|
+
if (calendar)
|
|
672
|
+
format = format.replace('dd', '').replace(splitChar + splitChar, splitChar);
|
|
673
|
+
|
|
674
|
+
var index = format.indexOf(type),
|
|
675
|
+
nextIndex = index + format.substr(index).indexOf(splitChar) + 1,
|
|
676
|
+
id, nextInput;
|
|
677
|
+
|
|
678
|
+
if (!nextIndex || nextIndex == index)
|
|
679
|
+
{
|
|
680
|
+
var match = format.match(new RegExp(type, "g"));
|
|
681
|
+
|
|
682
|
+
if (nextIndex == index && match && match.length == input.getValue().length) // last input is filled
|
|
683
|
+
valueChanged();
|
|
684
|
+
|
|
685
|
+
return;
|
|
686
|
+
}
|
|
687
|
+
|
|
688
|
+
id = format.substr(nextIndex, 1).toUpperCase();
|
|
689
|
+
id = (calendar) ? _calendarDialog.id + '_' + id : _instance.id + '_' + id;
|
|
690
|
+
nextInput = $UI.store[id];
|
|
691
|
+
|
|
692
|
+
if (input.getValue().length == (nextIndex - index) - 1)
|
|
693
|
+
nextInput.select();
|
|
694
|
+
}
|
|
695
|
+
|
|
696
|
+
function dayInputChange(input, args)
|
|
697
|
+
{
|
|
698
|
+
var format = _instance.dateFormat.toLowerCase(),
|
|
699
|
+
last = (format.indexOf('d') > (format.indexOf('m') + format.indexOf('y'))) ? true : false;
|
|
700
|
+
|
|
701
|
+
_day = _dayInput.getValue();
|
|
702
|
+
|
|
703
|
+
if (last)
|
|
704
|
+
setMonthEnd(true);
|
|
705
|
+
else if (validDate(_date) && parseFloat(_day) < 32 && (parseFloat(_day) > getDayCount(_date)))
|
|
706
|
+
{
|
|
707
|
+
if (format.indexOf('y') > format.indexOf('d'))
|
|
708
|
+
_yearInput.clear();
|
|
709
|
+
|
|
710
|
+
if (format.indexOf('m') > format.indexOf('d'))
|
|
711
|
+
_monthInput.clear();
|
|
712
|
+
}
|
|
713
|
+
|
|
714
|
+
moveFocus('d', false, input, args);
|
|
715
|
+
}
|
|
716
|
+
|
|
717
|
+
function monthInputChange(input, args)
|
|
718
|
+
{
|
|
719
|
+
setMonthEnd(false);
|
|
720
|
+
moveFocus('m', false, input, args);
|
|
721
|
+
}
|
|
722
|
+
|
|
723
|
+
function yearInputChange(input, args)
|
|
724
|
+
{
|
|
725
|
+
setMonthEnd(false);
|
|
726
|
+
moveFocus('y', false, input, args);
|
|
727
|
+
}
|
|
728
|
+
|
|
729
|
+
function setMonthEnd(dayChange)
|
|
730
|
+
{
|
|
731
|
+
if (_yearInput.getValue().length != 4)
|
|
732
|
+
return;
|
|
733
|
+
|
|
734
|
+
var dayCount = null, day = null; _instance.dateFormat.toLowerCase(); var digitPadLeftValue,
|
|
735
|
+
date = parseDate(_yearInput.getValue(), _monthInput.getValue(), '01');
|
|
736
|
+
|
|
737
|
+
if (!date || isNaN(date))
|
|
738
|
+
return;
|
|
739
|
+
|
|
740
|
+
dayCount = getDayCount(date);
|
|
741
|
+
day = (parseFloat(_day) > dayCount) ? dayCount : _day;
|
|
742
|
+
|
|
743
|
+
if (dayChange)
|
|
744
|
+
{
|
|
745
|
+
if (day.length == 1)
|
|
746
|
+
{
|
|
747
|
+
digitPadLeftValue = _dayInput.digitPadLeftValue;
|
|
748
|
+
_dayInput.digitPadLeftValue = null;
|
|
749
|
+
_dayInput.setValue(day);
|
|
750
|
+
_dayInput.digitPadLeftValue = digitPadLeftValue;
|
|
751
|
+
}
|
|
752
|
+
else
|
|
753
|
+
_dayInput.setValue(day);
|
|
754
|
+
}
|
|
755
|
+
else
|
|
756
|
+
{
|
|
757
|
+
day = day || 1;
|
|
758
|
+
_dayInput.setValue(day);
|
|
759
|
+
}
|
|
760
|
+
|
|
761
|
+
_day = day;
|
|
762
|
+
|
|
763
|
+
return date;
|
|
764
|
+
}
|
|
765
|
+
|
|
766
|
+
function inputKeyUp(e)
|
|
767
|
+
{
|
|
768
|
+
var keyCode = e.key,
|
|
769
|
+
hasDate = validDate(_date);
|
|
770
|
+
|
|
771
|
+
if (hasDate && (keyCode == 'Enter' || keyCode == ' ') && _calendarDialog && _calendarDialog.showing)
|
|
772
|
+
{
|
|
773
|
+
hideCalendar();
|
|
774
|
+
this.blur();
|
|
775
|
+
}
|
|
776
|
+
}
|
|
777
|
+
|
|
778
|
+
function validDate(date)
|
|
779
|
+
{
|
|
780
|
+
return (date && !isNaN(date.getTime()));
|
|
781
|
+
}
|
|
782
|
+
|
|
783
|
+
function incrementDay(input, args)
|
|
784
|
+
{
|
|
785
|
+
if (validDate(_date))
|
|
786
|
+
{
|
|
787
|
+
_date.setDate(_date.getDate() + 1);
|
|
788
|
+
_day = _date.getDate();
|
|
789
|
+
setInputs(_date);
|
|
790
|
+
}
|
|
791
|
+
|
|
792
|
+
valueChanged();
|
|
793
|
+
}
|
|
794
|
+
|
|
795
|
+
function decrementDay(input, args)
|
|
796
|
+
{
|
|
797
|
+
if (validDate(_date))
|
|
798
|
+
{
|
|
799
|
+
_date.setDate(_date.getDate() - 1);
|
|
800
|
+
_day = _date.getDate();
|
|
801
|
+
setInputs(_date);
|
|
802
|
+
|
|
803
|
+
}
|
|
804
|
+
|
|
805
|
+
valueChanged();
|
|
806
|
+
}
|
|
807
|
+
|
|
808
|
+
function incrementMonth(calendar)
|
|
809
|
+
{
|
|
810
|
+
var date = (calendar) ? _calendarDate : _date;
|
|
811
|
+
|
|
812
|
+
if (validDate(date))
|
|
813
|
+
setNextMonth(calendar);
|
|
814
|
+
|
|
815
|
+
valueChanged(calendar);
|
|
816
|
+
}
|
|
817
|
+
|
|
818
|
+
function decrementMonth(calendar)
|
|
819
|
+
{
|
|
820
|
+
var date = (calendar) ? _calendarDate : _date;
|
|
821
|
+
|
|
822
|
+
if (validDate(date))
|
|
823
|
+
setPreviousMonth(calendar);
|
|
824
|
+
|
|
825
|
+
valueChanged(calendar);
|
|
826
|
+
}
|
|
827
|
+
|
|
828
|
+
function setPreviousMonth(calendar)
|
|
829
|
+
{
|
|
830
|
+
var date = (calendar) ? _calendarDate : _date,
|
|
831
|
+
dayCount = getDayCount(new Date(date.getFullYear(), date.getMonth() - 1, 1));
|
|
832
|
+
|
|
833
|
+
if (date.getDate() > dayCount)
|
|
834
|
+
{
|
|
835
|
+
date.setDate(dayCount);
|
|
836
|
+
|
|
837
|
+
if (!calendar)
|
|
838
|
+
_day = dayCount;
|
|
839
|
+
}
|
|
840
|
+
|
|
841
|
+
date.setMonth(date.getMonth() - 1);
|
|
842
|
+
setInputs(date, calendar);
|
|
843
|
+
}
|
|
844
|
+
|
|
845
|
+
function setNextMonth(calendar)
|
|
846
|
+
{
|
|
847
|
+
var date = (calendar) ? _calendarDate : _date,
|
|
848
|
+
dayCount = getDayCount(new Date(date.getFullYear(), date.getMonth() + 1, 1));
|
|
849
|
+
|
|
850
|
+
if (date.getDate() > dayCount)
|
|
851
|
+
{
|
|
852
|
+
date.setDate(dayCount);
|
|
853
|
+
|
|
854
|
+
if (!calendar)
|
|
855
|
+
_day = dayCount;
|
|
856
|
+
}
|
|
857
|
+
|
|
858
|
+
date.setMonth(date.getMonth() + 1);
|
|
859
|
+
setInputs(date, calendar);
|
|
860
|
+
}
|
|
861
|
+
|
|
862
|
+
function setInputs(date, calendar)
|
|
863
|
+
{
|
|
864
|
+
if (calendar)
|
|
865
|
+
{
|
|
866
|
+
_calendarMonthInput.setValue(addNil(date.getMonth() + 1, hasLeadingZero('mm')));
|
|
867
|
+
_calendarYearInput.setValue(date.getFullYear());
|
|
868
|
+
}
|
|
869
|
+
else
|
|
870
|
+
{
|
|
871
|
+
_dayInput.setValue(addNil(date.getDate(), hasLeadingZero('dd')));
|
|
872
|
+
_monthInput.setValue(addNil(date.getMonth() + 1, hasLeadingZero('mm')));
|
|
873
|
+
_yearInput.setValue(date.getFullYear());
|
|
874
|
+
}
|
|
875
|
+
}
|
|
876
|
+
|
|
877
|
+
function valueChanged(calendar)
|
|
878
|
+
{
|
|
879
|
+
if (!calendar)
|
|
880
|
+
{
|
|
881
|
+
setDate(parseDate(_yearInput.getValue(), _monthInput.getValue(), _dayInput.getValue()), true, false);
|
|
882
|
+
|
|
883
|
+
if (validDate(_date))
|
|
884
|
+
showCalendar();
|
|
885
|
+
}
|
|
886
|
+
else
|
|
887
|
+
{
|
|
888
|
+
var month = _calendarMonthInput.getValue();
|
|
889
|
+
var year = _calendarYearInput.getValue();
|
|
890
|
+
if (!$lib.isEmpty(month) && !$lib.isEmpty(year))
|
|
891
|
+
{
|
|
892
|
+
_calendarDate = new Date(parseFloat(year), parseFloat(month) - 1, 1);
|
|
893
|
+
|
|
894
|
+
if (validDate(_calendarDate))
|
|
895
|
+
updateCalendar();
|
|
896
|
+
}
|
|
897
|
+
}
|
|
898
|
+
}
|
|
899
|
+
|
|
900
|
+
function parseDate(year, month, day)
|
|
901
|
+
{
|
|
902
|
+
return $lib.parseDate($lib.format('{0}/{1}/{2}', year, addNil(month, true), addNil(day, true)), 'yyyy/mm/dd');
|
|
903
|
+
}
|
|
904
|
+
|
|
905
|
+
function createPicker()
|
|
906
|
+
{
|
|
907
|
+
var id = _instance.id + '_Picker';
|
|
908
|
+
_pickerButton = $UI.createComponent(componyx.UI.Button, { id: id, containerElement: _instance.element });
|
|
909
|
+
|
|
910
|
+
_pickerButton.clone($UI.store[_instance.pickerButtonId], _instance);
|
|
911
|
+
_pickerButton.transparent = true;
|
|
912
|
+
_pickerButton.cssClass = _pickerButton.cssClass || _instance.cssClassPicker || _classOption.PICKER;
|
|
913
|
+
_pickerButton.hasIcon = true;
|
|
914
|
+
_pickerButton.events.onPostRender.priorityAdd(() => { _instance.isReady.apply(_instance); }, null);
|
|
915
|
+
_pickerButton.command = function () { toggleCalendar(); };
|
|
916
|
+
_pickerButton.type = componyx.UI.Button.TypeOption.CHECKBUTTON;
|
|
917
|
+
_pickerButton.disabled = _instance.disabled;
|
|
918
|
+
_pickerButton.delegateFocusEvents(_instance);
|
|
919
|
+
_pickerButton.showing = true;
|
|
920
|
+
}
|
|
921
|
+
|
|
922
|
+
function createCalendar()
|
|
923
|
+
{
|
|
924
|
+
var id = _instance.id + '_Dialog',
|
|
925
|
+
header = document.createElement('div'),
|
|
926
|
+
content = document.createElement('div'),
|
|
927
|
+
footer = document.createElement('div');
|
|
928
|
+
|
|
929
|
+
content.id = id + '_Content';
|
|
930
|
+
_calendarDialog = $UI.createComponent(componyx.UI.Dialog, { id: id, containerElement: _instance.element });
|
|
931
|
+
|
|
932
|
+
_calendarDialog.clone($UI.store[_instance.dialogId], _instance);
|
|
933
|
+
_calendarDialog.cssClass = _calendarDialog.cssClass || _instance.cssClassCalendar || _classOption.CALENDAR;
|
|
934
|
+
_calendarDialog.autoFit = _calendarDialog.buttons.close = _calendarDialog.buttons.confirm = _calendarDialog.buttons.deny = _calendarDialog.buttons.cancel = false;
|
|
935
|
+
_calendarDialog.events.onPostRender.priorityAdd(calendarReady, null);
|
|
936
|
+
_calendarDialog.events.onPostRender.priorityAdd(() => { _instance.isReady.apply(_instance); }, null);
|
|
937
|
+
_calendarDialog.setHeaderTemplate(header);
|
|
938
|
+
_calendarDialog.setContentTemplate(content);
|
|
939
|
+
_calendarDialog.setFooterTemplate(footer);
|
|
940
|
+
_calendarDialog.expandDirection = componyx.UI.Box.ExpandDirectionOption.DOWN;
|
|
941
|
+
|
|
942
|
+
if (isPopup())
|
|
943
|
+
{
|
|
944
|
+
_calendarDialog.expander = _instance.id;
|
|
945
|
+
_calendarDialog.autoPosition = componyx.UI.Box.AutoPositionOption.EXPAND;
|
|
946
|
+
_calendarDialog.autoInvertFit = _calendarDialog.autoFit = true;
|
|
947
|
+
_calendarDialog.events.onHideComplete.priorityAdd(function () { _pickerButton.deselect(); }, null);
|
|
948
|
+
_calendarDialog.hideOnOutsideClick = true;
|
|
949
|
+
}
|
|
950
|
+
else
|
|
951
|
+
{
|
|
952
|
+
_calendarDialog.autoPosition = componyx.UI.Box.AutoPositionOption.NONE;
|
|
953
|
+
_calendarDialog.showing = true;
|
|
954
|
+
}
|
|
955
|
+
|
|
956
|
+
function calendarReady()
|
|
957
|
+
{
|
|
958
|
+
createHeader();
|
|
959
|
+
createContent();
|
|
960
|
+
createFooter();
|
|
961
|
+
}
|
|
962
|
+
|
|
963
|
+
function createHeader()
|
|
964
|
+
{
|
|
965
|
+
var button = createButton(_calendarDialog.id + '_Prev'),
|
|
966
|
+
label = document.createElement('span');
|
|
967
|
+
|
|
968
|
+
button.id = _calendarDialog.id + '_Prev';
|
|
969
|
+
button.cssClass = _instance.cssClassPrevMonth || _classOption.PREVMONTH;
|
|
970
|
+
button.command = function () { prevMonth(); };
|
|
971
|
+
button.delegateFocusEvents(_instance);
|
|
972
|
+
|
|
973
|
+
button = createButton(_calendarDialog.id + '_Next');
|
|
974
|
+
button.id = _calendarDialog.id + '_Next';
|
|
975
|
+
button.cssClass = _instance.cssClassNextMonth || _classOption.NEXTMONTH;
|
|
976
|
+
button.command = function () { nextMonth(); };
|
|
977
|
+
button.delegateFocusEvents(_instance);
|
|
978
|
+
|
|
979
|
+
label.id = _calendarDialog.id + '_HeaderLabel';
|
|
980
|
+
label.className = _instance.cssClassHeaderLabel || _classOption.HEADERLABEL;
|
|
981
|
+
header.appendChild(label);
|
|
982
|
+
}
|
|
983
|
+
|
|
984
|
+
function createButton(id)
|
|
985
|
+
{
|
|
986
|
+
var button = $UI.createComponent(componyx.UI.Button, { id: id, containerElement: header });
|
|
987
|
+
|
|
988
|
+
button.clone(null, _instance);
|
|
989
|
+
button.showing = true;
|
|
990
|
+
button.hasIcon = true;
|
|
991
|
+
button.transparent = true;
|
|
992
|
+
button.events.onPostRender.priorityAdd(() => { _instance.isReady.apply(_instance); }, null);
|
|
993
|
+
|
|
994
|
+
return button;
|
|
995
|
+
}
|
|
996
|
+
|
|
997
|
+
function createContent()
|
|
998
|
+
{
|
|
999
|
+
var table = document.createElement('table'),
|
|
1000
|
+
rowIndex = 0, columnIndex = 0,
|
|
1001
|
+
cell = null, row = null;
|
|
1002
|
+
|
|
1003
|
+
content.appendChild(table);
|
|
1004
|
+
drawHeader(table);
|
|
1005
|
+
|
|
1006
|
+
for (; rowIndex < 6; ++rowIndex)
|
|
1007
|
+
{
|
|
1008
|
+
row = table.insertRow(-1);
|
|
1009
|
+
|
|
1010
|
+
if (_instance.weekNumbers)
|
|
1011
|
+
{
|
|
1012
|
+
cell = row.insertCell(-1);
|
|
1013
|
+
$lib.addClass(cell, _instance.cssClassWeekNumber || _classOption.WEEKNUMBER);
|
|
1014
|
+
}
|
|
1015
|
+
|
|
1016
|
+
for (columnIndex = 0; columnIndex < 7; columnIndex++)
|
|
1017
|
+
{
|
|
1018
|
+
cell = row.insertCell(-1);
|
|
1019
|
+
}
|
|
1020
|
+
}
|
|
1021
|
+
}
|
|
1022
|
+
|
|
1023
|
+
function drawHeader(table)
|
|
1024
|
+
{
|
|
1025
|
+
var row = null, cell = null, index = 0;
|
|
1026
|
+
|
|
1027
|
+
row = table.insertRow(-1);
|
|
1028
|
+
|
|
1029
|
+
if (_instance.weekNumbers)
|
|
1030
|
+
{
|
|
1031
|
+
cell = document.createElement('th');
|
|
1032
|
+
$lib.addClass(cell, _instance.cssClassWeekNumber || _classOption.WEEKNUMBER);
|
|
1033
|
+
row.appendChild(cell);
|
|
1034
|
+
}
|
|
1035
|
+
|
|
1036
|
+
for (; index < 7; index++)
|
|
1037
|
+
{
|
|
1038
|
+
cell = document.createElement('th');
|
|
1039
|
+
cell.innerHTML = _instance.days[index];
|
|
1040
|
+
$lib.addClass(cell, _instance.cssClassDay || _classOption.DAY);
|
|
1041
|
+
row.appendChild(cell);
|
|
1042
|
+
}
|
|
1043
|
+
}
|
|
1044
|
+
|
|
1045
|
+
function createFooter()
|
|
1046
|
+
{
|
|
1047
|
+
var format = _instance.dateFormat.toLowerCase();
|
|
1048
|
+
|
|
1049
|
+
if (format.indexOf('m') < format.indexOf('y'))
|
|
1050
|
+
{
|
|
1051
|
+
createMonthInput(footer, true);
|
|
1052
|
+
createYearInput(footer, true);
|
|
1053
|
+
}
|
|
1054
|
+
else
|
|
1055
|
+
{
|
|
1056
|
+
createYearInput(footer, true);
|
|
1057
|
+
createMonthInput(footer, true);
|
|
1058
|
+
}
|
|
1059
|
+
}
|
|
1060
|
+
}
|
|
1061
|
+
|
|
1062
|
+
function prevMonth()
|
|
1063
|
+
{
|
|
1064
|
+
setPreviousMonth(true);
|
|
1065
|
+
updateCalendar();
|
|
1066
|
+
}
|
|
1067
|
+
|
|
1068
|
+
function nextMonth()
|
|
1069
|
+
{
|
|
1070
|
+
setNextMonth(true);
|
|
1071
|
+
updateCalendar();
|
|
1072
|
+
}
|
|
1073
|
+
|
|
1074
|
+
function toggleCalendar()
|
|
1075
|
+
{
|
|
1076
|
+
if (!_calendarDialog.showing)
|
|
1077
|
+
showCalendar(true); // allow focus by tab on calendar elements
|
|
1078
|
+
else
|
|
1079
|
+
_calendarDialog.hide();
|
|
1080
|
+
}
|
|
1081
|
+
|
|
1082
|
+
function showCalendar(allowFocusInside = false)
|
|
1083
|
+
{
|
|
1084
|
+
if (!_calendarDialog)
|
|
1085
|
+
return;
|
|
1086
|
+
|
|
1087
|
+
var hasCalendarDate = validDate(_calendarDate),
|
|
1088
|
+
hasDate = validDate(_date),
|
|
1089
|
+
date = _date || _today;
|
|
1090
|
+
|
|
1091
|
+
if (_pickerButton)
|
|
1092
|
+
_pickerButton.select();
|
|
1093
|
+
|
|
1094
|
+
if (!isPopup())
|
|
1095
|
+
allowFocusInside = true;
|
|
1096
|
+
|
|
1097
|
+
if (!hasCalendarDate || !hasDate || !isPopup())
|
|
1098
|
+
{
|
|
1099
|
+
_calendarDate = new Date(date.getFullYear(), date.getMonth(), 1);
|
|
1100
|
+
updateCalendar();
|
|
1101
|
+
_calendarDialog.show();
|
|
1102
|
+
}
|
|
1103
|
+
else
|
|
1104
|
+
{
|
|
1105
|
+
if (_calendarDate.getMonth() === date.getMonth() && _calendarDate.getFullYear() === date.getFullYear()) // different day
|
|
1106
|
+
{
|
|
1107
|
+
var day = addNil(1, _instance.calendarDayLeadingZero),
|
|
1108
|
+
firstDayIndex = $lib.indexOf(_dayButtons, function (button) { return (button.text === day); });
|
|
1109
|
+
|
|
1110
|
+
_dayButtons[((date.getDate() - 1) + firstDayIndex)].select();
|
|
1111
|
+
_calendarDialog.show();
|
|
1112
|
+
}
|
|
1113
|
+
else // different year or month
|
|
1114
|
+
{
|
|
1115
|
+
_calendarDate = new Date(date.getFullYear(), date.getMonth(), 1);
|
|
1116
|
+
updateCalendar();
|
|
1117
|
+
_calendarDialog.show();
|
|
1118
|
+
}
|
|
1119
|
+
}
|
|
1120
|
+
|
|
1121
|
+
const focusableEls = _calendarDialog.element.querySelectorAll('input, a');
|
|
1122
|
+
|
|
1123
|
+
focusableEls.forEach(el =>
|
|
1124
|
+
{
|
|
1125
|
+
if (allowFocusInside)
|
|
1126
|
+
{
|
|
1127
|
+
el.setAttribute('tabindex', '0');
|
|
1128
|
+
}
|
|
1129
|
+
else
|
|
1130
|
+
{
|
|
1131
|
+
el.setAttribute('tabindex', '-1');
|
|
1132
|
+
}
|
|
1133
|
+
});
|
|
1134
|
+
}
|
|
1135
|
+
|
|
1136
|
+
function hideCalendar()
|
|
1137
|
+
{
|
|
1138
|
+
_calendarDialog.hide();
|
|
1139
|
+
}
|
|
1140
|
+
|
|
1141
|
+
function updateCalendar()
|
|
1142
|
+
{
|
|
1143
|
+
updateHeader();
|
|
1144
|
+
updateFooter();
|
|
1145
|
+
drawMonth();
|
|
1146
|
+
|
|
1147
|
+
function updateHeader()
|
|
1148
|
+
{
|
|
1149
|
+
var label = $lib($lib.format('#{0}_HeaderLabel', _calendarDialog.id)),
|
|
1150
|
+
month = document.createElement('span'), year = document.createElement('span'),
|
|
1151
|
+
format = _instance.dateFormat.toLowerCase();
|
|
1152
|
+
|
|
1153
|
+
month.className = _instance.cssClassMonth || _classOption.MONTH;
|
|
1154
|
+
month.innerHTML = _instance.months[_calendarDate.getMonth()];
|
|
1155
|
+
year.className = _instance.cssClassYear || _classOption.YEAR;
|
|
1156
|
+
year.innerHTML = _calendarDate.getFullYear();
|
|
1157
|
+
|
|
1158
|
+
label.innerHTML = '';
|
|
1159
|
+
|
|
1160
|
+
if (format.indexOf('m') < format.indexOf('y'))
|
|
1161
|
+
{
|
|
1162
|
+
label.appendChild(month);
|
|
1163
|
+
label.appendChild(year);
|
|
1164
|
+
}
|
|
1165
|
+
else
|
|
1166
|
+
{
|
|
1167
|
+
label.appendChild(year);
|
|
1168
|
+
label.appendChild(month);
|
|
1169
|
+
}
|
|
1170
|
+
}
|
|
1171
|
+
|
|
1172
|
+
function updateFooter()
|
|
1173
|
+
{
|
|
1174
|
+
_calendarMonthInput.events.onChange.disable(true);
|
|
1175
|
+
_calendarMonthInput.events.onChanged.disable(true);
|
|
1176
|
+
_calendarYearInput.events.onChange.disable(true);
|
|
1177
|
+
_calendarYearInput.events.onChanged.disable(true);
|
|
1178
|
+
|
|
1179
|
+
_calendarMonthInput.setValue(addNil(_calendarDate.getMonth() + 1, hasLeadingZero('mm')));
|
|
1180
|
+
_calendarYearInput.setValue(_calendarDate.getFullYear());
|
|
1181
|
+
|
|
1182
|
+
_calendarMonthInput.events.onChange.enable(true);
|
|
1183
|
+
_calendarMonthInput.events.onChanged.enable(true);
|
|
1184
|
+
_calendarYearInput.events.onChange.enable(true);
|
|
1185
|
+
_calendarYearInput.events.onChanged.enable(true);
|
|
1186
|
+
}
|
|
1187
|
+
|
|
1188
|
+
function drawMonth()
|
|
1189
|
+
{
|
|
1190
|
+
var content = $lib($lib.format('#{0}_Content', _calendarDialog.id)),
|
|
1191
|
+
rowIndex = 0, columnIndex = 0, columnStart = 0,
|
|
1192
|
+
date = new Date(_calendarDate.getFullYear(), _calendarDate.getMonth(), 1),
|
|
1193
|
+
prevRemainder = date.getDay() - _instance.firstDayOfWeek,
|
|
1194
|
+
table = $lib(null, content, 'table', true),
|
|
1195
|
+
index = 0;
|
|
1196
|
+
|
|
1197
|
+
if (prevRemainder < 0)
|
|
1198
|
+
prevRemainder += 7;
|
|
1199
|
+
|
|
1200
|
+
for (rowIndex = 0; rowIndex < 6; ++rowIndex)
|
|
1201
|
+
{
|
|
1202
|
+
var row = $lib(null, table, 'tr')[rowIndex + 1];
|
|
1203
|
+
|
|
1204
|
+
columnStart = 0;
|
|
1205
|
+
row.className = '';
|
|
1206
|
+
if (rowIndex == 0 && prevRemainder > 0)
|
|
1207
|
+
date.setDate(date.getDate() - prevRemainder);
|
|
1208
|
+
|
|
1209
|
+
_instance.events.onCalendarWeekRender.fire(_instance, { row: row, date: new Date(date) });
|
|
1210
|
+
|
|
1211
|
+
if (_instance.weekNumbers)
|
|
1212
|
+
{
|
|
1213
|
+
var cell = $lib(null, row, 'td')[0];
|
|
1214
|
+
cell.innerHTML = $lib.getWeekNumber(date, _instance.firstDayOfWeek);
|
|
1215
|
+
}
|
|
1216
|
+
|
|
1217
|
+
while (prevRemainder > 0)
|
|
1218
|
+
{
|
|
1219
|
+
drawDay(row, date, index++);
|
|
1220
|
+
prevRemainder--;
|
|
1221
|
+
columnStart++;
|
|
1222
|
+
}
|
|
1223
|
+
|
|
1224
|
+
for (columnIndex = columnStart; columnIndex < 7; columnIndex++)
|
|
1225
|
+
{
|
|
1226
|
+
drawDay(row, date, index++);
|
|
1227
|
+
}
|
|
1228
|
+
}
|
|
1229
|
+
|
|
1230
|
+
function drawDay(row, date, index)
|
|
1231
|
+
{
|
|
1232
|
+
var cell = $lib(null, row, 'td')[(_instance.weekNumbers) ? (index % 7) + 1 : (index % 7)],
|
|
1233
|
+
container = document.createElement('div'),
|
|
1234
|
+
year = date.getFullYear(), month = date.getMonth(), day = date.getDate(),
|
|
1235
|
+
button = null;
|
|
1236
|
+
|
|
1237
|
+
cell.className = '';
|
|
1238
|
+
$lib.addClass(cell, _instance.cssClassDay || _classOption.DAY);
|
|
1239
|
+
|
|
1240
|
+
if (comparableDate(date) == comparableDate(_today))
|
|
1241
|
+
{
|
|
1242
|
+
$lib.addClass(row, _instance.cssClassCurrentWeek || _classOption.CURRENTWEEK);
|
|
1243
|
+
$lib.addClass(cell, _instance.cssClassToday || _classOption.TODAY);
|
|
1244
|
+
}
|
|
1245
|
+
|
|
1246
|
+
if (date.getMonth() != _calendarDate.getMonth())
|
|
1247
|
+
$lib.addClass(cell, _instance.cssClassInactive || _classOption.INACTIVE);
|
|
1248
|
+
|
|
1249
|
+
if (_dayButtons[index])
|
|
1250
|
+
{
|
|
1251
|
+
button = _dayButtons[index];
|
|
1252
|
+
button.deselect();
|
|
1253
|
+
button.command = function () { selectDay(year, month, day); };
|
|
1254
|
+
button.text = addNil(day, _instance.calendarDayLeadingZero);
|
|
1255
|
+
button.updateContent();
|
|
1256
|
+
}
|
|
1257
|
+
else
|
|
1258
|
+
{
|
|
1259
|
+
cell.appendChild(container);
|
|
1260
|
+
|
|
1261
|
+
_dayButtons[index] = button = $UI.createComponent(componyx.UI.Button, { id: $lib.format('{0}_{1}', _instance.id, index), containerElement: container });
|
|
1262
|
+
|
|
1263
|
+
button.clone(null, _instance);
|
|
1264
|
+
button.containerElement = container;
|
|
1265
|
+
button.renderId = false;
|
|
1266
|
+
button.transparent = true;
|
|
1267
|
+
button.text = addNil(day, _instance.calendarDayLeadingZero);
|
|
1268
|
+
button.type = componyx.UI.Button.TypeOption.RADIOBUTTON;
|
|
1269
|
+
button.radioGroupId = _instance.id;
|
|
1270
|
+
button.command = function () { selectDay(year, month, day); };
|
|
1271
|
+
button.selected = false;
|
|
1272
|
+
button.delegateFocusEvents(_instance);
|
|
1273
|
+
button.show();
|
|
1274
|
+
}
|
|
1275
|
+
|
|
1276
|
+
if (!isAllowedDate(date))
|
|
1277
|
+
button.disable();
|
|
1278
|
+
else
|
|
1279
|
+
button.enable();
|
|
1280
|
+
|
|
1281
|
+
if (_date && comparableDate(date) == comparableDate(_date))
|
|
1282
|
+
button.select();
|
|
1283
|
+
|
|
1284
|
+
_instance.events.onCalendarDayRender.fire(_instance, { row: row, cell: cell, button: button, date: new Date(date) });
|
|
1285
|
+
date.setDate(date.getDate() + 1);
|
|
1286
|
+
}
|
|
1287
|
+
}
|
|
1288
|
+
}
|
|
1289
|
+
|
|
1290
|
+
function isAllowedDate(date)
|
|
1291
|
+
{
|
|
1292
|
+
var minDate = _instance.minValue,
|
|
1293
|
+
maxDate = _instance.maxValue,
|
|
1294
|
+
dates = _instance.allowedDates,
|
|
1295
|
+
time = date.getTime();
|
|
1296
|
+
|
|
1297
|
+
if (minDate && time < minDate.getTime())
|
|
1298
|
+
return false;
|
|
1299
|
+
else if (maxDate && time > maxDate.getTime())
|
|
1300
|
+
return false;
|
|
1301
|
+
else if (!$lib.isEmpty(dates))
|
|
1302
|
+
{
|
|
1303
|
+
var val = dates[$lib.indexOf(dates, function (item)
|
|
1304
|
+
{
|
|
1305
|
+
if (item.length == 1)
|
|
1306
|
+
return (item[0].getTime() === time);
|
|
1307
|
+
else // min-max
|
|
1308
|
+
return (time > item[0].getTime() && time < item[1].getTime());
|
|
1309
|
+
})];
|
|
1310
|
+
|
|
1311
|
+
if ((val && _instance.disallowDates) || (!val && !_instance.disallowDates))
|
|
1312
|
+
return false;
|
|
1313
|
+
}
|
|
1314
|
+
|
|
1315
|
+
return true;
|
|
1316
|
+
}
|
|
1317
|
+
|
|
1318
|
+
function comparableDate(date)
|
|
1319
|
+
{
|
|
1320
|
+
return parseInt(date.getFullYear() + addNil(date.getMonth(), true) + addNil(date.getDate(), true), 10);
|
|
1321
|
+
}
|
|
1322
|
+
|
|
1323
|
+
function selectDay(year, month, day)
|
|
1324
|
+
{
|
|
1325
|
+
_date = new Date(year, month, day);
|
|
1326
|
+
_day = _date.getDate();
|
|
1327
|
+
|
|
1328
|
+
if (!isPopup())
|
|
1329
|
+
_calendarDate = new Date(year, month, day);
|
|
1330
|
+
|
|
1331
|
+
if (_pickerButton)
|
|
1332
|
+
_pickerButton.focus();
|
|
1333
|
+
|
|
1334
|
+
setDate(_date);
|
|
1335
|
+
|
|
1336
|
+
if (isPopup())
|
|
1337
|
+
_calendarDialog.hide();
|
|
1338
|
+
}
|
|
1339
|
+
|
|
1340
|
+
function toggleEvents(enable)
|
|
1341
|
+
{
|
|
1342
|
+
if (enable)
|
|
1343
|
+
{
|
|
1344
|
+
_yearInput.events.onChange.enable(true);
|
|
1345
|
+
_yearInput.events.onChanged.enable(true);
|
|
1346
|
+
_monthInput.events.onChange.enable(true);
|
|
1347
|
+
_monthInput.events.onChanged.enable(true);
|
|
1348
|
+
_dayInput.events.onChange.enable(true);
|
|
1349
|
+
_dayInput.events.onChanged.enable(true);
|
|
1350
|
+
}
|
|
1351
|
+
else
|
|
1352
|
+
{
|
|
1353
|
+
_yearInput.events.onChange.disable(true);
|
|
1354
|
+
_yearInput.events.onChanged.disable(true);
|
|
1355
|
+
_monthInput.events.onChange.disable(true);
|
|
1356
|
+
_monthInput.events.onChanged.disable(true);
|
|
1357
|
+
_dayInput.events.onChange.disable(true);
|
|
1358
|
+
_dayInput.events.onChanged.disable(true);
|
|
1359
|
+
}
|
|
1360
|
+
}
|
|
1361
|
+
|
|
1362
|
+
function getDayCount(date)
|
|
1363
|
+
{
|
|
1364
|
+
var month = date.getMonth();
|
|
1365
|
+
|
|
1366
|
+
if (month == 1)
|
|
1367
|
+
{
|
|
1368
|
+
if ($lib.isLeapYear(date.getFullYear()))
|
|
1369
|
+
return 29;
|
|
1370
|
+
else
|
|
1371
|
+
return 28;
|
|
1372
|
+
}
|
|
1373
|
+
else if (month == 3 || month == 5 || month == 8 || month == 10)
|
|
1374
|
+
return 30;
|
|
1375
|
+
else
|
|
1376
|
+
return 31;
|
|
1377
|
+
}
|
|
1378
|
+
|
|
1379
|
+
function reset(fireEvent)
|
|
1380
|
+
{
|
|
1381
|
+
var value = (_instance.value) ? _instance.value : (_instance.today) ? _today : null;
|
|
1382
|
+
|
|
1383
|
+
if (!value)
|
|
1384
|
+
clear(fireEvent);
|
|
1385
|
+
else
|
|
1386
|
+
setDate(value, fireEvent);
|
|
1387
|
+
}
|
|
1388
|
+
|
|
1389
|
+
function clear(fireEvent)
|
|
1390
|
+
{
|
|
1391
|
+
setDate(null, fireEvent);
|
|
1392
|
+
}
|
|
1393
|
+
|
|
1394
|
+
function select()
|
|
1395
|
+
{
|
|
1396
|
+
var input = $lib(null, _instance.element, 'input')[0];
|
|
1397
|
+
input.select();
|
|
1398
|
+
}
|
|
1399
|
+
|
|
1400
|
+
function getDate()
|
|
1401
|
+
{
|
|
1402
|
+
return _date;
|
|
1403
|
+
}
|
|
1404
|
+
|
|
1405
|
+
function setDate(date, fireEvent, allowClearance)
|
|
1406
|
+
{
|
|
1407
|
+
var minDate = _instance.minValue,
|
|
1408
|
+
maxDate = _instance.maxValue,
|
|
1409
|
+
prevValue = _hidden.value,
|
|
1410
|
+
hasInputs = (_instance.viewMode < _viewModeOption.CALENDAR);
|
|
1411
|
+
|
|
1412
|
+
if (hasInputs)
|
|
1413
|
+
toggleEvents();
|
|
1414
|
+
|
|
1415
|
+
if (date)
|
|
1416
|
+
{
|
|
1417
|
+
_date = (typeof (date) == 'string') ? convertDate(date) : createNewDate(date);
|
|
1418
|
+
|
|
1419
|
+
if (minDate && _date.getTime() < minDate.getTime())
|
|
1420
|
+
_date = createNewDate(minDate);
|
|
1421
|
+
else if (maxDate && _date.getTime() > maxDate.getTime())
|
|
1422
|
+
_date = createNewDate(maxDate);
|
|
1423
|
+
|
|
1424
|
+
if (hasInputs)
|
|
1425
|
+
{
|
|
1426
|
+
_yearInput.setValue(_date.getFullYear());
|
|
1427
|
+
_monthInput.setValue(addNil(_date.getMonth() + 1, hasLeadingZero('mm')));
|
|
1428
|
+
_dayInput.setValue(addNil(_date.getDate(), hasLeadingZero('dd')));
|
|
1429
|
+
}
|
|
1430
|
+
}
|
|
1431
|
+
else
|
|
1432
|
+
{
|
|
1433
|
+
_date = null;
|
|
1434
|
+
|
|
1435
|
+
if (allowClearance != false && hasInputs)
|
|
1436
|
+
{
|
|
1437
|
+
_yearInput.setValue('');
|
|
1438
|
+
_monthInput.setValue('');
|
|
1439
|
+
_dayInput.setValue('');
|
|
1440
|
+
}
|
|
1441
|
+
}
|
|
1442
|
+
|
|
1443
|
+
if (hasInputs)
|
|
1444
|
+
toggleEvents(true);
|
|
1445
|
+
|
|
1446
|
+
setValue();
|
|
1447
|
+
|
|
1448
|
+
if (fireEvent != false && prevValue != _hidden.value)
|
|
1449
|
+
_instance.events.onChanged.fire(_instance, { date: _date });
|
|
1450
|
+
}
|
|
1451
|
+
|
|
1452
|
+
function createNewDate(date)
|
|
1453
|
+
{
|
|
1454
|
+
return new Date(date.getFullYear(), date.getMonth(), date.getDate());
|
|
1455
|
+
}
|
|
1456
|
+
|
|
1457
|
+
function getValue()
|
|
1458
|
+
{
|
|
1459
|
+
return _hidden.value;
|
|
1460
|
+
}
|
|
1461
|
+
|
|
1462
|
+
function setValue()
|
|
1463
|
+
{
|
|
1464
|
+
var format = _instance.dateFormat.toLowerCase();
|
|
1465
|
+
|
|
1466
|
+
if (validDate(_date))
|
|
1467
|
+
{
|
|
1468
|
+
var val = format;
|
|
1469
|
+
|
|
1470
|
+
val = val.replace('yyyy', _date.getFullYear());
|
|
1471
|
+
val = (format.indexOf('mm') > -1) ? val.replace('mm', addNil(_date.getMonth() + 1, true)) : val.replace('m', _date.getMonth() + 1);
|
|
1472
|
+
val = (format.indexOf('dd') > -1) ? val.replace('dd', addNil(_date.getDate(), true)) : val.replace('d', _date.getDate());
|
|
1473
|
+
_hidden.__setValue(val);
|
|
1474
|
+
}
|
|
1475
|
+
else
|
|
1476
|
+
_hidden.__setValue('');
|
|
1477
|
+
}
|
|
1478
|
+
|
|
1479
|
+
function isPopup()
|
|
1480
|
+
{
|
|
1481
|
+
var v = _instance.viewMode;
|
|
1482
|
+
return (v == _viewModeOption.INPUT_CALENDAR_POPUP || v == _viewModeOption.CALENDAR_POPUP)
|
|
1483
|
+
}
|
|
1484
|
+
|
|
1485
|
+
function dispose()
|
|
1486
|
+
{
|
|
1487
|
+
_dayButtons = [];
|
|
1488
|
+
_pickerButton = null;
|
|
1489
|
+
_calendarDialog = null;
|
|
1490
|
+
_calendarDate = null;
|
|
1491
|
+
_date = null;
|
|
1492
|
+
$lib.off(window, 'keyup', checkTabFocus);
|
|
1493
|
+
}
|
|
1494
|
+
};
|
|
1495
|
+
|
|
1496
|
+
/**
|
|
1497
|
+
* @see {@link componyx.UI.base.methods}
|
|
1498
|
+
*/
|
|
1499
|
+
componyx.UI.DatePicker.prototype = Object.create($base.methods);
|
|
1500
|
+
componyx.UI.DatePicker.prototype.constructor = componyx.UI.DatePicker;
|
|
1501
|
+
|
|
1502
|
+
/**
|
|
1503
|
+
* FirstDayOfWeekOption
|
|
1504
|
+
* @readonly
|
|
1505
|
+
* @enum {number}
|
|
1506
|
+
*/
|
|
1507
|
+
componyx.UI.DatePicker.FirstDayOfWeekOption =
|
|
1508
|
+
{
|
|
1509
|
+
SUNDAY: 0,
|
|
1510
|
+
MONDAY: 1,
|
|
1511
|
+
SATURDAY: 6
|
|
1512
|
+
};
|
|
1513
|
+
|
|
1514
|
+
/**
|
|
1515
|
+
* ViewModeOption
|
|
1516
|
+
* @readonly
|
|
1517
|
+
* @enum {number}
|
|
1518
|
+
*/
|
|
1519
|
+
componyx.UI.DatePicker.ViewModeOption =
|
|
1520
|
+
{
|
|
1521
|
+
INPUT_CALENDAR_POPUP: 0,
|
|
1522
|
+
INPUT_CALENDAR_STATIC: 1,
|
|
1523
|
+
INPUT: 2,
|
|
1524
|
+
CALENDAR: 3,
|
|
1525
|
+
CALENDAR_POPUP: 4
|
|
1526
|
+
};
|
|
1527
|
+
})(window);
|
|
1528
|
+
|
|
1529
|
+
const DatePicker = componyx.UI.DatePicker;
|
|
1530
|
+
|
|
1531
|
+
export { DatePicker };
|