nice-elements 1.12.9 → 1.12.11
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/.vscode/settings.json +18 -18
- package/CHANGELOG.md +585 -573
- package/LICENSE.md +21 -21
- package/README.md +102 -102
- package/bower.json +17 -17
- package/dist/nice.js +9187 -11517
- package/dist/nice.min.js +1 -1
- package/dist/style.css +12 -12
- package/dist/style.css.map +1 -1
- package/dist/style.min.css +8 -8
- package/eslint.config.mjs +32 -32
- package/package.json +44 -44
- package/src/components/nice-alert/nice-alert.html +6 -6
- package/src/components/nice-alert/nice-alert.js +29 -29
- package/src/components/nice-alert/nice-alert.scss +59 -59
- package/src/components/nice-avatar/nice-avatar.js +122 -122
- package/src/components/nice-avatar/nice-avatar.scss +4 -4
- package/src/components/nice-button/nice-button.html +4 -4
- package/src/components/nice-button/nice-button.js +41 -41
- package/src/components/nice-button/nice-button.scss +16 -16
- package/src/components/nice-button-toggle/nice-button-toggle.html +9 -9
- package/src/components/nice-button-toggle/nice-button-toggle.js +23 -23
- package/src/components/nice-button-toggle/nice-button-toggle.scss +2 -2
- package/src/components/nice-calendar/nice-calendar.html +91 -91
- package/src/components/nice-calendar/nice-calendar.js +346 -346
- package/src/components/nice-calendar/nice-calendar.scss +288 -288
- package/src/components/nice-checkbox/nice-checkbox.html +20 -9
- package/src/components/nice-checkbox/nice-checkbox.js +38 -37
- package/src/components/nice-checkbox/nice-checkbox.scss +120 -120
- package/src/components/nice-choice/nice-choice.html +18 -18
- package/src/components/nice-choice/nice-choice.js +211 -211
- package/src/components/nice-choice/nice-choice.scss +110 -110
- package/src/components/nice-comment/nice-comment.html +10 -10
- package/src/components/nice-comment/nice-comment.js +71 -71
- package/src/components/nice-comment/nice-comment.scss +39 -39
- package/src/components/nice-date/nice-date.html +82 -82
- package/src/components/nice-date/nice-date.js +350 -350
- package/src/components/nice-date/nice-date.scss +305 -305
- package/src/components/nice-date-input/nice-date-input.html +56 -56
- package/src/components/nice-date-input/nice-date-input.js +143 -143
- package/src/components/nice-date-input/nice-date-input.scss +55 -55
- package/src/components/nice-date-range/nice-date-range.html +15 -15
- package/src/components/nice-date-range/nice-date-range.js +78 -78
- package/src/components/nice-date-range/nice-date-range.scss +390 -390
- package/src/components/nice-datetime-picker/nice-datetime-picker.html +29 -29
- package/src/components/nice-datetime-picker/nice-datetime-picker.js +89 -89
- package/src/components/nice-datetime-picker/nice-datetime-picker.scss +428 -428
- package/src/components/nice-datetimerange-picker/nice-datetimerange-picker.html +55 -55
- package/src/components/nice-datetimerange-picker/nice-datetimerange-picker.js +248 -248
- package/src/components/nice-datetimerange-picker/nice-datetimerange-picker.scss +73 -73
- package/src/components/nice-datetimerange-picker-2/nice-datetimerange-picker-2.html +44 -44
- package/src/components/nice-datetimerange-picker-2/nice-datetimerange-picker-2.js +175 -175
- package/src/components/nice-datetimerange-picker-2/nice-datetimerange-picker-2.scss +127 -127
- package/src/components/nice-dropdown/nice-dropdown.html +61 -61
- package/src/components/nice-dropdown/nice-dropdown.js +517 -517
- package/src/components/nice-dropdown/nice-dropdown.scss +262 -262
- package/src/components/nice-dropdown-date/nice-dropdown-date.html +28 -28
- package/src/components/nice-dropdown-date/nice-dropdown-date.js +132 -132
- package/src/components/nice-dropdown-date/nice-dropdown-date.scss +87 -87
- package/src/components/nice-dropdown-old/nice-dropdown-old.html +44 -44
- package/src/components/nice-dropdown-old/nice-dropdown-old.js +330 -330
- package/src/components/nice-dropdown-old/nice-dropdown-old.scss +129 -129
- package/src/components/nice-dtp/nice-dtp.html +91 -91
- package/src/components/nice-dtp/nice-dtp.js +835 -835
- package/src/components/nice-help/nice-help.html +6 -6
- package/src/components/nice-help/nice-help.js +58 -58
- package/src/components/nice-help/nice-help.scss +78 -78
- package/src/components/nice-input/nice-input.html +47 -47
- package/src/components/nice-input/nice-input.js +251 -251
- package/src/components/nice-input/nice-input.scss +130 -130
- package/src/components/nice-label/nice-label.html +10 -10
- package/src/components/nice-label/nice-label.js +32 -32
- package/src/components/nice-loader/nice-loader.html +6 -6
- package/src/components/nice-loader/nice-loader.js +28 -28
- package/src/components/nice-loader/nice-loader.scss +47 -47
- package/src/components/nice-no-data/nice-no-data.html +3 -3
- package/src/components/nice-no-data/nice-no-data.js +27 -27
- package/src/components/nice-no-data/nice-no-data.scss +26 -26
- package/src/components/nice-notification/nice-notification.html +3 -3
- package/src/components/nice-notification/nice-notification.js +124 -124
- package/src/components/nice-notification/nice-notification.scss +66 -66
- package/src/components/nice-number/nice-number.html +40 -40
- package/src/components/nice-number/nice-number.js +172 -172
- package/src/components/nice-number/nice-number.scss +18 -18
- package/src/components/nice-on-scroll/nice-on-scroll.js +17 -17
- package/src/components/nice-percent/nice-percent.html +24 -24
- package/src/components/nice-percent/nice-percent.js +95 -95
- package/src/components/nice-pill/nice-pill.html +3 -3
- package/src/components/nice-pill/nice-pill.js +29 -29
- package/src/components/nice-pill/nice-pill.scss +25 -25
- package/src/components/nice-popup/nice-popup.html +6 -6
- package/src/components/nice-popup/nice-popup.js +122 -122
- package/src/components/nice-popup/nice-popup.scss +43 -43
- package/src/components/nice-progress-bar/nice-progress-bar.html +15 -15
- package/src/components/nice-progress-bar/nice-progress-bar.js +55 -55
- package/src/components/nice-progress-bar/nice-progress-bar.scss +47 -47
- package/src/components/nice-quantity/nice-quantity.html +22 -22
- package/src/components/nice-quantity/nice-quantity.js +57 -57
- package/src/components/nice-quantity/nice-quantity.scss +51 -51
- package/src/components/nice-search/nice-search.html +44 -44
- package/src/components/nice-search/nice-search.js +243 -243
- package/src/components/nice-search/nice-search.scss +90 -90
- package/src/components/nice-search2/nice-search2.html +32 -32
- package/src/components/nice-search2/nice-search2.js +267 -267
- package/src/components/nice-search2/nice-search2.scss +80 -80
- package/src/components/nice-slot/nice-slot.html +10 -10
- package/src/components/nice-slot/nice-slot.js +31 -31
- package/src/components/nice-steps/nice-steps.scss +81 -81
- package/src/components/nice-svgs/nice-svgs.html +1332 -1320
- package/src/components/nice-svgs/nice-svgs.js +19 -19
- package/src/components/nice-table/nice-table.html +38 -38
- package/src/components/nice-table/nice-table.js +60 -60
- package/src/components/nice-table/nice-table.scss +112 -112
- package/src/components/nice-time-picker/nice-time-picker.html +43 -43
- package/src/components/nice-time-picker/nice-time-picker.js +85 -85
- package/src/components/nice-time-picker/nice-time-picker.scss +37 -37
- package/src/components/nice-title/nice-title.html +6 -6
- package/src/components/nice-title/nice-title.js +22 -22
- package/src/components/nice-toast/nice-toast.html +2 -2
- package/src/components/nice-toast/nice-toast.js +56 -56
- package/src/components/nice-toast/nice-toast.scss +74 -74
- package/src/components/nice-toggle/nice-toggle.html +12 -12
- package/src/components/nice-toggle/nice-toggle.js +57 -57
- package/src/components/nice-toggle/nice-toggle.scss +131 -131
- package/src/components/nice-upload/nice-upload.html +22 -22
- package/src/components/nice-upload/nice-upload.js +160 -159
- package/src/components/nice-upload/nice-upload.scss +85 -85
- package/src/components/nice-view/_nice-view.scss +63 -63
- package/src/components/nice-view/nice-view.html +12 -12
- package/src/components/nice-view/nice-view.js +29 -30
- package/src/components/nice-virtual-scroll/_nice-virtual-scroll.scss +17 -17
- package/src/components/nice-virtual-scroll/nice-virtual-scroll.html +12 -12
- package/src/components/nice-virtual-scroll/nice-virtual-scroll.js +70 -70
- package/src/components/nice-wrapper/_nice-wrapper.scss +87 -87
- package/src/components/nice-wrapper/nice-wrapper.html +12 -12
- package/src/components/nice-wrapper/nice-wrapper.js +44 -44
- package/src/components/nice-yesno/nice-yesno.html +14 -14
- package/src/components/nice-yesno/nice-yesno.js +111 -111
- package/src/components/nice-yesno/nice-yesno.scss +95 -95
- package/src/directives/nice-click-outside.js +105 -105
- package/src/directives/nice-infinite-loader.js +27 -27
- package/src/directives/nice-tooltip/_nice-tooltip.scss +55 -55
- package/src/directives/nice-tooltip/nice-tooltip.js +84 -84
- package/src/filters/nice-date.js +17 -17
- package/src/filters/nice-highlight.js +16 -16
- package/src/modals/nice-multilangual-modal/nice-multilangual-modal.html +30 -30
- package/src/modals/nice-multilangual-modal/nice-multilangual-modal.js +67 -67
- package/src/modals/nice-multilangual-modal/nice-multilangual-modal.scss +19 -19
- package/src/nice.js +2 -2
- package/src/services/nice-service.js +22 -22
- package/src/styles/_bootstrap-variables.scss +178 -178
- package/src/styles/_nice-buttons.scss +612 -612
- package/src/styles/_nice-common.scss +479 -479
- package/src/styles/_nice-ngdialog.scss +85 -85
- package/src/styles/_nice-spacing.scss +283 -283
- package/src/styles/_nice.scss +75 -75
- package/src/styles/_variables.scss +194 -194
|
@@ -1,836 +1,836 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* @ngdoc directive
|
|
5
|
-
* @name niceElements.directive:niceDtp
|
|
6
|
-
* @description
|
|
7
|
-
* # niceDtp
|
|
8
|
-
*/
|
|
9
|
-
angular.module('niceElements')
|
|
10
|
-
|
|
11
|
-
.directive('niceDtp', function ($window, $parse, $document) {
|
|
12
|
-
|
|
13
|
-
return {
|
|
14
|
-
scope: {
|
|
15
|
-
onChange: '&?', // function called on date changed
|
|
16
|
-
model: '=', // binding model
|
|
17
|
-
format: '@', // default: 'D.M.YYYY • H:mm', format for input label string
|
|
18
|
-
modelFormat: '@', // default: ''
|
|
19
|
-
//currentDate: '@',
|
|
20
|
-
date: '@', // default: true, is date picker enabled?
|
|
21
|
-
time: '@', // default: false, is time picker enabled?
|
|
22
|
-
width: '@', // default: 300, width of entire dtp-picker in px
|
|
23
|
-
enableOkButtons: '@', // default: false, is ok/cancel buttons enabled?
|
|
24
|
-
lang: '@', // default: 'en', which locale to use - you must load angular locales first
|
|
25
|
-
minDate: '@', // default: undefined
|
|
26
|
-
maxDate: '@', // default: undefined
|
|
27
|
-
weekStart: '@', // default: 1, which day does the week start? (0 - sunday, 1 - monday, ...)
|
|
28
|
-
okText: '@',
|
|
29
|
-
cancelText: '@',
|
|
30
|
-
shortTime: '@', // default: false,
|
|
31
|
-
niceTitle: '@',
|
|
32
|
-
title: '@', // default: ''
|
|
33
|
-
noMargin: '@', // default: false, if noMargin==true then entire directive can be injected inside other divs
|
|
34
|
-
fieldWidth: '@', // default: 'col-sm-8', bootstrap classes that defines width of field
|
|
35
|
-
labelWidth: '@', // default: 'col-sm-4', bootstrap classes that defines width of label
|
|
36
|
-
closed: '=',
|
|
37
|
-
required: '='
|
|
38
|
-
},
|
|
39
|
-
templateUrl: 'src/components/nice-dtp/nice-dtp.html',
|
|
40
|
-
controller: function ($scope, $element, $attrs, gettextCatalog) {
|
|
41
|
-
console.warn("[NICE ELEMENTS] nice-dtp component is deprecated!");
|
|
42
|
-
|
|
43
|
-
// default parameters
|
|
44
|
-
const params = {
|
|
45
|
-
title: '',
|
|
46
|
-
noMargin: false,
|
|
47
|
-
fieldWidth: 'col-sm-8',
|
|
48
|
-
labelWidth: 'col-sm-4',
|
|
49
|
-
format: 'D.M.YYYY • H:mm',
|
|
50
|
-
modelFormat: 'YYYY-MM-DDTHH:mm:ss.SSS',
|
|
51
|
-
minDate: null,
|
|
52
|
-
maxDate: null,
|
|
53
|
-
lang: 'en',
|
|
54
|
-
weekStart: 1,
|
|
55
|
-
shortTime: false,
|
|
56
|
-
cancelText: gettextCatalog.getString('Cancel', null, 'Nice'),
|
|
57
|
-
okText: gettextCatalog.getString('OK', null, 'Nice'),
|
|
58
|
-
date: true,
|
|
59
|
-
time: false,
|
|
60
|
-
width: 300,
|
|
61
|
-
enableOkButtons: false
|
|
62
|
-
};
|
|
63
|
-
|
|
64
|
-
const prepareAttrs = function () {
|
|
65
|
-
// prepare attributes
|
|
66
|
-
params.date = $attrs.date === 'true' || $attrs.date === true;
|
|
67
|
-
params.time = $attrs.time === 'true' || $attrs.time === true;
|
|
68
|
-
params.inline = $attrs.inline === 'true' || $attrs.inline === true;
|
|
69
|
-
if ($attrs.format && $attrs.format != "")
|
|
70
|
-
params.format = $attrs.format;
|
|
71
|
-
if ($scope.enableOkButtons && $attrs.enableOkButtons != "")
|
|
72
|
-
params.enableOkButtons = $attrs.enableOkButtons === 'true';
|
|
73
|
-
if ($attrs.lang && $attrs.lang != "")
|
|
74
|
-
params.lang = $attrs.lang;
|
|
75
|
-
if ($attrs.minDate && $attrs.minDate != "")
|
|
76
|
-
params.minDate = $attrs.minDate;
|
|
77
|
-
if ($attrs.maxDate && $attrs.maxDate != "")
|
|
78
|
-
params.maxDate = $attrs.maxDate;
|
|
79
|
-
if ($scope.weekStart && $attrs.weekStart != "")
|
|
80
|
-
params.weekStart = parseInt($attrs.weekStart);
|
|
81
|
-
if ($attrs.okText && $attrs.okText != "")
|
|
82
|
-
params.okText = $attrs.okText;
|
|
83
|
-
if ($attrs.cancelText && $attrs.cancelText != "")
|
|
84
|
-
params.cancelText = $attrs.cancelText;
|
|
85
|
-
if ($attrs.noMargin && $attrs.noMargin != "")
|
|
86
|
-
params.noMargin = $attrs.noMargin === 'true';
|
|
87
|
-
if ($attrs.modelFormat && $attrs.modelFormat != "")
|
|
88
|
-
params.modelFormat = $attrs.modelFormat;
|
|
89
|
-
|
|
90
|
-
if ($attrs.width) {
|
|
91
|
-
params.width = parseInt($attrs.width);
|
|
92
|
-
}
|
|
93
|
-
//$scope.dtp_content_style = {width: params.width + 'px'};
|
|
94
|
-
|
|
95
|
-
// copy attributes back to scope - for template usage
|
|
96
|
-
$scope = angular.extend($scope, params);
|
|
97
|
-
|
|
98
|
-
};
|
|
99
|
-
|
|
100
|
-
$scope.date = $attrs.date === 'true' || $attrs.date === true;
|
|
101
|
-
$scope.time = $attrs.time === 'true' || $attrs.time === true;
|
|
102
|
-
|
|
103
|
-
// functions are defined in a variable 'const that', not in $scope
|
|
104
|
-
const that = {
|
|
105
|
-
init: function () {
|
|
106
|
-
//console.log('init', $scope);
|
|
107
|
-
|
|
108
|
-
$scope.showDtp = false;
|
|
109
|
-
that.initDays();
|
|
110
|
-
that.initDates();
|
|
111
|
-
},
|
|
112
|
-
initDays: function () {
|
|
113
|
-
//console.log('initDays');
|
|
114
|
-
$scope.days = [];
|
|
115
|
-
for (let i = params.weekStart; $scope.days.length < 7; i++) {
|
|
116
|
-
if (i > 6) {
|
|
117
|
-
i = 0;
|
|
118
|
-
}
|
|
119
|
-
$scope.days.push(i.toString());
|
|
120
|
-
}
|
|
121
|
-
},
|
|
122
|
-
fixMinMaxDate: function () {
|
|
123
|
-
if ($scope.minDate === "")
|
|
124
|
-
$scope.minDate = null;
|
|
125
|
-
if ($scope.maxDate === "")
|
|
126
|
-
$scope.maxDate = null;
|
|
127
|
-
},
|
|
128
|
-
initDates: function () {
|
|
129
|
-
that.fixMinMaxDate();
|
|
130
|
-
if (typeof ($scope.model) === 'undefined' || $scope.model === null) {
|
|
131
|
-
$scope.currentDate = moment();
|
|
132
|
-
} else {
|
|
133
|
-
//// all other combinations
|
|
134
|
-
//if (typeof($scope.model) === 'string') {
|
|
135
|
-
// $scope.currentDate = moment($scope.model, params.modelFormat).locale(params.lang);
|
|
136
|
-
//}
|
|
137
|
-
//else {
|
|
138
|
-
$scope.currentDate = moment($scope.model).locale(params.lang);
|
|
139
|
-
//}
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
that.setDateModel();
|
|
143
|
-
that.setElementValue();
|
|
144
|
-
|
|
145
|
-
// Parse minDate
|
|
146
|
-
if (typeof ($scope.minDate) !== 'undefined' && $scope.minDate !== null) {
|
|
147
|
-
if (typeof ($scope.minDate) === 'string') {
|
|
148
|
-
$scope.minDate = moment($scope.minDate).locale(params.lang);
|
|
149
|
-
}
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
// Parse maxDate
|
|
153
|
-
if (typeof ($scope.maxDate) !== 'undefined' && $scope.maxDate !== null) {
|
|
154
|
-
if (typeof ($scope.maxDate) === 'string') {
|
|
155
|
-
$scope.maxDate = moment($scope.maxDate).locale(params.lang);
|
|
156
|
-
}
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
// Fix currentDate if violates minDate and maxDate constraints
|
|
160
|
-
if (params.date === true) {
|
|
161
|
-
if (!that.isAfterMinDate($scope.currentDate)) {
|
|
162
|
-
$scope.currentDate = moment($scope.minDate);
|
|
163
|
-
}
|
|
164
|
-
if (!that.isBeforeMaxDate($scope.currentDate)) {
|
|
165
|
-
$scope.currentDate = moment($scope.maxDate);
|
|
166
|
-
}
|
|
167
|
-
}
|
|
168
|
-
},
|
|
169
|
-
initDate: function () {
|
|
170
|
-
that.fixMinMaxDate();
|
|
171
|
-
|
|
172
|
-
$scope.currentView = 0;
|
|
173
|
-
|
|
174
|
-
$scope.showCalendar = true;
|
|
175
|
-
$scope.showTime = false;
|
|
176
|
-
|
|
177
|
-
const _date = ((typeof ($scope.currentDate) !== 'undefined' && $scope.currentDate !== null) ? $scope.currentDate : null);
|
|
178
|
-
$scope.calendar = that.generateCalendar($scope.currentDate);
|
|
179
|
-
|
|
180
|
-
if (typeof ($scope.calendar.week) !== 'undefined' && typeof ($scope.calendar.days) !== 'undefined') {
|
|
181
|
-
that.constructHTMLCalendar(_date, $scope.calendar);
|
|
182
|
-
that.toggleButtons(_date);
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
that._centerBox();
|
|
186
|
-
that.showDate(_date);
|
|
187
|
-
},
|
|
188
|
-
initHours: function () {
|
|
189
|
-
that.fixMinMaxDate();
|
|
190
|
-
$scope.currentView = 1;
|
|
191
|
-
$scope.hours = [];
|
|
192
|
-
$scope.minutes = [];
|
|
193
|
-
$scope.showTime = true;
|
|
194
|
-
$scope.showCalendar = false;
|
|
195
|
-
|
|
196
|
-
that.showTime($scope.currentDate);
|
|
197
|
-
|
|
198
|
-
const pL = 10;
|
|
199
|
-
const pT = 10;
|
|
200
|
-
const mL = 20;
|
|
201
|
-
const mT = 10;
|
|
202
|
-
const r = 100;
|
|
203
|
-
|
|
204
|
-
const j = r / 1.55;
|
|
205
|
-
const j_pm = r / 1.15;
|
|
206
|
-
|
|
207
|
-
const _hours = [];
|
|
208
|
-
|
|
209
|
-
// AM hours
|
|
210
|
-
for (let h = 0; h < 12; ++h) {
|
|
211
|
-
const cH = (($scope.currentDate.format('HH') == 24) ? 0 : $scope.currentDate.format('HH'));
|
|
212
|
-
const x = j * Math.sin(Math.PI * 2 * (h / 12));
|
|
213
|
-
const y = j * Math.cos(Math.PI * 2 * (h / 12));
|
|
214
|
-
|
|
215
|
-
const _hour = {
|
|
216
|
-
style: {
|
|
217
|
-
x: x,
|
|
218
|
-
y: y,
|
|
219
|
-
marginLeft: (r + x + parseInt(pL) / 2) - (parseInt(pL) + parseInt(mL)) + 'px',
|
|
220
|
-
marginTop: (r - y - parseInt(mT) / 2) - (parseInt(pT) + parseInt(mT)) + 'px'
|
|
221
|
-
},
|
|
222
|
-
h: h == 0 ? 12 : h,
|
|
223
|
-
selected: h == parseInt(cH)
|
|
224
|
-
};
|
|
225
|
-
|
|
226
|
-
_hours.push(_hour);
|
|
227
|
-
}
|
|
228
|
-
|
|
229
|
-
// PM hours
|
|
230
|
-
for (let h = 0; h < 12; ++h) {
|
|
231
|
-
const cH = (($scope.currentDate.format('HH') == 24) ? 0 : $scope.currentDate.format('HH'));
|
|
232
|
-
const x = j_pm * Math.sin(Math.PI * 2 * (h / 12));
|
|
233
|
-
const y = j_pm * Math.cos(Math.PI * 2 * (h / 12));
|
|
234
|
-
|
|
235
|
-
const _hour = {
|
|
236
|
-
style: {
|
|
237
|
-
x: x,
|
|
238
|
-
y: y,
|
|
239
|
-
marginLeft: (r + x + parseInt(pL) / 2) - (parseInt(pL) + parseInt(mL)) + 'px',
|
|
240
|
-
marginTop: (r - y - parseInt(mT) / 2) - (parseInt(pT) + parseInt(mT)) + 'px'
|
|
241
|
-
},
|
|
242
|
-
h: h == 0 ? 0 : h + 12,
|
|
243
|
-
selected: h + 12 == parseInt(cH)
|
|
244
|
-
};
|
|
245
|
-
|
|
246
|
-
_hours.push(_hour);
|
|
247
|
-
}
|
|
248
|
-
|
|
249
|
-
$scope.hours = _hours;
|
|
250
|
-
that.toggleTime(true);
|
|
251
|
-
that.initHands(true);
|
|
252
|
-
},
|
|
253
|
-
initMinutes: function () {
|
|
254
|
-
that.fixMinMaxDate();
|
|
255
|
-
$scope.currentView = 2;
|
|
256
|
-
$scope.hours = [];
|
|
257
|
-
$scope.minutes = [];
|
|
258
|
-
$scope.showCalendar = false;
|
|
259
|
-
$scope.showTime = true;
|
|
260
|
-
|
|
261
|
-
that.showTime($scope.currentDate);
|
|
262
|
-
|
|
263
|
-
const pL = 10;
|
|
264
|
-
const pT = 10;
|
|
265
|
-
const mL = 20;
|
|
266
|
-
const mT = 10;
|
|
267
|
-
const w = 200;
|
|
268
|
-
const r = w / 2;
|
|
269
|
-
const j = r / 1.2;
|
|
270
|
-
const _minutes = [];
|
|
271
|
-
|
|
272
|
-
for (let m = 0; m < 60; m += 5) {
|
|
273
|
-
const x = j * Math.sin(Math.PI * 2 * (m / 60));
|
|
274
|
-
const y = j * Math.cos(Math.PI * 2 * (m / 60));
|
|
275
|
-
|
|
276
|
-
const _minute = {
|
|
277
|
-
style: {
|
|
278
|
-
x: x,
|
|
279
|
-
y: y,
|
|
280
|
-
marginLeft: (r + x + parseInt(pL) / 2) - (parseInt(pL) + parseInt(mL)) + 'px',
|
|
281
|
-
marginTop: (r - y - parseInt(mT) / 2) - (parseInt(pT) + parseInt(mT)) + 'px'
|
|
282
|
-
},
|
|
283
|
-
m: ((m.toString().length == 2) ? m : '0' + m),
|
|
284
|
-
selected: m == 5 * Math.round($scope.currentDate.minute() / 5)
|
|
285
|
-
};
|
|
286
|
-
_minutes.push(_minute);
|
|
287
|
-
}
|
|
288
|
-
|
|
289
|
-
$scope.minutes = _minutes;
|
|
290
|
-
that.toggleTime(false);
|
|
291
|
-
that.initHands(false);
|
|
292
|
-
that._centerBox();
|
|
293
|
-
},
|
|
294
|
-
initHands: function (t) {
|
|
295
|
-
const pL = 10;
|
|
296
|
-
const mL = 20;
|
|
297
|
-
const w = 7.5;
|
|
298
|
-
const h = 7.5;
|
|
299
|
-
const r = 100;
|
|
300
|
-
const _hL = r / 1.7;
|
|
301
|
-
const _mL = r / 1.5;
|
|
302
|
-
|
|
303
|
-
const dtpHourHand = $element[0].getElementsByClassName('dtp-hour-hand')[0];
|
|
304
|
-
dtpHourHand.style.left = r + (parseInt(mL) * 1.5) + 'px';
|
|
305
|
-
dtpHourHand.style.height = _hL + 'px';
|
|
306
|
-
dtpHourHand.style.marginTop = (r - _hL - parseInt(pL)) + 'px';
|
|
307
|
-
if (t) dtpHourHand.classList.add("on");
|
|
308
|
-
|
|
309
|
-
const dtpMinuteHand = $element[0].getElementsByClassName('dtp-minute-hand')[0];
|
|
310
|
-
dtpMinuteHand.style.left = r + (parseInt(mL) * 1.5) + 'px';
|
|
311
|
-
dtpMinuteHand.style.height = _mL + 'px';
|
|
312
|
-
dtpMinuteHand.style.marginTop = (r - _mL - parseInt(pL)) + 'px';
|
|
313
|
-
if (t) dtpMinuteHand.classList.add("on");
|
|
314
|
-
|
|
315
|
-
const dtpClockCenter = $element[0].getElementsByClassName('dtp-clock-center')[0];
|
|
316
|
-
dtpClockCenter.style.left = r + parseInt(pL) + parseInt(mL) - w + 'px';
|
|
317
|
-
dtpClockCenter.style.marginTop = (r - (parseInt(mL) / 2)) - h + 'px';
|
|
318
|
-
|
|
319
|
-
that.animateHands();
|
|
320
|
-
|
|
321
|
-
that._centerBox();
|
|
322
|
-
},
|
|
323
|
-
animateHands: function () {
|
|
324
|
-
const h = $scope.currentDate.hour();
|
|
325
|
-
const m = $scope.currentDate.minute();
|
|
326
|
-
|
|
327
|
-
const dtpHourHand = $element[0].getElementsByClassName('dtp-hour-hand')[0];
|
|
328
|
-
const dtpMinuteHand = $element[0].getElementsByClassName('dtp-minute-hand')[0];
|
|
329
|
-
that.rotateElement(dtpHourHand, (360 / 12) * h);
|
|
330
|
-
that.rotateElement(dtpMinuteHand, ((360 / 60) * (5 * Math.round(m / 5))));
|
|
331
|
-
},
|
|
332
|
-
isAfterMinDate: function (date, checkHour, checkMinute) {
|
|
333
|
-
let _return = true;
|
|
334
|
-
|
|
335
|
-
if (typeof ($scope.minDate) !== 'undefined' && $scope.minDate !== null) {
|
|
336
|
-
const _minDate = moment($scope.minDate);
|
|
337
|
-
const _date = moment(date);
|
|
338
|
-
|
|
339
|
-
if (!checkHour && !checkMinute) {
|
|
340
|
-
_minDate.hour(0);
|
|
341
|
-
_minDate.minute(0);
|
|
342
|
-
|
|
343
|
-
_date.hour(0);
|
|
344
|
-
_date.minute(0);
|
|
345
|
-
}
|
|
346
|
-
|
|
347
|
-
_minDate.second(0);
|
|
348
|
-
_date.second(0);
|
|
349
|
-
_minDate.millisecond(0);
|
|
350
|
-
_date.millisecond(0);
|
|
351
|
-
|
|
352
|
-
if (!checkMinute) {
|
|
353
|
-
_date.minute(0);
|
|
354
|
-
_minDate.minute(0);
|
|
355
|
-
|
|
356
|
-
_return = (parseInt(_date.format("X")) >= parseInt(_minDate.format("X")));
|
|
357
|
-
} else {
|
|
358
|
-
_return = (parseInt(_date.format("X")) >= parseInt(_minDate.format("X")));
|
|
359
|
-
}
|
|
360
|
-
}
|
|
361
|
-
|
|
362
|
-
return _return;
|
|
363
|
-
},
|
|
364
|
-
isBeforeMaxDate: function (date, checkTime, checkMinute) {
|
|
365
|
-
let _return = true;
|
|
366
|
-
|
|
367
|
-
if (typeof ($scope.maxDate) !== 'undefined' && $scope.maxDate !== null) {
|
|
368
|
-
const _maxDate = moment($scope.maxDate);
|
|
369
|
-
const _date = moment(date);
|
|
370
|
-
|
|
371
|
-
if (!checkTime && !checkMinute) {
|
|
372
|
-
_maxDate.hour(0);
|
|
373
|
-
_maxDate.minute(0);
|
|
374
|
-
|
|
375
|
-
_date.hour(0);
|
|
376
|
-
_date.minute(0);
|
|
377
|
-
}
|
|
378
|
-
|
|
379
|
-
_maxDate.second(0);
|
|
380
|
-
_date.second(0);
|
|
381
|
-
_maxDate.millisecond(0);
|
|
382
|
-
_date.millisecond(0);
|
|
383
|
-
|
|
384
|
-
if (!checkMinute) {
|
|
385
|
-
_date.minute(0);
|
|
386
|
-
_maxDate.minute(0);
|
|
387
|
-
|
|
388
|
-
_return = (parseInt(_date.format("X")) <= parseInt(_maxDate.format("X")));
|
|
389
|
-
} else {
|
|
390
|
-
_return = (parseInt(_date.format("X")) <= parseInt(_maxDate.format("X")));
|
|
391
|
-
}
|
|
392
|
-
}
|
|
393
|
-
|
|
394
|
-
return _return;
|
|
395
|
-
},
|
|
396
|
-
rotateElement: function (el, deg) {
|
|
397
|
-
el.style.transform = 'rotate(' + deg + 'deg)';
|
|
398
|
-
},
|
|
399
|
-
showDate: function (date) {
|
|
400
|
-
//console.log('showDate');
|
|
401
|
-
$scope.showTimeHeader = true;
|
|
402
|
-
if (date) {
|
|
403
|
-
$scope.showDateHeader = true;
|
|
404
|
-
$scope.actualDay = date.locale(params.lang).format('dddd');
|
|
405
|
-
$scope.actualMonth = date.locale(params.lang).format('MMM').toUpperCase();
|
|
406
|
-
$scope.actualNum = date.locale(params.lang).format('DD');
|
|
407
|
-
$scope.actualYear = date.locale(params.lang).format('YYYY');
|
|
408
|
-
}
|
|
409
|
-
},
|
|
410
|
-
showTime: function (date) {
|
|
411
|
-
//console.log('showTime', date);
|
|
412
|
-
if (date) {
|
|
413
|
-
const _minutes = (5 * Math.round(date.minute() / 5));
|
|
414
|
-
const _time = {
|
|
415
|
-
hours: date.format('HH'),
|
|
416
|
-
minutes: ((_minutes.toString().length == 2) ? _minutes : '0' + _minutes)
|
|
417
|
-
};
|
|
418
|
-
|
|
419
|
-
if (params.date) {
|
|
420
|
-
$scope.showTimeHeader = true;
|
|
421
|
-
$scope.actualTime = _time;
|
|
422
|
-
} else {
|
|
423
|
-
if (params.shortTime)
|
|
424
|
-
$scope.actualDay = date.format('A');
|
|
425
|
-
else
|
|
426
|
-
$scope.actualDay = ' ';
|
|
427
|
-
|
|
428
|
-
$scope.showTimeHeader = false;
|
|
429
|
-
$scope.actualTime = _time;
|
|
430
|
-
}
|
|
431
|
-
}
|
|
432
|
-
},
|
|
433
|
-
selectDate: function (date) {
|
|
434
|
-
//console.log('selectDate');
|
|
435
|
-
if (date) {
|
|
436
|
-
$scope.currentDate = date;
|
|
437
|
-
that.showDate($scope.currentDate);
|
|
438
|
-
$scope.$emit('dateSelected', {
|
|
439
|
-
date: date
|
|
440
|
-
});
|
|
441
|
-
}
|
|
442
|
-
},
|
|
443
|
-
generateCalendar: function (date) {
|
|
444
|
-
//console.log('generateCalendar');
|
|
445
|
-
const _calendar = {};
|
|
446
|
-
|
|
447
|
-
if (date !== null) {
|
|
448
|
-
const startOfMonth = moment(date).locale(params.lang).startOf('month');
|
|
449
|
-
const endOfMonth = moment(date).locale(params.lang).endOf('month');
|
|
450
|
-
|
|
451
|
-
const iNumDay = startOfMonth.format('d');
|
|
452
|
-
|
|
453
|
-
_calendar.week = $scope.days;
|
|
454
|
-
_calendar.days = [];
|
|
455
|
-
|
|
456
|
-
for (let i = startOfMonth.date(); i <= endOfMonth.date(); i++) {
|
|
457
|
-
if (i === startOfMonth.date()) {
|
|
458
|
-
const iWeek = _calendar.week.indexOf(iNumDay.toString());
|
|
459
|
-
if (iWeek > 0) {
|
|
460
|
-
for (let x = 0; x < iWeek; x++) {
|
|
461
|
-
_calendar.days.push(0);
|
|
462
|
-
}
|
|
463
|
-
}
|
|
464
|
-
}
|
|
465
|
-
_calendar.days.push(moment(startOfMonth).locale(params.lang).date(i));
|
|
466
|
-
}
|
|
467
|
-
}
|
|
468
|
-
|
|
469
|
-
return _calendar;
|
|
470
|
-
},
|
|
471
|
-
constructHTMLCalendar: function (date, calendar) {
|
|
472
|
-
$scope.monthAndYear = date.locale(params.lang).format('MMMM YYYY');
|
|
473
|
-
|
|
474
|
-
const _weekDays = [];
|
|
475
|
-
for (let i = 0; i < calendar.week.length; i++) {
|
|
476
|
-
_weekDays.push(moment(parseInt(calendar.week[i]), "d").locale(params.lang).format("dd").substring(0, 1));
|
|
477
|
-
}
|
|
478
|
-
$scope.weekDays = _weekDays;
|
|
479
|
-
|
|
480
|
-
const _weeks = [];
|
|
481
|
-
|
|
482
|
-
let _week = [];
|
|
483
|
-
for (let i = 0; i < calendar.days.length; i++) {
|
|
484
|
-
if (i % 7 == 0) {
|
|
485
|
-
if (i != 0) {
|
|
486
|
-
_weeks.push(_week);
|
|
487
|
-
}
|
|
488
|
-
_week = [];
|
|
489
|
-
}
|
|
490
|
-
|
|
491
|
-
const _day = {
|
|
492
|
-
label: null,
|
|
493
|
-
selected: false,
|
|
494
|
-
disabled: true,
|
|
495
|
-
data: {}
|
|
496
|
-
};
|
|
497
|
-
|
|
498
|
-
if (calendar.days[i] != 0) {
|
|
499
|
-
_day.disabled = false;
|
|
500
|
-
_day.label = moment(calendar.days[i]).locale(params.lang).format("DD");
|
|
501
|
-
_day.data = calendar.days[i];
|
|
502
|
-
if (that.isBeforeMaxDate(moment(calendar.days[i]), false, false) === false || that.isAfterMinDate(moment(calendar.days[i]), false, false) === false) {
|
|
503
|
-
_day.disabled = true;
|
|
504
|
-
} else {
|
|
505
|
-
if (moment(calendar.days[i]).locale(params.lang).format("DD") === moment($scope.currentDate).locale(params.lang).format("DD")) {
|
|
506
|
-
_day.selected = true;
|
|
507
|
-
|
|
508
|
-
}
|
|
509
|
-
}
|
|
510
|
-
}
|
|
511
|
-
_week.push(_day);
|
|
512
|
-
}
|
|
513
|
-
|
|
514
|
-
if (_week.length > 0) {
|
|
515
|
-
_weeks.push(_week);
|
|
516
|
-
}
|
|
517
|
-
|
|
518
|
-
$scope.weeks = _weeks;
|
|
519
|
-
//console.log('$scope.weeks', $scope.weeks);
|
|
520
|
-
//console.log('$scope.weekDays', $scope.weekDays);
|
|
521
|
-
},
|
|
522
|
-
setName: function () {
|
|
523
|
-
let text = "";
|
|
524
|
-
const possible = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
|
|
525
|
-
|
|
526
|
-
for (let i = 0; i < 5; i++) {
|
|
527
|
-
text += possible.charAt(Math.floor(Math.random() * possible.length));
|
|
528
|
-
}
|
|
529
|
-
|
|
530
|
-
return text;
|
|
531
|
-
},
|
|
532
|
-
isPM: function () {
|
|
533
|
-
return $scope.isPM;
|
|
534
|
-
},
|
|
535
|
-
setElementValue: function (date) {
|
|
536
|
-
|
|
537
|
-
//if (typeof(date) !== 'undefined'){
|
|
538
|
-
// $scope.currentDate = moment(date).locale(params.lang);
|
|
539
|
-
//}
|
|
540
|
-
|
|
541
|
-
$scope.value = moment($scope.currentDate).locale(params.lang).format(params.format);
|
|
542
|
-
},
|
|
543
|
-
setDateModel: function () {
|
|
544
|
-
$scope.model = angular.copy($scope.currentDate);
|
|
545
|
-
if ($scope.onChange) $scope.onChange({ model: $scope.model });
|
|
546
|
-
//$scope.model = $scope.currentDate.format(params.modelFormat);
|
|
547
|
-
//$scope.formDatetimePicker.$setDirty();
|
|
548
|
-
},
|
|
549
|
-
toggleButtons: function (date) {
|
|
550
|
-
if (date && date.isValid()) {
|
|
551
|
-
const startOfMonth = moment(date).locale(params.lang).startOf('month');
|
|
552
|
-
const endOfMonth = moment(date).locale(params.lang).endOf('month');
|
|
553
|
-
|
|
554
|
-
$scope.btnMonthBeforeEnabled = that.isAfterMinDate(startOfMonth, false, false);
|
|
555
|
-
$scope.btnMonthAfterEnabled = that.isBeforeMaxDate(endOfMonth, false, false);
|
|
556
|
-
|
|
557
|
-
const startOfYear = moment(date).locale(params.lang).startOf('year');
|
|
558
|
-
const endOfYear = moment(date).locale(params.lang).endOf('year');
|
|
559
|
-
|
|
560
|
-
$scope.btnYearBeforeEnabled = that.isAfterMinDate(startOfYear, false, false);
|
|
561
|
-
$scope.btnYearAfterEnabled = that.isBeforeMaxDate(endOfYear, false, false);
|
|
562
|
-
}
|
|
563
|
-
},
|
|
564
|
-
toggleTime: function (isHours) {
|
|
565
|
-
if (isHours) {
|
|
566
|
-
angular.forEach($scope.hours, function (hour, hourKey) {
|
|
567
|
-
const _date = moment($scope.currentDate);
|
|
568
|
-
_date.hour(that.convertHours(hour.h)).minute(0).second(0);
|
|
569
|
-
|
|
570
|
-
if (that.isAfterMinDate(_date, true, false) === false || that.isBeforeMaxDate(_date, true, false) === false) {
|
|
571
|
-
hour.disabled = true;
|
|
572
|
-
} else {
|
|
573
|
-
hour.disabled = false;
|
|
574
|
-
}
|
|
575
|
-
});
|
|
576
|
-
} else {
|
|
577
|
-
angular.forEach($scope.minutes, function (minute, minuteKey) {
|
|
578
|
-
const _minute = minute.m;
|
|
579
|
-
const _date = moment($scope.currentDate);
|
|
580
|
-
_date.minute(_minute).second(0);
|
|
581
|
-
|
|
582
|
-
if (that.isAfterMinDate(_date, true, true) === false || that.isBeforeMaxDate(_date, true, true) === false) {
|
|
583
|
-
minute.disabled = true;
|
|
584
|
-
} else {
|
|
585
|
-
minute.disabled = false;
|
|
586
|
-
}
|
|
587
|
-
});
|
|
588
|
-
}
|
|
589
|
-
},
|
|
590
|
-
_onClick: function () {
|
|
591
|
-
$scope.currentView = 0;
|
|
592
|
-
|
|
593
|
-
that.initDates();
|
|
594
|
-
|
|
595
|
-
that.show();
|
|
596
|
-
|
|
597
|
-
if (params.date) {
|
|
598
|
-
$scope.showDate = true;
|
|
599
|
-
that.initDate();
|
|
600
|
-
} else {
|
|
601
|
-
if (params.time) {
|
|
602
|
-
$scope.showTime = true;
|
|
603
|
-
that.initHours();
|
|
604
|
-
}
|
|
605
|
-
}
|
|
606
|
-
},
|
|
607
|
-
_onBackgroundClick: function (e) {
|
|
608
|
-
e.stopPropagation();
|
|
609
|
-
that.hide();
|
|
610
|
-
},
|
|
611
|
-
_onElementClick: function (e) {
|
|
612
|
-
e.stopPropagation();
|
|
613
|
-
},
|
|
614
|
-
_onCloseClick: function () {
|
|
615
|
-
that.hide();
|
|
616
|
-
if ($scope.closed) $scope.closed(true);
|
|
617
|
-
},
|
|
618
|
-
_onOKClick: function () {
|
|
619
|
-
switch ($scope.currentView) {
|
|
620
|
-
case 0:
|
|
621
|
-
if (params.time === true) {
|
|
622
|
-
that.initHours();
|
|
623
|
-
} else {
|
|
624
|
-
that.setElementValue();
|
|
625
|
-
that.setDateModel();
|
|
626
|
-
if (!$scope.inline)
|
|
627
|
-
that.hide();
|
|
628
|
-
}
|
|
629
|
-
break;
|
|
630
|
-
case 1:
|
|
631
|
-
that.initMinutes();
|
|
632
|
-
break;
|
|
633
|
-
case 2:
|
|
634
|
-
that.setElementValue();
|
|
635
|
-
that.setDateModel();
|
|
636
|
-
if ($scope.inline) {
|
|
637
|
-
that._onClick();
|
|
638
|
-
} else {
|
|
639
|
-
that.hide();
|
|
640
|
-
}
|
|
641
|
-
break;
|
|
642
|
-
}
|
|
643
|
-
},
|
|
644
|
-
_onCancelClick: function () {
|
|
645
|
-
if (params.time) {
|
|
646
|
-
switch ($scope.currentView) {
|
|
647
|
-
case 0:
|
|
648
|
-
that.hide();
|
|
649
|
-
break;
|
|
650
|
-
case 1:
|
|
651
|
-
if (params.date) {
|
|
652
|
-
that.initDate();
|
|
653
|
-
} else {
|
|
654
|
-
that.hide();
|
|
655
|
-
}
|
|
656
|
-
break;
|
|
657
|
-
case 2:
|
|
658
|
-
that.initHours();
|
|
659
|
-
break;
|
|
660
|
-
}
|
|
661
|
-
} else {
|
|
662
|
-
that.hide();
|
|
663
|
-
}
|
|
664
|
-
},
|
|
665
|
-
_onMonthBeforeClick: function () {
|
|
666
|
-
if ($scope.btnMonthBeforeEnabled) {
|
|
667
|
-
$scope.currentDate.subtract(1, 'months');
|
|
668
|
-
that.initDate($scope.currentDate);
|
|
669
|
-
}
|
|
670
|
-
},
|
|
671
|
-
_onMonthAfterClick: function () {
|
|
672
|
-
if ($scope.btnMonthAfterEnabled) {
|
|
673
|
-
$scope.currentDate.add(1, 'months');
|
|
674
|
-
that.initDate($scope.currentDate);
|
|
675
|
-
}
|
|
676
|
-
},
|
|
677
|
-
_onYearBeforeClick: function () {
|
|
678
|
-
if ($scope.btnYearBeforeEnabled) {
|
|
679
|
-
$scope.currentDate.subtract(1, 'years');
|
|
680
|
-
that.initDate($scope.currentDate);
|
|
681
|
-
}
|
|
682
|
-
},
|
|
683
|
-
_onYearAfterClick: function () {
|
|
684
|
-
if ($scope.btnYearAfterEnabled) {
|
|
685
|
-
$scope.currentDate.add(1, 'years');
|
|
686
|
-
that.initDate($scope.currentDate);
|
|
687
|
-
}
|
|
688
|
-
},
|
|
689
|
-
_onSelectDate: function (date) {
|
|
690
|
-
// remove selected from all dates in $scope.weeks
|
|
691
|
-
angular.forEach($scope.weeks, function (week, weekKey) {
|
|
692
|
-
angular.forEach($scope.weeks[weekKey], function (day, dayKey) {
|
|
693
|
-
$scope.weeks[weekKey][dayKey].selected = false;
|
|
694
|
-
});
|
|
695
|
-
});
|
|
696
|
-
date.selected = true;
|
|
697
|
-
that.selectDate(date.data);
|
|
698
|
-
|
|
699
|
-
if (!params.enableOkButtons) {
|
|
700
|
-
that._onOKClick();
|
|
701
|
-
}
|
|
702
|
-
},
|
|
703
|
-
_onSelectHour: function (hourSelected) {
|
|
704
|
-
|
|
705
|
-
if (!hourSelected.disabled) {
|
|
706
|
-
// remove selected from all dates in $scope.weeks
|
|
707
|
-
angular.forEach($scope.hours, function (hour, hourKey) {
|
|
708
|
-
$scope.hours[hourKey].selected = false;
|
|
709
|
-
});
|
|
710
|
-
hourSelected.selected = true;
|
|
711
|
-
|
|
712
|
-
let dataHour = parseInt(hourSelected.h);
|
|
713
|
-
if (that.isPM())
|
|
714
|
-
dataHour += 12;
|
|
715
|
-
|
|
716
|
-
$scope.currentDate.hour(dataHour);
|
|
717
|
-
that.showTime($scope.currentDate);
|
|
718
|
-
|
|
719
|
-
that.animateHands();
|
|
720
|
-
if (!params.enableOkButtons) {
|
|
721
|
-
that._onOKClick();
|
|
722
|
-
}
|
|
723
|
-
} else {
|
|
724
|
-
//console.log('hour disabled');
|
|
725
|
-
}
|
|
726
|
-
},
|
|
727
|
-
_onSelectMinute: function (minuteSelected) {
|
|
728
|
-
|
|
729
|
-
if (!minuteSelected.disabled) {
|
|
730
|
-
// remove selected from all minutes in $scope.minutes
|
|
731
|
-
angular.forEach($scope.minutes, function (minute, minuteKey) {
|
|
732
|
-
$scope.minutes[minuteKey].selected = false;
|
|
733
|
-
});
|
|
734
|
-
minuteSelected.selected = true;
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
$scope.currentDate.minute(parseInt(minuteSelected.m));
|
|
738
|
-
that.showTime($scope.currentDate);
|
|
739
|
-
|
|
740
|
-
that.animateHands();
|
|
741
|
-
if (!params.enableOkButtons) {
|
|
742
|
-
that._onOKClick();
|
|
743
|
-
}
|
|
744
|
-
}
|
|
745
|
-
},
|
|
746
|
-
convertHours: function (h) {
|
|
747
|
-
let _return = h;
|
|
748
|
-
|
|
749
|
-
if ((h < 12) && that.isPM())
|
|
750
|
-
_return += 12;
|
|
751
|
-
|
|
752
|
-
return _return;
|
|
753
|
-
},
|
|
754
|
-
setDate: function (date) {
|
|
755
|
-
//console.log('setDate');
|
|
756
|
-
params.currentDate = date;
|
|
757
|
-
that.initDates();
|
|
758
|
-
},
|
|
759
|
-
setMinDate: function (date) {
|
|
760
|
-
params.minDate = date;
|
|
761
|
-
that.initDates();
|
|
762
|
-
},
|
|
763
|
-
setMaxDate: function (date) {
|
|
764
|
-
params.maxDate = date;
|
|
765
|
-
that.initDates();
|
|
766
|
-
},
|
|
767
|
-
show: function () {
|
|
768
|
-
$scope.showDtp = true;
|
|
769
|
-
that._centerBox();
|
|
770
|
-
},
|
|
771
|
-
hide: function () {
|
|
772
|
-
$scope.showDtp = false;
|
|
773
|
-
},
|
|
774
|
-
resetDate: function () {
|
|
775
|
-
|
|
776
|
-
},
|
|
777
|
-
_centerBox: function () {
|
|
778
|
-
//var h = (this.$dtpElement.height() - this.$dtpElement.find('.dtp-content').height()) / 2;
|
|
779
|
-
//this.$dtpElement.find('.dtp-content').css('marginLeft', -(this.$dtpElement.find('.dtp-content').width() / 2) + 'px');
|
|
780
|
-
//this.$dtpElement.find('.dtp-content').css('top', h + 'px');
|
|
781
|
-
}
|
|
782
|
-
};
|
|
783
|
-
|
|
784
|
-
$scope.onClick = that._onClick;
|
|
785
|
-
$scope.onOKClick = that._onOKClick;
|
|
786
|
-
$scope.onCancelClick = that._onCancelClick;
|
|
787
|
-
$scope.onCloseClick = that._onCloseClick;
|
|
788
|
-
|
|
789
|
-
$scope.onSelectDate = that._onSelectDate;
|
|
790
|
-
$scope.onMonthBeforeClick = that._onMonthBeforeClick;
|
|
791
|
-
$scope.onMonthAfterClick = that._onMonthAfterClick;
|
|
792
|
-
$scope.onYearBeforeClick = that._onYearBeforeClick;
|
|
793
|
-
$scope.onYearAfterClick = that._onYearAfterClick;
|
|
794
|
-
|
|
795
|
-
$scope.onSelectHour = that._onSelectHour;
|
|
796
|
-
$scope.onSelectMinute = that._onSelectMinute;
|
|
797
|
-
|
|
798
|
-
$scope.initDate = that.initDate;
|
|
799
|
-
$scope.initHours = that.initHours;
|
|
800
|
-
$scope.initMinutes = that.initMinutes;
|
|
801
|
-
|
|
802
|
-
prepareAttrs();
|
|
803
|
-
that.init();
|
|
804
|
-
|
|
805
|
-
if ($scope.inline) {
|
|
806
|
-
//console.log('auto show inline');
|
|
807
|
-
that._onClick();
|
|
808
|
-
}
|
|
809
|
-
|
|
810
|
-
$scope.$on('dtp-open-click', function () {
|
|
811
|
-
that._onClick();
|
|
812
|
-
});
|
|
813
|
-
|
|
814
|
-
$scope.$on('dtp-close-click', function () {
|
|
815
|
-
that.hide();
|
|
816
|
-
});
|
|
817
|
-
|
|
818
|
-
$scope.$watch('model', function (newDate) {
|
|
819
|
-
$scope.currentDate = newDate;
|
|
820
|
-
that.showDate($scope.currentDate);
|
|
821
|
-
that.initDate();
|
|
822
|
-
});
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
// Close the dropdown if clicked outside
|
|
826
|
-
//$document.bind('click', function(event){
|
|
827
|
-
// console.log($element.find(event.target));
|
|
828
|
-
// var isClickedElementChildOfPopup = $element.find(event.target).length == 0;
|
|
829
|
-
// if (isClickedElementChildOfPopup){
|
|
830
|
-
// that.hide();
|
|
831
|
-
// }
|
|
832
|
-
//});
|
|
833
|
-
}
|
|
834
|
-
};
|
|
835
|
-
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @ngdoc directive
|
|
5
|
+
* @name niceElements.directive:niceDtp
|
|
6
|
+
* @description
|
|
7
|
+
* # niceDtp
|
|
8
|
+
*/
|
|
9
|
+
angular.module('niceElements')
|
|
10
|
+
|
|
11
|
+
.directive('niceDtp', function ($window, $parse, $document) {
|
|
12
|
+
|
|
13
|
+
return {
|
|
14
|
+
scope: {
|
|
15
|
+
onChange: '&?', // function called on date changed
|
|
16
|
+
model: '=', // binding model
|
|
17
|
+
format: '@', // default: 'D.M.YYYY • H:mm', format for input label string
|
|
18
|
+
modelFormat: '@', // default: ''
|
|
19
|
+
//currentDate: '@',
|
|
20
|
+
date: '@', // default: true, is date picker enabled?
|
|
21
|
+
time: '@', // default: false, is time picker enabled?
|
|
22
|
+
width: '@', // default: 300, width of entire dtp-picker in px
|
|
23
|
+
enableOkButtons: '@', // default: false, is ok/cancel buttons enabled?
|
|
24
|
+
lang: '@', // default: 'en', which locale to use - you must load angular locales first
|
|
25
|
+
minDate: '@', // default: undefined
|
|
26
|
+
maxDate: '@', // default: undefined
|
|
27
|
+
weekStart: '@', // default: 1, which day does the week start? (0 - sunday, 1 - monday, ...)
|
|
28
|
+
okText: '@',
|
|
29
|
+
cancelText: '@',
|
|
30
|
+
shortTime: '@', // default: false,
|
|
31
|
+
niceTitle: '@',
|
|
32
|
+
title: '@', // default: ''
|
|
33
|
+
noMargin: '@', // default: false, if noMargin==true then entire directive can be injected inside other divs
|
|
34
|
+
fieldWidth: '@', // default: 'col-sm-8', bootstrap classes that defines width of field
|
|
35
|
+
labelWidth: '@', // default: 'col-sm-4', bootstrap classes that defines width of label
|
|
36
|
+
closed: '=',
|
|
37
|
+
required: '='
|
|
38
|
+
},
|
|
39
|
+
templateUrl: 'src/components/nice-dtp/nice-dtp.html',
|
|
40
|
+
controller: function ($scope, $element, $attrs, gettextCatalog) {
|
|
41
|
+
console.warn("[NICE ELEMENTS] nice-dtp component is deprecated!");
|
|
42
|
+
|
|
43
|
+
// default parameters
|
|
44
|
+
const params = {
|
|
45
|
+
title: '',
|
|
46
|
+
noMargin: false,
|
|
47
|
+
fieldWidth: 'col-sm-8',
|
|
48
|
+
labelWidth: 'col-sm-4',
|
|
49
|
+
format: 'D.M.YYYY • H:mm',
|
|
50
|
+
modelFormat: 'YYYY-MM-DDTHH:mm:ss.SSS',
|
|
51
|
+
minDate: null,
|
|
52
|
+
maxDate: null,
|
|
53
|
+
lang: 'en',
|
|
54
|
+
weekStart: 1,
|
|
55
|
+
shortTime: false,
|
|
56
|
+
cancelText: gettextCatalog.getString('Cancel', null, 'Nice'),
|
|
57
|
+
okText: gettextCatalog.getString('OK', null, 'Nice'),
|
|
58
|
+
date: true,
|
|
59
|
+
time: false,
|
|
60
|
+
width: 300,
|
|
61
|
+
enableOkButtons: false
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
const prepareAttrs = function () {
|
|
65
|
+
// prepare attributes
|
|
66
|
+
params.date = $attrs.date === 'true' || $attrs.date === true;
|
|
67
|
+
params.time = $attrs.time === 'true' || $attrs.time === true;
|
|
68
|
+
params.inline = $attrs.inline === 'true' || $attrs.inline === true;
|
|
69
|
+
if ($attrs.format && $attrs.format != "")
|
|
70
|
+
params.format = $attrs.format;
|
|
71
|
+
if ($scope.enableOkButtons && $attrs.enableOkButtons != "")
|
|
72
|
+
params.enableOkButtons = $attrs.enableOkButtons === 'true';
|
|
73
|
+
if ($attrs.lang && $attrs.lang != "")
|
|
74
|
+
params.lang = $attrs.lang;
|
|
75
|
+
if ($attrs.minDate && $attrs.minDate != "")
|
|
76
|
+
params.minDate = $attrs.minDate;
|
|
77
|
+
if ($attrs.maxDate && $attrs.maxDate != "")
|
|
78
|
+
params.maxDate = $attrs.maxDate;
|
|
79
|
+
if ($scope.weekStart && $attrs.weekStart != "")
|
|
80
|
+
params.weekStart = parseInt($attrs.weekStart);
|
|
81
|
+
if ($attrs.okText && $attrs.okText != "")
|
|
82
|
+
params.okText = $attrs.okText;
|
|
83
|
+
if ($attrs.cancelText && $attrs.cancelText != "")
|
|
84
|
+
params.cancelText = $attrs.cancelText;
|
|
85
|
+
if ($attrs.noMargin && $attrs.noMargin != "")
|
|
86
|
+
params.noMargin = $attrs.noMargin === 'true';
|
|
87
|
+
if ($attrs.modelFormat && $attrs.modelFormat != "")
|
|
88
|
+
params.modelFormat = $attrs.modelFormat;
|
|
89
|
+
|
|
90
|
+
if ($attrs.width) {
|
|
91
|
+
params.width = parseInt($attrs.width);
|
|
92
|
+
}
|
|
93
|
+
//$scope.dtp_content_style = {width: params.width + 'px'};
|
|
94
|
+
|
|
95
|
+
// copy attributes back to scope - for template usage
|
|
96
|
+
$scope = angular.extend($scope, params);
|
|
97
|
+
|
|
98
|
+
};
|
|
99
|
+
|
|
100
|
+
$scope.date = $attrs.date === 'true' || $attrs.date === true;
|
|
101
|
+
$scope.time = $attrs.time === 'true' || $attrs.time === true;
|
|
102
|
+
|
|
103
|
+
// functions are defined in a variable 'const that', not in $scope
|
|
104
|
+
const that = {
|
|
105
|
+
init: function () {
|
|
106
|
+
//console.log('init', $scope);
|
|
107
|
+
|
|
108
|
+
$scope.showDtp = false;
|
|
109
|
+
that.initDays();
|
|
110
|
+
that.initDates();
|
|
111
|
+
},
|
|
112
|
+
initDays: function () {
|
|
113
|
+
//console.log('initDays');
|
|
114
|
+
$scope.days = [];
|
|
115
|
+
for (let i = params.weekStart; $scope.days.length < 7; i++) {
|
|
116
|
+
if (i > 6) {
|
|
117
|
+
i = 0;
|
|
118
|
+
}
|
|
119
|
+
$scope.days.push(i.toString());
|
|
120
|
+
}
|
|
121
|
+
},
|
|
122
|
+
fixMinMaxDate: function () {
|
|
123
|
+
if ($scope.minDate === "")
|
|
124
|
+
$scope.minDate = null;
|
|
125
|
+
if ($scope.maxDate === "")
|
|
126
|
+
$scope.maxDate = null;
|
|
127
|
+
},
|
|
128
|
+
initDates: function () {
|
|
129
|
+
that.fixMinMaxDate();
|
|
130
|
+
if (typeof ($scope.model) === 'undefined' || $scope.model === null) {
|
|
131
|
+
$scope.currentDate = moment();
|
|
132
|
+
} else {
|
|
133
|
+
//// all other combinations
|
|
134
|
+
//if (typeof($scope.model) === 'string') {
|
|
135
|
+
// $scope.currentDate = moment($scope.model, params.modelFormat).locale(params.lang);
|
|
136
|
+
//}
|
|
137
|
+
//else {
|
|
138
|
+
$scope.currentDate = moment($scope.model).locale(params.lang);
|
|
139
|
+
//}
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
that.setDateModel();
|
|
143
|
+
that.setElementValue();
|
|
144
|
+
|
|
145
|
+
// Parse minDate
|
|
146
|
+
if (typeof ($scope.minDate) !== 'undefined' && $scope.minDate !== null) {
|
|
147
|
+
if (typeof ($scope.minDate) === 'string') {
|
|
148
|
+
$scope.minDate = moment($scope.minDate).locale(params.lang);
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
// Parse maxDate
|
|
153
|
+
if (typeof ($scope.maxDate) !== 'undefined' && $scope.maxDate !== null) {
|
|
154
|
+
if (typeof ($scope.maxDate) === 'string') {
|
|
155
|
+
$scope.maxDate = moment($scope.maxDate).locale(params.lang);
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
// Fix currentDate if violates minDate and maxDate constraints
|
|
160
|
+
if (params.date === true) {
|
|
161
|
+
if (!that.isAfterMinDate($scope.currentDate)) {
|
|
162
|
+
$scope.currentDate = moment($scope.minDate);
|
|
163
|
+
}
|
|
164
|
+
if (!that.isBeforeMaxDate($scope.currentDate)) {
|
|
165
|
+
$scope.currentDate = moment($scope.maxDate);
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
},
|
|
169
|
+
initDate: function () {
|
|
170
|
+
that.fixMinMaxDate();
|
|
171
|
+
|
|
172
|
+
$scope.currentView = 0;
|
|
173
|
+
|
|
174
|
+
$scope.showCalendar = true;
|
|
175
|
+
$scope.showTime = false;
|
|
176
|
+
|
|
177
|
+
const _date = ((typeof ($scope.currentDate) !== 'undefined' && $scope.currentDate !== null) ? $scope.currentDate : null);
|
|
178
|
+
$scope.calendar = that.generateCalendar($scope.currentDate);
|
|
179
|
+
|
|
180
|
+
if (typeof ($scope.calendar.week) !== 'undefined' && typeof ($scope.calendar.days) !== 'undefined') {
|
|
181
|
+
that.constructHTMLCalendar(_date, $scope.calendar);
|
|
182
|
+
that.toggleButtons(_date);
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
that._centerBox();
|
|
186
|
+
that.showDate(_date);
|
|
187
|
+
},
|
|
188
|
+
initHours: function () {
|
|
189
|
+
that.fixMinMaxDate();
|
|
190
|
+
$scope.currentView = 1;
|
|
191
|
+
$scope.hours = [];
|
|
192
|
+
$scope.minutes = [];
|
|
193
|
+
$scope.showTime = true;
|
|
194
|
+
$scope.showCalendar = false;
|
|
195
|
+
|
|
196
|
+
that.showTime($scope.currentDate);
|
|
197
|
+
|
|
198
|
+
const pL = 10;
|
|
199
|
+
const pT = 10;
|
|
200
|
+
const mL = 20;
|
|
201
|
+
const mT = 10;
|
|
202
|
+
const r = 100;
|
|
203
|
+
|
|
204
|
+
const j = r / 1.55;
|
|
205
|
+
const j_pm = r / 1.15;
|
|
206
|
+
|
|
207
|
+
const _hours = [];
|
|
208
|
+
|
|
209
|
+
// AM hours
|
|
210
|
+
for (let h = 0; h < 12; ++h) {
|
|
211
|
+
const cH = (($scope.currentDate.format('HH') == 24) ? 0 : $scope.currentDate.format('HH'));
|
|
212
|
+
const x = j * Math.sin(Math.PI * 2 * (h / 12));
|
|
213
|
+
const y = j * Math.cos(Math.PI * 2 * (h / 12));
|
|
214
|
+
|
|
215
|
+
const _hour = {
|
|
216
|
+
style: {
|
|
217
|
+
x: x,
|
|
218
|
+
y: y,
|
|
219
|
+
marginLeft: (r + x + parseInt(pL) / 2) - (parseInt(pL) + parseInt(mL)) + 'px',
|
|
220
|
+
marginTop: (r - y - parseInt(mT) / 2) - (parseInt(pT) + parseInt(mT)) + 'px'
|
|
221
|
+
},
|
|
222
|
+
h: h == 0 ? 12 : h,
|
|
223
|
+
selected: h == parseInt(cH)
|
|
224
|
+
};
|
|
225
|
+
|
|
226
|
+
_hours.push(_hour);
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
// PM hours
|
|
230
|
+
for (let h = 0; h < 12; ++h) {
|
|
231
|
+
const cH = (($scope.currentDate.format('HH') == 24) ? 0 : $scope.currentDate.format('HH'));
|
|
232
|
+
const x = j_pm * Math.sin(Math.PI * 2 * (h / 12));
|
|
233
|
+
const y = j_pm * Math.cos(Math.PI * 2 * (h / 12));
|
|
234
|
+
|
|
235
|
+
const _hour = {
|
|
236
|
+
style: {
|
|
237
|
+
x: x,
|
|
238
|
+
y: y,
|
|
239
|
+
marginLeft: (r + x + parseInt(pL) / 2) - (parseInt(pL) + parseInt(mL)) + 'px',
|
|
240
|
+
marginTop: (r - y - parseInt(mT) / 2) - (parseInt(pT) + parseInt(mT)) + 'px'
|
|
241
|
+
},
|
|
242
|
+
h: h == 0 ? 0 : h + 12,
|
|
243
|
+
selected: h + 12 == parseInt(cH)
|
|
244
|
+
};
|
|
245
|
+
|
|
246
|
+
_hours.push(_hour);
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
$scope.hours = _hours;
|
|
250
|
+
that.toggleTime(true);
|
|
251
|
+
that.initHands(true);
|
|
252
|
+
},
|
|
253
|
+
initMinutes: function () {
|
|
254
|
+
that.fixMinMaxDate();
|
|
255
|
+
$scope.currentView = 2;
|
|
256
|
+
$scope.hours = [];
|
|
257
|
+
$scope.minutes = [];
|
|
258
|
+
$scope.showCalendar = false;
|
|
259
|
+
$scope.showTime = true;
|
|
260
|
+
|
|
261
|
+
that.showTime($scope.currentDate);
|
|
262
|
+
|
|
263
|
+
const pL = 10;
|
|
264
|
+
const pT = 10;
|
|
265
|
+
const mL = 20;
|
|
266
|
+
const mT = 10;
|
|
267
|
+
const w = 200;
|
|
268
|
+
const r = w / 2;
|
|
269
|
+
const j = r / 1.2;
|
|
270
|
+
const _minutes = [];
|
|
271
|
+
|
|
272
|
+
for (let m = 0; m < 60; m += 5) {
|
|
273
|
+
const x = j * Math.sin(Math.PI * 2 * (m / 60));
|
|
274
|
+
const y = j * Math.cos(Math.PI * 2 * (m / 60));
|
|
275
|
+
|
|
276
|
+
const _minute = {
|
|
277
|
+
style: {
|
|
278
|
+
x: x,
|
|
279
|
+
y: y,
|
|
280
|
+
marginLeft: (r + x + parseInt(pL) / 2) - (parseInt(pL) + parseInt(mL)) + 'px',
|
|
281
|
+
marginTop: (r - y - parseInt(mT) / 2) - (parseInt(pT) + parseInt(mT)) + 'px'
|
|
282
|
+
},
|
|
283
|
+
m: ((m.toString().length == 2) ? m : '0' + m),
|
|
284
|
+
selected: m == 5 * Math.round($scope.currentDate.minute() / 5)
|
|
285
|
+
};
|
|
286
|
+
_minutes.push(_minute);
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
$scope.minutes = _minutes;
|
|
290
|
+
that.toggleTime(false);
|
|
291
|
+
that.initHands(false);
|
|
292
|
+
that._centerBox();
|
|
293
|
+
},
|
|
294
|
+
initHands: function (t) {
|
|
295
|
+
const pL = 10;
|
|
296
|
+
const mL = 20;
|
|
297
|
+
const w = 7.5;
|
|
298
|
+
const h = 7.5;
|
|
299
|
+
const r = 100;
|
|
300
|
+
const _hL = r / 1.7;
|
|
301
|
+
const _mL = r / 1.5;
|
|
302
|
+
|
|
303
|
+
const dtpHourHand = $element[0].getElementsByClassName('dtp-hour-hand')[0];
|
|
304
|
+
dtpHourHand.style.left = r + (parseInt(mL) * 1.5) + 'px';
|
|
305
|
+
dtpHourHand.style.height = _hL + 'px';
|
|
306
|
+
dtpHourHand.style.marginTop = (r - _hL - parseInt(pL)) + 'px';
|
|
307
|
+
if (t) dtpHourHand.classList.add("on");
|
|
308
|
+
|
|
309
|
+
const dtpMinuteHand = $element[0].getElementsByClassName('dtp-minute-hand')[0];
|
|
310
|
+
dtpMinuteHand.style.left = r + (parseInt(mL) * 1.5) + 'px';
|
|
311
|
+
dtpMinuteHand.style.height = _mL + 'px';
|
|
312
|
+
dtpMinuteHand.style.marginTop = (r - _mL - parseInt(pL)) + 'px';
|
|
313
|
+
if (t) dtpMinuteHand.classList.add("on");
|
|
314
|
+
|
|
315
|
+
const dtpClockCenter = $element[0].getElementsByClassName('dtp-clock-center')[0];
|
|
316
|
+
dtpClockCenter.style.left = r + parseInt(pL) + parseInt(mL) - w + 'px';
|
|
317
|
+
dtpClockCenter.style.marginTop = (r - (parseInt(mL) / 2)) - h + 'px';
|
|
318
|
+
|
|
319
|
+
that.animateHands();
|
|
320
|
+
|
|
321
|
+
that._centerBox();
|
|
322
|
+
},
|
|
323
|
+
animateHands: function () {
|
|
324
|
+
const h = $scope.currentDate.hour();
|
|
325
|
+
const m = $scope.currentDate.minute();
|
|
326
|
+
|
|
327
|
+
const dtpHourHand = $element[0].getElementsByClassName('dtp-hour-hand')[0];
|
|
328
|
+
const dtpMinuteHand = $element[0].getElementsByClassName('dtp-minute-hand')[0];
|
|
329
|
+
that.rotateElement(dtpHourHand, (360 / 12) * h);
|
|
330
|
+
that.rotateElement(dtpMinuteHand, ((360 / 60) * (5 * Math.round(m / 5))));
|
|
331
|
+
},
|
|
332
|
+
isAfterMinDate: function (date, checkHour, checkMinute) {
|
|
333
|
+
let _return = true;
|
|
334
|
+
|
|
335
|
+
if (typeof ($scope.minDate) !== 'undefined' && $scope.minDate !== null) {
|
|
336
|
+
const _minDate = moment($scope.minDate);
|
|
337
|
+
const _date = moment(date);
|
|
338
|
+
|
|
339
|
+
if (!checkHour && !checkMinute) {
|
|
340
|
+
_minDate.hour(0);
|
|
341
|
+
_minDate.minute(0);
|
|
342
|
+
|
|
343
|
+
_date.hour(0);
|
|
344
|
+
_date.minute(0);
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
_minDate.second(0);
|
|
348
|
+
_date.second(0);
|
|
349
|
+
_minDate.millisecond(0);
|
|
350
|
+
_date.millisecond(0);
|
|
351
|
+
|
|
352
|
+
if (!checkMinute) {
|
|
353
|
+
_date.minute(0);
|
|
354
|
+
_minDate.minute(0);
|
|
355
|
+
|
|
356
|
+
_return = (parseInt(_date.format("X")) >= parseInt(_minDate.format("X")));
|
|
357
|
+
} else {
|
|
358
|
+
_return = (parseInt(_date.format("X")) >= parseInt(_minDate.format("X")));
|
|
359
|
+
}
|
|
360
|
+
}
|
|
361
|
+
|
|
362
|
+
return _return;
|
|
363
|
+
},
|
|
364
|
+
isBeforeMaxDate: function (date, checkTime, checkMinute) {
|
|
365
|
+
let _return = true;
|
|
366
|
+
|
|
367
|
+
if (typeof ($scope.maxDate) !== 'undefined' && $scope.maxDate !== null) {
|
|
368
|
+
const _maxDate = moment($scope.maxDate);
|
|
369
|
+
const _date = moment(date);
|
|
370
|
+
|
|
371
|
+
if (!checkTime && !checkMinute) {
|
|
372
|
+
_maxDate.hour(0);
|
|
373
|
+
_maxDate.minute(0);
|
|
374
|
+
|
|
375
|
+
_date.hour(0);
|
|
376
|
+
_date.minute(0);
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
_maxDate.second(0);
|
|
380
|
+
_date.second(0);
|
|
381
|
+
_maxDate.millisecond(0);
|
|
382
|
+
_date.millisecond(0);
|
|
383
|
+
|
|
384
|
+
if (!checkMinute) {
|
|
385
|
+
_date.minute(0);
|
|
386
|
+
_maxDate.minute(0);
|
|
387
|
+
|
|
388
|
+
_return = (parseInt(_date.format("X")) <= parseInt(_maxDate.format("X")));
|
|
389
|
+
} else {
|
|
390
|
+
_return = (parseInt(_date.format("X")) <= parseInt(_maxDate.format("X")));
|
|
391
|
+
}
|
|
392
|
+
}
|
|
393
|
+
|
|
394
|
+
return _return;
|
|
395
|
+
},
|
|
396
|
+
rotateElement: function (el, deg) {
|
|
397
|
+
el.style.transform = 'rotate(' + deg + 'deg)';
|
|
398
|
+
},
|
|
399
|
+
showDate: function (date) {
|
|
400
|
+
//console.log('showDate');
|
|
401
|
+
$scope.showTimeHeader = true;
|
|
402
|
+
if (date) {
|
|
403
|
+
$scope.showDateHeader = true;
|
|
404
|
+
$scope.actualDay = date.locale(params.lang).format('dddd');
|
|
405
|
+
$scope.actualMonth = date.locale(params.lang).format('MMM').toUpperCase();
|
|
406
|
+
$scope.actualNum = date.locale(params.lang).format('DD');
|
|
407
|
+
$scope.actualYear = date.locale(params.lang).format('YYYY');
|
|
408
|
+
}
|
|
409
|
+
},
|
|
410
|
+
showTime: function (date) {
|
|
411
|
+
//console.log('showTime', date);
|
|
412
|
+
if (date) {
|
|
413
|
+
const _minutes = (5 * Math.round(date.minute() / 5));
|
|
414
|
+
const _time = {
|
|
415
|
+
hours: date.format('HH'),
|
|
416
|
+
minutes: ((_minutes.toString().length == 2) ? _minutes : '0' + _minutes)
|
|
417
|
+
};
|
|
418
|
+
|
|
419
|
+
if (params.date) {
|
|
420
|
+
$scope.showTimeHeader = true;
|
|
421
|
+
$scope.actualTime = _time;
|
|
422
|
+
} else {
|
|
423
|
+
if (params.shortTime)
|
|
424
|
+
$scope.actualDay = date.format('A');
|
|
425
|
+
else
|
|
426
|
+
$scope.actualDay = ' ';
|
|
427
|
+
|
|
428
|
+
$scope.showTimeHeader = false;
|
|
429
|
+
$scope.actualTime = _time;
|
|
430
|
+
}
|
|
431
|
+
}
|
|
432
|
+
},
|
|
433
|
+
selectDate: function (date) {
|
|
434
|
+
//console.log('selectDate');
|
|
435
|
+
if (date) {
|
|
436
|
+
$scope.currentDate = date;
|
|
437
|
+
that.showDate($scope.currentDate);
|
|
438
|
+
$scope.$emit('dateSelected', {
|
|
439
|
+
date: date
|
|
440
|
+
});
|
|
441
|
+
}
|
|
442
|
+
},
|
|
443
|
+
generateCalendar: function (date) {
|
|
444
|
+
//console.log('generateCalendar');
|
|
445
|
+
const _calendar = {};
|
|
446
|
+
|
|
447
|
+
if (date !== null) {
|
|
448
|
+
const startOfMonth = moment(date).locale(params.lang).startOf('month');
|
|
449
|
+
const endOfMonth = moment(date).locale(params.lang).endOf('month');
|
|
450
|
+
|
|
451
|
+
const iNumDay = startOfMonth.format('d');
|
|
452
|
+
|
|
453
|
+
_calendar.week = $scope.days;
|
|
454
|
+
_calendar.days = [];
|
|
455
|
+
|
|
456
|
+
for (let i = startOfMonth.date(); i <= endOfMonth.date(); i++) {
|
|
457
|
+
if (i === startOfMonth.date()) {
|
|
458
|
+
const iWeek = _calendar.week.indexOf(iNumDay.toString());
|
|
459
|
+
if (iWeek > 0) {
|
|
460
|
+
for (let x = 0; x < iWeek; x++) {
|
|
461
|
+
_calendar.days.push(0);
|
|
462
|
+
}
|
|
463
|
+
}
|
|
464
|
+
}
|
|
465
|
+
_calendar.days.push(moment(startOfMonth).locale(params.lang).date(i));
|
|
466
|
+
}
|
|
467
|
+
}
|
|
468
|
+
|
|
469
|
+
return _calendar;
|
|
470
|
+
},
|
|
471
|
+
constructHTMLCalendar: function (date, calendar) {
|
|
472
|
+
$scope.monthAndYear = date.locale(params.lang).format('MMMM YYYY');
|
|
473
|
+
|
|
474
|
+
const _weekDays = [];
|
|
475
|
+
for (let i = 0; i < calendar.week.length; i++) {
|
|
476
|
+
_weekDays.push(moment(parseInt(calendar.week[i]), "d").locale(params.lang).format("dd").substring(0, 1));
|
|
477
|
+
}
|
|
478
|
+
$scope.weekDays = _weekDays;
|
|
479
|
+
|
|
480
|
+
const _weeks = [];
|
|
481
|
+
|
|
482
|
+
let _week = [];
|
|
483
|
+
for (let i = 0; i < calendar.days.length; i++) {
|
|
484
|
+
if (i % 7 == 0) {
|
|
485
|
+
if (i != 0) {
|
|
486
|
+
_weeks.push(_week);
|
|
487
|
+
}
|
|
488
|
+
_week = [];
|
|
489
|
+
}
|
|
490
|
+
|
|
491
|
+
const _day = {
|
|
492
|
+
label: null,
|
|
493
|
+
selected: false,
|
|
494
|
+
disabled: true,
|
|
495
|
+
data: {}
|
|
496
|
+
};
|
|
497
|
+
|
|
498
|
+
if (calendar.days[i] != 0) {
|
|
499
|
+
_day.disabled = false;
|
|
500
|
+
_day.label = moment(calendar.days[i]).locale(params.lang).format("DD");
|
|
501
|
+
_day.data = calendar.days[i];
|
|
502
|
+
if (that.isBeforeMaxDate(moment(calendar.days[i]), false, false) === false || that.isAfterMinDate(moment(calendar.days[i]), false, false) === false) {
|
|
503
|
+
_day.disabled = true;
|
|
504
|
+
} else {
|
|
505
|
+
if (moment(calendar.days[i]).locale(params.lang).format("DD") === moment($scope.currentDate).locale(params.lang).format("DD")) {
|
|
506
|
+
_day.selected = true;
|
|
507
|
+
|
|
508
|
+
}
|
|
509
|
+
}
|
|
510
|
+
}
|
|
511
|
+
_week.push(_day);
|
|
512
|
+
}
|
|
513
|
+
|
|
514
|
+
if (_week.length > 0) {
|
|
515
|
+
_weeks.push(_week);
|
|
516
|
+
}
|
|
517
|
+
|
|
518
|
+
$scope.weeks = _weeks;
|
|
519
|
+
//console.log('$scope.weeks', $scope.weeks);
|
|
520
|
+
//console.log('$scope.weekDays', $scope.weekDays);
|
|
521
|
+
},
|
|
522
|
+
setName: function () {
|
|
523
|
+
let text = "";
|
|
524
|
+
const possible = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
|
|
525
|
+
|
|
526
|
+
for (let i = 0; i < 5; i++) {
|
|
527
|
+
text += possible.charAt(Math.floor(Math.random() * possible.length));
|
|
528
|
+
}
|
|
529
|
+
|
|
530
|
+
return text;
|
|
531
|
+
},
|
|
532
|
+
isPM: function () {
|
|
533
|
+
return $scope.isPM;
|
|
534
|
+
},
|
|
535
|
+
setElementValue: function (date) {
|
|
536
|
+
|
|
537
|
+
//if (typeof(date) !== 'undefined'){
|
|
538
|
+
// $scope.currentDate = moment(date).locale(params.lang);
|
|
539
|
+
//}
|
|
540
|
+
|
|
541
|
+
$scope.value = moment($scope.currentDate).locale(params.lang).format(params.format);
|
|
542
|
+
},
|
|
543
|
+
setDateModel: function () {
|
|
544
|
+
$scope.model = angular.copy($scope.currentDate);
|
|
545
|
+
if ($scope.onChange) $scope.onChange({ model: $scope.model });
|
|
546
|
+
//$scope.model = $scope.currentDate.format(params.modelFormat);
|
|
547
|
+
//$scope.formDatetimePicker.$setDirty();
|
|
548
|
+
},
|
|
549
|
+
toggleButtons: function (date) {
|
|
550
|
+
if (date && date.isValid()) {
|
|
551
|
+
const startOfMonth = moment(date).locale(params.lang).startOf('month');
|
|
552
|
+
const endOfMonth = moment(date).locale(params.lang).endOf('month');
|
|
553
|
+
|
|
554
|
+
$scope.btnMonthBeforeEnabled = that.isAfterMinDate(startOfMonth, false, false);
|
|
555
|
+
$scope.btnMonthAfterEnabled = that.isBeforeMaxDate(endOfMonth, false, false);
|
|
556
|
+
|
|
557
|
+
const startOfYear = moment(date).locale(params.lang).startOf('year');
|
|
558
|
+
const endOfYear = moment(date).locale(params.lang).endOf('year');
|
|
559
|
+
|
|
560
|
+
$scope.btnYearBeforeEnabled = that.isAfterMinDate(startOfYear, false, false);
|
|
561
|
+
$scope.btnYearAfterEnabled = that.isBeforeMaxDate(endOfYear, false, false);
|
|
562
|
+
}
|
|
563
|
+
},
|
|
564
|
+
toggleTime: function (isHours) {
|
|
565
|
+
if (isHours) {
|
|
566
|
+
angular.forEach($scope.hours, function (hour, hourKey) {
|
|
567
|
+
const _date = moment($scope.currentDate);
|
|
568
|
+
_date.hour(that.convertHours(hour.h)).minute(0).second(0);
|
|
569
|
+
|
|
570
|
+
if (that.isAfterMinDate(_date, true, false) === false || that.isBeforeMaxDate(_date, true, false) === false) {
|
|
571
|
+
hour.disabled = true;
|
|
572
|
+
} else {
|
|
573
|
+
hour.disabled = false;
|
|
574
|
+
}
|
|
575
|
+
});
|
|
576
|
+
} else {
|
|
577
|
+
angular.forEach($scope.minutes, function (minute, minuteKey) {
|
|
578
|
+
const _minute = minute.m;
|
|
579
|
+
const _date = moment($scope.currentDate);
|
|
580
|
+
_date.minute(_minute).second(0);
|
|
581
|
+
|
|
582
|
+
if (that.isAfterMinDate(_date, true, true) === false || that.isBeforeMaxDate(_date, true, true) === false) {
|
|
583
|
+
minute.disabled = true;
|
|
584
|
+
} else {
|
|
585
|
+
minute.disabled = false;
|
|
586
|
+
}
|
|
587
|
+
});
|
|
588
|
+
}
|
|
589
|
+
},
|
|
590
|
+
_onClick: function () {
|
|
591
|
+
$scope.currentView = 0;
|
|
592
|
+
|
|
593
|
+
that.initDates();
|
|
594
|
+
|
|
595
|
+
that.show();
|
|
596
|
+
|
|
597
|
+
if (params.date) {
|
|
598
|
+
$scope.showDate = true;
|
|
599
|
+
that.initDate();
|
|
600
|
+
} else {
|
|
601
|
+
if (params.time) {
|
|
602
|
+
$scope.showTime = true;
|
|
603
|
+
that.initHours();
|
|
604
|
+
}
|
|
605
|
+
}
|
|
606
|
+
},
|
|
607
|
+
_onBackgroundClick: function (e) {
|
|
608
|
+
e.stopPropagation();
|
|
609
|
+
that.hide();
|
|
610
|
+
},
|
|
611
|
+
_onElementClick: function (e) {
|
|
612
|
+
e.stopPropagation();
|
|
613
|
+
},
|
|
614
|
+
_onCloseClick: function () {
|
|
615
|
+
that.hide();
|
|
616
|
+
if ($scope.closed) $scope.closed(true);
|
|
617
|
+
},
|
|
618
|
+
_onOKClick: function () {
|
|
619
|
+
switch ($scope.currentView) {
|
|
620
|
+
case 0:
|
|
621
|
+
if (params.time === true) {
|
|
622
|
+
that.initHours();
|
|
623
|
+
} else {
|
|
624
|
+
that.setElementValue();
|
|
625
|
+
that.setDateModel();
|
|
626
|
+
if (!$scope.inline)
|
|
627
|
+
that.hide();
|
|
628
|
+
}
|
|
629
|
+
break;
|
|
630
|
+
case 1:
|
|
631
|
+
that.initMinutes();
|
|
632
|
+
break;
|
|
633
|
+
case 2:
|
|
634
|
+
that.setElementValue();
|
|
635
|
+
that.setDateModel();
|
|
636
|
+
if ($scope.inline) {
|
|
637
|
+
that._onClick();
|
|
638
|
+
} else {
|
|
639
|
+
that.hide();
|
|
640
|
+
}
|
|
641
|
+
break;
|
|
642
|
+
}
|
|
643
|
+
},
|
|
644
|
+
_onCancelClick: function () {
|
|
645
|
+
if (params.time) {
|
|
646
|
+
switch ($scope.currentView) {
|
|
647
|
+
case 0:
|
|
648
|
+
that.hide();
|
|
649
|
+
break;
|
|
650
|
+
case 1:
|
|
651
|
+
if (params.date) {
|
|
652
|
+
that.initDate();
|
|
653
|
+
} else {
|
|
654
|
+
that.hide();
|
|
655
|
+
}
|
|
656
|
+
break;
|
|
657
|
+
case 2:
|
|
658
|
+
that.initHours();
|
|
659
|
+
break;
|
|
660
|
+
}
|
|
661
|
+
} else {
|
|
662
|
+
that.hide();
|
|
663
|
+
}
|
|
664
|
+
},
|
|
665
|
+
_onMonthBeforeClick: function () {
|
|
666
|
+
if ($scope.btnMonthBeforeEnabled) {
|
|
667
|
+
$scope.currentDate.subtract(1, 'months');
|
|
668
|
+
that.initDate($scope.currentDate);
|
|
669
|
+
}
|
|
670
|
+
},
|
|
671
|
+
_onMonthAfterClick: function () {
|
|
672
|
+
if ($scope.btnMonthAfterEnabled) {
|
|
673
|
+
$scope.currentDate.add(1, 'months');
|
|
674
|
+
that.initDate($scope.currentDate);
|
|
675
|
+
}
|
|
676
|
+
},
|
|
677
|
+
_onYearBeforeClick: function () {
|
|
678
|
+
if ($scope.btnYearBeforeEnabled) {
|
|
679
|
+
$scope.currentDate.subtract(1, 'years');
|
|
680
|
+
that.initDate($scope.currentDate);
|
|
681
|
+
}
|
|
682
|
+
},
|
|
683
|
+
_onYearAfterClick: function () {
|
|
684
|
+
if ($scope.btnYearAfterEnabled) {
|
|
685
|
+
$scope.currentDate.add(1, 'years');
|
|
686
|
+
that.initDate($scope.currentDate);
|
|
687
|
+
}
|
|
688
|
+
},
|
|
689
|
+
_onSelectDate: function (date) {
|
|
690
|
+
// remove selected from all dates in $scope.weeks
|
|
691
|
+
angular.forEach($scope.weeks, function (week, weekKey) {
|
|
692
|
+
angular.forEach($scope.weeks[weekKey], function (day, dayKey) {
|
|
693
|
+
$scope.weeks[weekKey][dayKey].selected = false;
|
|
694
|
+
});
|
|
695
|
+
});
|
|
696
|
+
date.selected = true;
|
|
697
|
+
that.selectDate(date.data);
|
|
698
|
+
|
|
699
|
+
if (!params.enableOkButtons) {
|
|
700
|
+
that._onOKClick();
|
|
701
|
+
}
|
|
702
|
+
},
|
|
703
|
+
_onSelectHour: function (hourSelected) {
|
|
704
|
+
|
|
705
|
+
if (!hourSelected.disabled) {
|
|
706
|
+
// remove selected from all dates in $scope.weeks
|
|
707
|
+
angular.forEach($scope.hours, function (hour, hourKey) {
|
|
708
|
+
$scope.hours[hourKey].selected = false;
|
|
709
|
+
});
|
|
710
|
+
hourSelected.selected = true;
|
|
711
|
+
|
|
712
|
+
let dataHour = parseInt(hourSelected.h);
|
|
713
|
+
if (that.isPM())
|
|
714
|
+
dataHour += 12;
|
|
715
|
+
|
|
716
|
+
$scope.currentDate.hour(dataHour);
|
|
717
|
+
that.showTime($scope.currentDate);
|
|
718
|
+
|
|
719
|
+
that.animateHands();
|
|
720
|
+
if (!params.enableOkButtons) {
|
|
721
|
+
that._onOKClick();
|
|
722
|
+
}
|
|
723
|
+
} else {
|
|
724
|
+
//console.log('hour disabled');
|
|
725
|
+
}
|
|
726
|
+
},
|
|
727
|
+
_onSelectMinute: function (minuteSelected) {
|
|
728
|
+
|
|
729
|
+
if (!minuteSelected.disabled) {
|
|
730
|
+
// remove selected from all minutes in $scope.minutes
|
|
731
|
+
angular.forEach($scope.minutes, function (minute, minuteKey) {
|
|
732
|
+
$scope.minutes[minuteKey].selected = false;
|
|
733
|
+
});
|
|
734
|
+
minuteSelected.selected = true;
|
|
735
|
+
|
|
736
|
+
|
|
737
|
+
$scope.currentDate.minute(parseInt(minuteSelected.m));
|
|
738
|
+
that.showTime($scope.currentDate);
|
|
739
|
+
|
|
740
|
+
that.animateHands();
|
|
741
|
+
if (!params.enableOkButtons) {
|
|
742
|
+
that._onOKClick();
|
|
743
|
+
}
|
|
744
|
+
}
|
|
745
|
+
},
|
|
746
|
+
convertHours: function (h) {
|
|
747
|
+
let _return = h;
|
|
748
|
+
|
|
749
|
+
if ((h < 12) && that.isPM())
|
|
750
|
+
_return += 12;
|
|
751
|
+
|
|
752
|
+
return _return;
|
|
753
|
+
},
|
|
754
|
+
setDate: function (date) {
|
|
755
|
+
//console.log('setDate');
|
|
756
|
+
params.currentDate = date;
|
|
757
|
+
that.initDates();
|
|
758
|
+
},
|
|
759
|
+
setMinDate: function (date) {
|
|
760
|
+
params.minDate = date;
|
|
761
|
+
that.initDates();
|
|
762
|
+
},
|
|
763
|
+
setMaxDate: function (date) {
|
|
764
|
+
params.maxDate = date;
|
|
765
|
+
that.initDates();
|
|
766
|
+
},
|
|
767
|
+
show: function () {
|
|
768
|
+
$scope.showDtp = true;
|
|
769
|
+
that._centerBox();
|
|
770
|
+
},
|
|
771
|
+
hide: function () {
|
|
772
|
+
$scope.showDtp = false;
|
|
773
|
+
},
|
|
774
|
+
resetDate: function () {
|
|
775
|
+
|
|
776
|
+
},
|
|
777
|
+
_centerBox: function () {
|
|
778
|
+
//var h = (this.$dtpElement.height() - this.$dtpElement.find('.dtp-content').height()) / 2;
|
|
779
|
+
//this.$dtpElement.find('.dtp-content').css('marginLeft', -(this.$dtpElement.find('.dtp-content').width() / 2) + 'px');
|
|
780
|
+
//this.$dtpElement.find('.dtp-content').css('top', h + 'px');
|
|
781
|
+
}
|
|
782
|
+
};
|
|
783
|
+
|
|
784
|
+
$scope.onClick = that._onClick;
|
|
785
|
+
$scope.onOKClick = that._onOKClick;
|
|
786
|
+
$scope.onCancelClick = that._onCancelClick;
|
|
787
|
+
$scope.onCloseClick = that._onCloseClick;
|
|
788
|
+
|
|
789
|
+
$scope.onSelectDate = that._onSelectDate;
|
|
790
|
+
$scope.onMonthBeforeClick = that._onMonthBeforeClick;
|
|
791
|
+
$scope.onMonthAfterClick = that._onMonthAfterClick;
|
|
792
|
+
$scope.onYearBeforeClick = that._onYearBeforeClick;
|
|
793
|
+
$scope.onYearAfterClick = that._onYearAfterClick;
|
|
794
|
+
|
|
795
|
+
$scope.onSelectHour = that._onSelectHour;
|
|
796
|
+
$scope.onSelectMinute = that._onSelectMinute;
|
|
797
|
+
|
|
798
|
+
$scope.initDate = that.initDate;
|
|
799
|
+
$scope.initHours = that.initHours;
|
|
800
|
+
$scope.initMinutes = that.initMinutes;
|
|
801
|
+
|
|
802
|
+
prepareAttrs();
|
|
803
|
+
that.init();
|
|
804
|
+
|
|
805
|
+
if ($scope.inline) {
|
|
806
|
+
//console.log('auto show inline');
|
|
807
|
+
that._onClick();
|
|
808
|
+
}
|
|
809
|
+
|
|
810
|
+
$scope.$on('dtp-open-click', function () {
|
|
811
|
+
that._onClick();
|
|
812
|
+
});
|
|
813
|
+
|
|
814
|
+
$scope.$on('dtp-close-click', function () {
|
|
815
|
+
that.hide();
|
|
816
|
+
});
|
|
817
|
+
|
|
818
|
+
$scope.$watch('model', function (newDate) {
|
|
819
|
+
$scope.currentDate = newDate;
|
|
820
|
+
that.showDate($scope.currentDate);
|
|
821
|
+
that.initDate();
|
|
822
|
+
});
|
|
823
|
+
|
|
824
|
+
|
|
825
|
+
// Close the dropdown if clicked outside
|
|
826
|
+
//$document.bind('click', function(event){
|
|
827
|
+
// console.log($element.find(event.target));
|
|
828
|
+
// var isClickedElementChildOfPopup = $element.find(event.target).length == 0;
|
|
829
|
+
// if (isClickedElementChildOfPopup){
|
|
830
|
+
// that.hide();
|
|
831
|
+
// }
|
|
832
|
+
//});
|
|
833
|
+
}
|
|
834
|
+
};
|
|
835
|
+
|
|
836
836
|
});
|