nice-elements 1.10.5 → 1.10.6
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 +17 -17
- package/CHANGELOG.md +444 -440
- package/LICENSE.md +21 -21
- package/README.md +95 -95
- package/bower.json +10 -10
- package/dist/nice.js +8074 -8114
- package/dist/nice.min.js +1 -1
- package/dist/style.css +7 -7
- package/dist/style.min.css +7 -7
- package/eslint.config.mjs +27 -27
- package/package.json +45 -45
- package/src/components/nice-button/nice-button.html +4 -4
- package/src/components/nice-button/nice-button.js +40 -40
- 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 +336 -336
- package/src/components/nice-calendar/nice-calendar.scss +285 -285
- package/src/components/nice-checkbox/nice-checkbox.html +5 -5
- package/src/components/nice-checkbox/nice-checkbox.js +34 -34
- package/src/components/nice-checkbox/nice-checkbox.scss +91 -91
- 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-click-outside/nice-click-outside.js +105 -105
- 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 +75 -75
- package/src/components/nice-date/nice-date.js +329 -329
- package/src/components/nice-date/nice-date.scss +302 -302
- package/src/components/nice-date-input/nice-date-input.html +41 -41
- package/src/components/nice-date-input/nice-date-input.js +111 -111
- package/src/components/nice-date-input/nice-date-input.scss +45 -45
- 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 +174 -174
- 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 +496 -496
- package/src/components/nice-dropdown/nice-dropdown.scss +261 -261
- package/src/components/nice-dropdown-date/nice-dropdown-date.html +28 -28
- package/src/components/nice-dropdown-date/nice-dropdown-date.js +128 -128
- package/src/components/nice-dropdown-date/nice-dropdown-date.scss +82 -82
- package/src/components/nice-dropdown-old/nice-dropdown-old.html +44 -44
- package/src/components/nice-dropdown-old/nice-dropdown-old.js +331 -331
- 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 +55 -55
- package/src/components/nice-help/nice-help.scss +78 -78
- package/src/components/nice-input/nice-input.html +48 -48
- package/src/components/nice-input/nice-input.js +245 -245
- 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 +30 -30
- 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 +170 -170
- package/src/components/nice-number/nice-number.scss +18 -18
- 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 +240 -240
- 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 +265 -265
- 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 +1262 -1262
- package/src/components/nice-svgs/nice-svgs.js +16 -16
- 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 +111 -111
- 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 +3 -3
- package/src/components/nice-title/nice-title.js +21 -21
- 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 +54 -54
- package/src/components/nice-toggle/nice-toggle.scss +131 -131
- package/src/components/nice-tooltip/_nice-tooltip.scss +71 -71
- package/src/components/nice-tooltip/nice-tooltip.js +23 -23
- package/src/components/nice-upload/nice-upload.html +22 -22
- package/src/components/nice-upload/nice-upload.js +159 -159
- package/src/components/nice-upload/nice-upload.scss +85 -85
- 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/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 +471 -471
- package/src/styles/_nice-ngdialog.scss +85 -85
- package/src/styles/_nice-spacing.scss +283 -283
- package/src/styles/_nice.scss +67 -67
- package/src/styles/_variables.scss +198 -198
|
@@ -1,329 +1,329 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* @ngdoc directive
|
|
5
|
-
* @name niceElements.directive:niceDate
|
|
6
|
-
* @description
|
|
7
|
-
* # niceDate
|
|
8
|
-
*/
|
|
9
|
-
angular.module('niceElements')
|
|
10
|
-
.directive('niceDate', function () {
|
|
11
|
-
return {
|
|
12
|
-
restrict: 'E',
|
|
13
|
-
replace: true,
|
|
14
|
-
transclude: true,
|
|
15
|
-
templateUrl: 'src/components/nice-date/nice-date.html',
|
|
16
|
-
scope: {
|
|
17
|
-
niceTitle: '@',
|
|
18
|
-
title: '@', // default: ''
|
|
19
|
-
noMargin: '@', // default: false, if noMargin==true then entire directive can be injected inside other divs
|
|
20
|
-
fieldWidth: '@', // default: 'col-sm-8', bootstrap classes that defines width of field
|
|
21
|
-
labelWidth: '@', // default: 'col-sm-4', bootstrap classes that defines width of label
|
|
22
|
-
model: '=',
|
|
23
|
-
time: '=?',
|
|
24
|
-
date: '=?',
|
|
25
|
-
help: '@',
|
|
26
|
-
inline: '@',
|
|
27
|
-
maxDate: '=',
|
|
28
|
-
minDate: '=',
|
|
29
|
-
nextDate: '=',
|
|
30
|
-
isDisabled: '=',
|
|
31
|
-
isInline: '=',
|
|
32
|
-
onChange: '&?',
|
|
33
|
-
required: '='
|
|
34
|
-
},
|
|
35
|
-
controller: function ($scope, $element, $timeout, gettextCatalog) {
|
|
36
|
-
$scope.isOpen = false;
|
|
37
|
-
if ($scope.date == undefined) $scope.date = true;
|
|
38
|
-
if ($scope.time == undefined) $scope.time = false;
|
|
39
|
-
$scope.hours = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23];
|
|
40
|
-
$scope.minutes = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59];
|
|
41
|
-
$scope.translations = {
|
|
42
|
-
nextMonth: gettextCatalog.getString("Next month", null, "Nice"),
|
|
43
|
-
prevMonth: gettextCatalog.getString("Previous month", null, "Nice"),
|
|
44
|
-
};
|
|
45
|
-
if (!$scope.model) $scope.model = moment();
|
|
46
|
-
$scope.innerDate = {
|
|
47
|
-
month: 0,
|
|
48
|
-
year: 0,
|
|
49
|
-
minute: 0,
|
|
50
|
-
hour: 0,
|
|
51
|
-
date: moment(),
|
|
52
|
-
value: ""
|
|
53
|
-
};
|
|
54
|
-
$scope.days = [];
|
|
55
|
-
|
|
56
|
-
// $scope.weekdays = moment.weekdaysShort(false);
|
|
57
|
-
$scope.weekdays = [
|
|
58
|
-
gettextCatalog.getString("Mon", null, "Nice"),
|
|
59
|
-
gettextCatalog.getString("Tue", null, "Nice"),
|
|
60
|
-
gettextCatalog.getString("Wed", null, "Nice"),
|
|
61
|
-
gettextCatalog.getString("Thu", null, "Nice"),
|
|
62
|
-
gettextCatalog.getString("Fri", null, "Nice"),
|
|
63
|
-
gettextCatalog.getString("Sat", null, "Nice"),
|
|
64
|
-
gettextCatalog.getString("Sun", null, "Nice")
|
|
65
|
-
];
|
|
66
|
-
|
|
67
|
-
$scope.years = [];
|
|
68
|
-
var year = moment().year() - 100;
|
|
69
|
-
for (var i = 0; i < 200; i++) {
|
|
70
|
-
$scope.years.push(year + i);
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
$scope.months = [
|
|
74
|
-
{ value: 0, name: gettextCatalog.getString("January", null, "Nice") },
|
|
75
|
-
{ value: 1, name: gettextCatalog.getString("February", null, "Nice") },
|
|
76
|
-
{ value: 2, name: gettextCatalog.getString("March", null, "Nice") },
|
|
77
|
-
{ value: 3, name: gettextCatalog.getString("April", null, "Nice") },
|
|
78
|
-
{ value: 4, name: gettextCatalog.getString("May", null, "Nice") },
|
|
79
|
-
{ value: 5, name: gettextCatalog.getString("June", null, "Nice") },
|
|
80
|
-
{ value: 6, name: gettextCatalog.getString("July", null, "Nice") },
|
|
81
|
-
{ value: 7, name: gettextCatalog.getString("August", null, "Nice") },
|
|
82
|
-
{ value: 8, name: gettextCatalog.getString("September", null, "Nice") },
|
|
83
|
-
{ value: 9, name: gettextCatalog.getString("October", null, "Nice") },
|
|
84
|
-
{ value: 10, name: gettextCatalog.getString("November", null, "Nice") },
|
|
85
|
-
{ value: 11, name: gettextCatalog.getString("December", null, "Nice") }
|
|
86
|
-
]
|
|
87
|
-
|
|
88
|
-
if ($scope.maxDate) $scope.maxDate = moment($scope.maxDate);
|
|
89
|
-
if ($scope.minDate) $scope.minDate = moment($scope.minDate);
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
// Setup popper
|
|
93
|
-
// https://popper.js.org/docs/v2/constructors/
|
|
94
|
-
$scope.setupPopper = function () {
|
|
95
|
-
var button = $element[0].getElementsByClassName('nice-date-button')[0];
|
|
96
|
-
var tooltip = $element[0].getElementsByClassName('nice-date-dropdown-wrapper')[0];
|
|
97
|
-
$scope.popper = Popper.createPopper(button, tooltip, {
|
|
98
|
-
strategy: 'fixed',
|
|
99
|
-
placement: 'bottom-start',
|
|
100
|
-
modifiers: [
|
|
101
|
-
{
|
|
102
|
-
name: 'offset',
|
|
103
|
-
options: {
|
|
104
|
-
offset: [0, 5],
|
|
105
|
-
},
|
|
106
|
-
}
|
|
107
|
-
],
|
|
108
|
-
});
|
|
109
|
-
};
|
|
110
|
-
|
|
111
|
-
$timeout(function () {
|
|
112
|
-
if (!$scope.inline) $scope.setupPopper();
|
|
113
|
-
});
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
// ------------------ Time changes ------------------
|
|
117
|
-
$scope.timeChange = function () {
|
|
118
|
-
var selectedDate = angular.copy($scope.model);
|
|
119
|
-
selectedDate = $scope._removeTime(selectedDate);
|
|
120
|
-
selectedDate.hours($scope.innerDate.hour);
|
|
121
|
-
selectedDate.minutes($scope.innerDate.minute);
|
|
122
|
-
$scope.innerDate.value = $scope.formatDate(selectedDate);
|
|
123
|
-
|
|
124
|
-
$scope.model = angular.copy(selectedDate);
|
|
125
|
-
if ($scope.onChange) $scope.onChange({ model: $scope.model });
|
|
126
|
-
$scope.forma.$setDirty();
|
|
127
|
-
};
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
// ------------------ Day was selected ------------------
|
|
131
|
-
$scope.select = function (day) {
|
|
132
|
-
if (!day.isDisabled) {
|
|
133
|
-
var selectedDate = angular.copy(day.date);
|
|
134
|
-
selectedDate.hours($scope.innerDate.hour);
|
|
135
|
-
selectedDate.minutes($scope.innerDate.minute);
|
|
136
|
-
|
|
137
|
-
$scope.model = angular.copy(selectedDate);
|
|
138
|
-
if ($scope.onChange) $scope.onChange({ model: $scope.model });
|
|
139
|
-
$scope.forma.$setDirty();
|
|
140
|
-
}
|
|
141
|
-
};
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
// ------------------ Handle date change ------------------
|
|
145
|
-
$scope.handleDateChange = function () {
|
|
146
|
-
$scope.innerDate.date.year($scope.innerDate.year);
|
|
147
|
-
$scope.innerDate.date.month($scope.innerDate.month);
|
|
148
|
-
$scope._buildMonth();
|
|
149
|
-
};
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
// ------------------ Set inner date ------------------
|
|
153
|
-
$scope.setInnerDate = function (date) {
|
|
154
|
-
$scope.innerDate.year = date.year();
|
|
155
|
-
$scope.innerDate.month = date.month();
|
|
156
|
-
$scope.innerDate.date = date;
|
|
157
|
-
};
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
// ------------------ Today ------------------
|
|
161
|
-
$scope.today = function () {
|
|
162
|
-
$scope.setInnerDate(moment());
|
|
163
|
-
$scope._buildMonth();
|
|
164
|
-
};
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
// ------------------ Go to next month ------------------
|
|
168
|
-
$scope.next = function () {
|
|
169
|
-
$scope.innerDate.date.add(1, "month");
|
|
170
|
-
$scope.setInnerDate($scope.innerDate.date);
|
|
171
|
-
$scope._buildMonth();
|
|
172
|
-
};
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
// ------------------ Go to previous month ------------------
|
|
176
|
-
$scope.previous = function () {
|
|
177
|
-
$scope.innerDate.date.subtract(1, "month");
|
|
178
|
-
$scope.setInnerDate($scope.innerDate.date);
|
|
179
|
-
$scope._buildMonth();
|
|
180
|
-
};
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
// ------------------ Check if dates are equal without time ------------------
|
|
184
|
-
$scope.isSameDay = function (date1, date2) {
|
|
185
|
-
date1 = moment(date1);
|
|
186
|
-
date2 = moment(date2);
|
|
187
|
-
return (
|
|
188
|
-
date1.date() == date2.date() &&
|
|
189
|
-
date1.month() == date2.month() &&
|
|
190
|
-
date1.year() == date2.year()
|
|
191
|
-
);
|
|
192
|
-
};
|
|
193
|
-
|
|
194
|
-
// ------------------ Check month ------------------
|
|
195
|
-
$scope.isSameMonth = function (date1, date2) {
|
|
196
|
-
date1 = moment(date1);
|
|
197
|
-
date2 = moment(date2);
|
|
198
|
-
return (
|
|
199
|
-
date1.month() == date2.month() &&
|
|
200
|
-
date1.year() == date2.year()
|
|
201
|
-
);
|
|
202
|
-
};
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
$scope.isBetween = function (date1, date2, date3) {
|
|
206
|
-
if (!$scope.nextDate) {
|
|
207
|
-
return false;
|
|
208
|
-
} else if ($scope.isSameDay(date1, date2) || $scope.isSameDay(date1, date3)) {
|
|
209
|
-
return true;
|
|
210
|
-
} else if (date2.isBefore(date3)) {
|
|
211
|
-
return $scope._removeTime(date1).isBetween(date2, date3);
|
|
212
|
-
} else {
|
|
213
|
-
return $scope._removeTime(date1).isBetween(date3, date2);
|
|
214
|
-
}
|
|
215
|
-
};
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
// ------------------ Format date ------------------
|
|
219
|
-
$scope.formatDate = function (date) {
|
|
220
|
-
if ($scope.time) return date.format('D.M.YYYY • H:mm');
|
|
221
|
-
else return date.format('D.M.YYYY');
|
|
222
|
-
};
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
// ------------------ Remove time from date ------------------
|
|
226
|
-
$scope._removeTime = function (date) {
|
|
227
|
-
if (!date) return date;
|
|
228
|
-
return date.hour(0).minute(0).second(0).millisecond(0);
|
|
229
|
-
};
|
|
230
|
-
|
|
231
|
-
$scope._removeTimeWithDate = function (date) {
|
|
232
|
-
return date.date(0).hour(0).minute(0).second(0).millisecond(0);
|
|
233
|
-
};
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
// ------------------ Build month ------------------
|
|
237
|
-
$scope._buildMonth = function () {
|
|
238
|
-
var done = false;
|
|
239
|
-
var date = angular.copy($scope.innerDate.date).date(0).startOf('week').isoWeekday(1);
|
|
240
|
-
var monthIndex = date.month();
|
|
241
|
-
var count = 0;
|
|
242
|
-
|
|
243
|
-
date.add(1, "w");
|
|
244
|
-
|
|
245
|
-
$scope.weeks = [];
|
|
246
|
-
while (!done) {
|
|
247
|
-
$scope.weeks.push({ days: $scope._buildWeek(date.clone()) });
|
|
248
|
-
date.add(1, "w");
|
|
249
|
-
done = count++ > 2 && monthIndex !== date.month();
|
|
250
|
-
monthIndex = date.month();
|
|
251
|
-
}
|
|
252
|
-
};
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
// ------------------ Build week ------------------
|
|
256
|
-
$scope._buildWeek = function (date) {
|
|
257
|
-
var days = [];
|
|
258
|
-
for (var i = 0; i < 7; i++) {
|
|
259
|
-
var day = {
|
|
260
|
-
name: date.format("dd"),
|
|
261
|
-
number: date.date(),
|
|
262
|
-
isCurrentMonth: $scope.isSameMonth(date, $scope.innerDate.date),
|
|
263
|
-
isToday: date.isSame(new Date(), "day"),
|
|
264
|
-
isWeekday: date.weekday() == 6 || date.weekday() == 0,
|
|
265
|
-
value: date.format('D.M.YYYY'),
|
|
266
|
-
date: date
|
|
267
|
-
};
|
|
268
|
-
|
|
269
|
-
if ($scope.minDate) day.isDisabled = date.isBefore($scope.minDate);
|
|
270
|
-
if ($scope.maxDate) day.isDisabled = date.isAfter($scope.maxDate);
|
|
271
|
-
if ($scope.minDate && $scope.maxDate) day.isDisabled = !date.isBetween($scope.minDate, $scope.maxDate);
|
|
272
|
-
|
|
273
|
-
days.push(day);
|
|
274
|
-
date = date.clone();
|
|
275
|
-
date.add(1, "d");
|
|
276
|
-
}
|
|
277
|
-
|
|
278
|
-
return days;
|
|
279
|
-
};
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
// ------------------ Watch for model change ------------------
|
|
283
|
-
$scope.$watchGroup(["model", 'minDate', 'maxDate', 'nextDate'], function (value) {
|
|
284
|
-
$scope.boostrap();
|
|
285
|
-
});
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
// ------------------ Get time ------------------
|
|
289
|
-
$scope.getTime = function () {
|
|
290
|
-
if ($scope.time) {
|
|
291
|
-
$scope.innerDate.hour = moment($scope.model).hours();
|
|
292
|
-
$scope.innerDate.minute = moment($scope.model).minutes();
|
|
293
|
-
} else {
|
|
294
|
-
$scope.innerDate.hour = 0;
|
|
295
|
-
$scope.innerDate.minute = 0;
|
|
296
|
-
}
|
|
297
|
-
|
|
298
|
-
$scope.innerDate.value = $scope.formatDate($scope.innerDate.date);
|
|
299
|
-
};
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
// ------------------ Bootstrap ------------------
|
|
303
|
-
$scope.boostrap = function () {
|
|
304
|
-
$scope.setInnerDate(moment($scope.model));
|
|
305
|
-
$scope.getTime();
|
|
306
|
-
|
|
307
|
-
if (!$scope.time) {
|
|
308
|
-
$scope.model = $scope._removeTime($scope.model);
|
|
309
|
-
}
|
|
310
|
-
|
|
311
|
-
$scope.innerDate.value = $scope.formatDate(moment($scope.model));
|
|
312
|
-
$scope._buildMonth();
|
|
313
|
-
};
|
|
314
|
-
|
|
315
|
-
$scope.boostrap();
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
// ------------------ Toggle open ------------------
|
|
319
|
-
$scope.toggleOpen = function () {
|
|
320
|
-
if (!$scope.isDisabled) {
|
|
321
|
-
$scope.isOpen = !$scope.isOpen;
|
|
322
|
-
$timeout(function () {
|
|
323
|
-
if ($scope.popper) $scope.popper.update();
|
|
324
|
-
})
|
|
325
|
-
}
|
|
326
|
-
};
|
|
327
|
-
}
|
|
328
|
-
};
|
|
329
|
-
});
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @ngdoc directive
|
|
5
|
+
* @name niceElements.directive:niceDate
|
|
6
|
+
* @description
|
|
7
|
+
* # niceDate
|
|
8
|
+
*/
|
|
9
|
+
angular.module('niceElements')
|
|
10
|
+
.directive('niceDate', function () {
|
|
11
|
+
return {
|
|
12
|
+
restrict: 'E',
|
|
13
|
+
replace: true,
|
|
14
|
+
transclude: true,
|
|
15
|
+
templateUrl: 'src/components/nice-date/nice-date.html',
|
|
16
|
+
scope: {
|
|
17
|
+
niceTitle: '@',
|
|
18
|
+
title: '@', // default: ''
|
|
19
|
+
noMargin: '@', // default: false, if noMargin==true then entire directive can be injected inside other divs
|
|
20
|
+
fieldWidth: '@', // default: 'col-sm-8', bootstrap classes that defines width of field
|
|
21
|
+
labelWidth: '@', // default: 'col-sm-4', bootstrap classes that defines width of label
|
|
22
|
+
model: '=',
|
|
23
|
+
time: '=?',
|
|
24
|
+
date: '=?',
|
|
25
|
+
help: '@',
|
|
26
|
+
inline: '@',
|
|
27
|
+
maxDate: '=',
|
|
28
|
+
minDate: '=',
|
|
29
|
+
nextDate: '=',
|
|
30
|
+
isDisabled: '=',
|
|
31
|
+
isInline: '=',
|
|
32
|
+
onChange: '&?',
|
|
33
|
+
required: '='
|
|
34
|
+
},
|
|
35
|
+
controller: function ($scope, $element, $timeout, gettextCatalog) {
|
|
36
|
+
$scope.isOpen = false;
|
|
37
|
+
if ($scope.date == undefined) $scope.date = true;
|
|
38
|
+
if ($scope.time == undefined) $scope.time = false;
|
|
39
|
+
$scope.hours = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23];
|
|
40
|
+
$scope.minutes = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59];
|
|
41
|
+
$scope.translations = {
|
|
42
|
+
nextMonth: gettextCatalog.getString("Next month", null, "Nice"),
|
|
43
|
+
prevMonth: gettextCatalog.getString("Previous month", null, "Nice"),
|
|
44
|
+
};
|
|
45
|
+
if (!$scope.model) $scope.model = moment();
|
|
46
|
+
$scope.innerDate = {
|
|
47
|
+
month: 0,
|
|
48
|
+
year: 0,
|
|
49
|
+
minute: 0,
|
|
50
|
+
hour: 0,
|
|
51
|
+
date: moment(),
|
|
52
|
+
value: ""
|
|
53
|
+
};
|
|
54
|
+
$scope.days = [];
|
|
55
|
+
|
|
56
|
+
// $scope.weekdays = moment.weekdaysShort(false);
|
|
57
|
+
$scope.weekdays = [
|
|
58
|
+
gettextCatalog.getString("Mon", null, "Nice"),
|
|
59
|
+
gettextCatalog.getString("Tue", null, "Nice"),
|
|
60
|
+
gettextCatalog.getString("Wed", null, "Nice"),
|
|
61
|
+
gettextCatalog.getString("Thu", null, "Nice"),
|
|
62
|
+
gettextCatalog.getString("Fri", null, "Nice"),
|
|
63
|
+
gettextCatalog.getString("Sat", null, "Nice"),
|
|
64
|
+
gettextCatalog.getString("Sun", null, "Nice")
|
|
65
|
+
];
|
|
66
|
+
|
|
67
|
+
$scope.years = [];
|
|
68
|
+
var year = moment().year() - 100;
|
|
69
|
+
for (var i = 0; i < 200; i++) {
|
|
70
|
+
$scope.years.push(year + i);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
$scope.months = [
|
|
74
|
+
{ value: 0, name: gettextCatalog.getString("January", null, "Nice") },
|
|
75
|
+
{ value: 1, name: gettextCatalog.getString("February", null, "Nice") },
|
|
76
|
+
{ value: 2, name: gettextCatalog.getString("March", null, "Nice") },
|
|
77
|
+
{ value: 3, name: gettextCatalog.getString("April", null, "Nice") },
|
|
78
|
+
{ value: 4, name: gettextCatalog.getString("May", null, "Nice") },
|
|
79
|
+
{ value: 5, name: gettextCatalog.getString("June", null, "Nice") },
|
|
80
|
+
{ value: 6, name: gettextCatalog.getString("July", null, "Nice") },
|
|
81
|
+
{ value: 7, name: gettextCatalog.getString("August", null, "Nice") },
|
|
82
|
+
{ value: 8, name: gettextCatalog.getString("September", null, "Nice") },
|
|
83
|
+
{ value: 9, name: gettextCatalog.getString("October", null, "Nice") },
|
|
84
|
+
{ value: 10, name: gettextCatalog.getString("November", null, "Nice") },
|
|
85
|
+
{ value: 11, name: gettextCatalog.getString("December", null, "Nice") }
|
|
86
|
+
]
|
|
87
|
+
|
|
88
|
+
if ($scope.maxDate) $scope.maxDate = moment($scope.maxDate);
|
|
89
|
+
if ($scope.minDate) $scope.minDate = moment($scope.minDate);
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
// Setup popper
|
|
93
|
+
// https://popper.js.org/docs/v2/constructors/
|
|
94
|
+
$scope.setupPopper = function () {
|
|
95
|
+
var button = $element[0].getElementsByClassName('nice-date-button')[0];
|
|
96
|
+
var tooltip = $element[0].getElementsByClassName('nice-date-dropdown-wrapper')[0];
|
|
97
|
+
$scope.popper = Popper.createPopper(button, tooltip, {
|
|
98
|
+
strategy: 'fixed',
|
|
99
|
+
placement: 'bottom-start',
|
|
100
|
+
modifiers: [
|
|
101
|
+
{
|
|
102
|
+
name: 'offset',
|
|
103
|
+
options: {
|
|
104
|
+
offset: [0, 5],
|
|
105
|
+
},
|
|
106
|
+
}
|
|
107
|
+
],
|
|
108
|
+
});
|
|
109
|
+
};
|
|
110
|
+
|
|
111
|
+
$timeout(function () {
|
|
112
|
+
if (!$scope.inline) $scope.setupPopper();
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
|
|
116
|
+
// ------------------ Time changes ------------------
|
|
117
|
+
$scope.timeChange = function () {
|
|
118
|
+
var selectedDate = angular.copy($scope.model);
|
|
119
|
+
selectedDate = $scope._removeTime(selectedDate);
|
|
120
|
+
selectedDate.hours($scope.innerDate.hour);
|
|
121
|
+
selectedDate.minutes($scope.innerDate.minute);
|
|
122
|
+
$scope.innerDate.value = $scope.formatDate(selectedDate);
|
|
123
|
+
|
|
124
|
+
$scope.model = angular.copy(selectedDate);
|
|
125
|
+
if ($scope.onChange) $scope.onChange({ model: $scope.model });
|
|
126
|
+
$scope.forma.$setDirty();
|
|
127
|
+
};
|
|
128
|
+
|
|
129
|
+
|
|
130
|
+
// ------------------ Day was selected ------------------
|
|
131
|
+
$scope.select = function (day) {
|
|
132
|
+
if (!day.isDisabled) {
|
|
133
|
+
var selectedDate = angular.copy(day.date);
|
|
134
|
+
selectedDate.hours($scope.innerDate.hour);
|
|
135
|
+
selectedDate.minutes($scope.innerDate.minute);
|
|
136
|
+
|
|
137
|
+
$scope.model = angular.copy(selectedDate);
|
|
138
|
+
if ($scope.onChange) $scope.onChange({ model: $scope.model });
|
|
139
|
+
$scope.forma.$setDirty();
|
|
140
|
+
}
|
|
141
|
+
};
|
|
142
|
+
|
|
143
|
+
|
|
144
|
+
// ------------------ Handle date change ------------------
|
|
145
|
+
$scope.handleDateChange = function () {
|
|
146
|
+
$scope.innerDate.date.year($scope.innerDate.year);
|
|
147
|
+
$scope.innerDate.date.month($scope.innerDate.month);
|
|
148
|
+
$scope._buildMonth();
|
|
149
|
+
};
|
|
150
|
+
|
|
151
|
+
|
|
152
|
+
// ------------------ Set inner date ------------------
|
|
153
|
+
$scope.setInnerDate = function (date) {
|
|
154
|
+
$scope.innerDate.year = date.year();
|
|
155
|
+
$scope.innerDate.month = date.month();
|
|
156
|
+
$scope.innerDate.date = date;
|
|
157
|
+
};
|
|
158
|
+
|
|
159
|
+
|
|
160
|
+
// ------------------ Today ------------------
|
|
161
|
+
$scope.today = function () {
|
|
162
|
+
$scope.setInnerDate(moment());
|
|
163
|
+
$scope._buildMonth();
|
|
164
|
+
};
|
|
165
|
+
|
|
166
|
+
|
|
167
|
+
// ------------------ Go to next month ------------------
|
|
168
|
+
$scope.next = function () {
|
|
169
|
+
$scope.innerDate.date.add(1, "month");
|
|
170
|
+
$scope.setInnerDate($scope.innerDate.date);
|
|
171
|
+
$scope._buildMonth();
|
|
172
|
+
};
|
|
173
|
+
|
|
174
|
+
|
|
175
|
+
// ------------------ Go to previous month ------------------
|
|
176
|
+
$scope.previous = function () {
|
|
177
|
+
$scope.innerDate.date.subtract(1, "month");
|
|
178
|
+
$scope.setInnerDate($scope.innerDate.date);
|
|
179
|
+
$scope._buildMonth();
|
|
180
|
+
};
|
|
181
|
+
|
|
182
|
+
|
|
183
|
+
// ------------------ Check if dates are equal without time ------------------
|
|
184
|
+
$scope.isSameDay = function (date1, date2) {
|
|
185
|
+
date1 = moment(date1);
|
|
186
|
+
date2 = moment(date2);
|
|
187
|
+
return (
|
|
188
|
+
date1.date() == date2.date() &&
|
|
189
|
+
date1.month() == date2.month() &&
|
|
190
|
+
date1.year() == date2.year()
|
|
191
|
+
);
|
|
192
|
+
};
|
|
193
|
+
|
|
194
|
+
// ------------------ Check month ------------------
|
|
195
|
+
$scope.isSameMonth = function (date1, date2) {
|
|
196
|
+
date1 = moment(date1);
|
|
197
|
+
date2 = moment(date2);
|
|
198
|
+
return (
|
|
199
|
+
date1.month() == date2.month() &&
|
|
200
|
+
date1.year() == date2.year()
|
|
201
|
+
);
|
|
202
|
+
};
|
|
203
|
+
|
|
204
|
+
|
|
205
|
+
$scope.isBetween = function (date1, date2, date3) {
|
|
206
|
+
if (!$scope.nextDate) {
|
|
207
|
+
return false;
|
|
208
|
+
} else if ($scope.isSameDay(date1, date2) || $scope.isSameDay(date1, date3)) {
|
|
209
|
+
return true;
|
|
210
|
+
} else if (date2.isBefore(date3)) {
|
|
211
|
+
return $scope._removeTime(date1).isBetween(date2, date3);
|
|
212
|
+
} else {
|
|
213
|
+
return $scope._removeTime(date1).isBetween(date3, date2);
|
|
214
|
+
}
|
|
215
|
+
};
|
|
216
|
+
|
|
217
|
+
|
|
218
|
+
// ------------------ Format date ------------------
|
|
219
|
+
$scope.formatDate = function (date) {
|
|
220
|
+
if ($scope.time) return date.format('D.M.YYYY • H:mm');
|
|
221
|
+
else return date.format('D.M.YYYY');
|
|
222
|
+
};
|
|
223
|
+
|
|
224
|
+
|
|
225
|
+
// ------------------ Remove time from date ------------------
|
|
226
|
+
$scope._removeTime = function (date) {
|
|
227
|
+
if (!date) return date;
|
|
228
|
+
return date.hour(0).minute(0).second(0).millisecond(0);
|
|
229
|
+
};
|
|
230
|
+
|
|
231
|
+
$scope._removeTimeWithDate = function (date) {
|
|
232
|
+
return date.date(0).hour(0).minute(0).second(0).millisecond(0);
|
|
233
|
+
};
|
|
234
|
+
|
|
235
|
+
|
|
236
|
+
// ------------------ Build month ------------------
|
|
237
|
+
$scope._buildMonth = function () {
|
|
238
|
+
var done = false;
|
|
239
|
+
var date = angular.copy($scope.innerDate.date).date(0).startOf('week').isoWeekday(1);
|
|
240
|
+
var monthIndex = date.month();
|
|
241
|
+
var count = 0;
|
|
242
|
+
|
|
243
|
+
date.add(1, "w");
|
|
244
|
+
|
|
245
|
+
$scope.weeks = [];
|
|
246
|
+
while (!done) {
|
|
247
|
+
$scope.weeks.push({ days: $scope._buildWeek(date.clone()) });
|
|
248
|
+
date.add(1, "w");
|
|
249
|
+
done = count++ > 2 && monthIndex !== date.month();
|
|
250
|
+
monthIndex = date.month();
|
|
251
|
+
}
|
|
252
|
+
};
|
|
253
|
+
|
|
254
|
+
|
|
255
|
+
// ------------------ Build week ------------------
|
|
256
|
+
$scope._buildWeek = function (date) {
|
|
257
|
+
var days = [];
|
|
258
|
+
for (var i = 0; i < 7; i++) {
|
|
259
|
+
var day = {
|
|
260
|
+
name: date.format("dd"),
|
|
261
|
+
number: date.date(),
|
|
262
|
+
isCurrentMonth: $scope.isSameMonth(date, $scope.innerDate.date),
|
|
263
|
+
isToday: date.isSame(new Date(), "day"),
|
|
264
|
+
isWeekday: date.weekday() == 6 || date.weekday() == 0,
|
|
265
|
+
value: date.format('D.M.YYYY'),
|
|
266
|
+
date: date
|
|
267
|
+
};
|
|
268
|
+
|
|
269
|
+
if ($scope.minDate) day.isDisabled = date.isBefore($scope.minDate);
|
|
270
|
+
if ($scope.maxDate) day.isDisabled = date.isAfter($scope.maxDate);
|
|
271
|
+
if ($scope.minDate && $scope.maxDate) day.isDisabled = !date.isBetween($scope.minDate, $scope.maxDate);
|
|
272
|
+
|
|
273
|
+
days.push(day);
|
|
274
|
+
date = date.clone();
|
|
275
|
+
date.add(1, "d");
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
return days;
|
|
279
|
+
};
|
|
280
|
+
|
|
281
|
+
|
|
282
|
+
// ------------------ Watch for model change ------------------
|
|
283
|
+
$scope.$watchGroup(["model", 'minDate', 'maxDate', 'nextDate'], function (value) {
|
|
284
|
+
$scope.boostrap();
|
|
285
|
+
});
|
|
286
|
+
|
|
287
|
+
|
|
288
|
+
// ------------------ Get time ------------------
|
|
289
|
+
$scope.getTime = function () {
|
|
290
|
+
if ($scope.time) {
|
|
291
|
+
$scope.innerDate.hour = moment($scope.model).hours();
|
|
292
|
+
$scope.innerDate.minute = moment($scope.model).minutes();
|
|
293
|
+
} else {
|
|
294
|
+
$scope.innerDate.hour = 0;
|
|
295
|
+
$scope.innerDate.minute = 0;
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
$scope.innerDate.value = $scope.formatDate($scope.innerDate.date);
|
|
299
|
+
};
|
|
300
|
+
|
|
301
|
+
|
|
302
|
+
// ------------------ Bootstrap ------------------
|
|
303
|
+
$scope.boostrap = function () {
|
|
304
|
+
$scope.setInnerDate(moment($scope.model));
|
|
305
|
+
$scope.getTime();
|
|
306
|
+
|
|
307
|
+
if (!$scope.time) {
|
|
308
|
+
$scope.model = $scope._removeTime($scope.model);
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
$scope.innerDate.value = $scope.formatDate(moment($scope.model));
|
|
312
|
+
$scope._buildMonth();
|
|
313
|
+
};
|
|
314
|
+
|
|
315
|
+
$scope.boostrap();
|
|
316
|
+
|
|
317
|
+
|
|
318
|
+
// ------------------ Toggle open ------------------
|
|
319
|
+
$scope.toggleOpen = function () {
|
|
320
|
+
if (!$scope.isDisabled) {
|
|
321
|
+
$scope.isOpen = !$scope.isOpen;
|
|
322
|
+
$timeout(function () {
|
|
323
|
+
if ($scope.popper) $scope.popper.update();
|
|
324
|
+
})
|
|
325
|
+
}
|
|
326
|
+
};
|
|
327
|
+
}
|
|
328
|
+
};
|
|
329
|
+
});
|