nice-elements 1.10.10 → 1.10.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 +17 -17
- package/CHANGELOG.md +468 -464
- package/LICENSE.md +21 -21
- package/README.md +95 -95
- package/bower.json +10 -10
- package/dist/nice.js +8150 -8110
- 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 +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 +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 +212 -212
- 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 +79 -79
- package/src/components/nice-date/nice-date.js +331 -331
- package/src/components/nice-date/nice-date.scss +305 -305
- 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 +510 -510
- 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 +1275 -1275
- 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 +55 -55
- 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,336 +1,336 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* @ngdoc directive
|
|
5
|
-
* @name niceElements.directive:niceCalendar
|
|
6
|
-
* @description
|
|
7
|
-
* # niceCalendar
|
|
8
|
-
*/
|
|
9
|
-
angular.module('niceElements')
|
|
10
|
-
.directive("niceCalendar", function ($timeout, gettextCatalog) {
|
|
11
|
-
return {
|
|
12
|
-
restrict: "E",
|
|
13
|
-
templateUrl: "src/components/nice-calendar/nice-calendar.html",
|
|
14
|
-
scope: {
|
|
15
|
-
niceTitle: '@',
|
|
16
|
-
title: '@',
|
|
17
|
-
fieldWidth: '@',
|
|
18
|
-
labelWidth: '@',
|
|
19
|
-
minDate: '=',
|
|
20
|
-
maxDate: '=',
|
|
21
|
-
hideHover: '=',
|
|
22
|
-
time: '=',
|
|
23
|
-
noMargin: '@',
|
|
24
|
-
color: '@',
|
|
25
|
-
endDate: '=',
|
|
26
|
-
startDate: '=',
|
|
27
|
-
isDisabled: '=',
|
|
28
|
-
help: '@',
|
|
29
|
-
isInline: '=',
|
|
30
|
-
onChange: '&?',
|
|
31
|
-
required: '='
|
|
32
|
-
},
|
|
33
|
-
link: function (scope, element) {
|
|
34
|
-
// ------------------ Init default values ------------------
|
|
35
|
-
scope.selectStart = true;
|
|
36
|
-
scope.popupText = gettextCatalog.getString("Select start date", null, "Nice");
|
|
37
|
-
|
|
38
|
-
scope.hours = [
|
|
39
|
-
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
|
-
];
|
|
41
|
-
|
|
42
|
-
scope.minutes = [
|
|
43
|
-
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
|
|
44
|
-
];
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
// ------------------ Check if attributes are set ------------------
|
|
48
|
-
if (!scope.startDate) scope.startDate = moment().minutes(0).second(0).millisecond(0);
|
|
49
|
-
if (!scope.endDate) scope.endDate = moment().minutes(0).second(0).millisecond(0);
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
// ------------------ Look for model changes ------------------
|
|
53
|
-
scope.$watch("startDate", function (value, valueOld) {
|
|
54
|
-
bootstrap();
|
|
55
|
-
});
|
|
56
|
-
|
|
57
|
-
scope.$watch("endDate", function (value, valueOld) {
|
|
58
|
-
bootstrap();
|
|
59
|
-
});
|
|
60
|
-
|
|
61
|
-
scope.$watch("minDate", function (value, valueOld) {
|
|
62
|
-
bootstrap();
|
|
63
|
-
});
|
|
64
|
-
|
|
65
|
-
scope.$watch("maxDate", function (value, valueOld) {
|
|
66
|
-
bootstrap();
|
|
67
|
-
});
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
// ------------------ Bootstrap calendar ------------------
|
|
71
|
-
function bootstrap() {
|
|
72
|
-
// scope.startDate = moment(scope.startDate.second(0).millisecond(0));
|
|
73
|
-
// scope.endDate = moment(scope.endDate.second(0).millisecond(0));
|
|
74
|
-
|
|
75
|
-
if (!scope.time) {
|
|
76
|
-
scope.startDateHour = 0;
|
|
77
|
-
scope.startDateMinute = 0;
|
|
78
|
-
scope.startDate.hours(0);
|
|
79
|
-
scope.startDate.minutes(0);
|
|
80
|
-
scope.startDate.seconds(0);
|
|
81
|
-
scope.startDate.millisecond(0);
|
|
82
|
-
scope.endDateHour = 0;
|
|
83
|
-
scope.endDateMinut = 0;
|
|
84
|
-
scope.endDate.hours(23);
|
|
85
|
-
scope.endDate.minutes(59);
|
|
86
|
-
scope.endDate.seconds(59);
|
|
87
|
-
scope.endDate.millisecond(999);
|
|
88
|
-
} else {
|
|
89
|
-
scope.startDateHour = moment(scope.startDate).hours();
|
|
90
|
-
scope.startDateMinute = moment(scope.startDate).minutes();
|
|
91
|
-
scope.endDateHour = moment(scope.endDate).hours();
|
|
92
|
-
scope.endDateMinute = moment(scope.endDate).minutes();
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
scope.month = angular.copy(moment(scope.startDate));
|
|
96
|
-
var start = angular.copy(moment(scope.startDate));
|
|
97
|
-
_removeTimeWithDate(start.date(0));
|
|
98
|
-
_buildMonth(scope, start, scope.month);
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
bootstrap();
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
// ------------------ Day was selected ------------------
|
|
105
|
-
scope.select = function (day) {
|
|
106
|
-
if (!day.isDisabled) {
|
|
107
|
-
var selectedDate = angular.copy(day.date);
|
|
108
|
-
|
|
109
|
-
if (scope.selectStart) {
|
|
110
|
-
if (!scope.time) {
|
|
111
|
-
selectedDate.hours(0);
|
|
112
|
-
selectedDate.minutes(0);
|
|
113
|
-
selectedDate.seconds(0);
|
|
114
|
-
selectedDate.millisecond(0);
|
|
115
|
-
} else {
|
|
116
|
-
selectedDate.hours(scope.startDateHour);
|
|
117
|
-
selectedDate.minutes(scope.startDateMinute);
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
// Set start date
|
|
121
|
-
scope.startDate = selectedDate;
|
|
122
|
-
scope.selectStart = false;
|
|
123
|
-
scope.popupText = gettextCatalog.getString("Select end date", null, "Nice");
|
|
124
|
-
scope.formCalendar.$setDirty();
|
|
125
|
-
scope.displayStartChange();
|
|
126
|
-
|
|
127
|
-
// If start date is after end date
|
|
128
|
-
if (scope.startDate.isAfter(scope.endDate)) {
|
|
129
|
-
scope.endDate = angular.copy(scope.startDate);
|
|
130
|
-
}
|
|
131
|
-
} else {
|
|
132
|
-
if (!scope.time) {
|
|
133
|
-
selectedDate.hours(23);
|
|
134
|
-
selectedDate.minutes(59);
|
|
135
|
-
selectedDate.seconds(59);
|
|
136
|
-
selectedDate.millisecond(999);
|
|
137
|
-
} else {
|
|
138
|
-
selectedDate.hours(scope.endDateHour);
|
|
139
|
-
selectedDate.minutes(scope.endDateMinute);
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
// Set end date
|
|
143
|
-
scope.endDate = selectedDate;
|
|
144
|
-
scope.selectStart = true;
|
|
145
|
-
scope.popupText = gettextCatalog.getString("Select start date", null, "Nice");
|
|
146
|
-
scope.formCalendar.$setDirty();
|
|
147
|
-
scope.displayEndChange();
|
|
148
|
-
|
|
149
|
-
// If end date is before start date
|
|
150
|
-
if (scope.endDate.isBefore(scope.startDate)) {
|
|
151
|
-
scope.startDate = angular.copy(scope.endDate);
|
|
152
|
-
}
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
if (scope.onChange) scope.onChange({ model: { startDate: scope.startDate, endDate: scope.endDate }, element: element });
|
|
156
|
-
}
|
|
157
|
-
};
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
// ------------------ Display date changes ------------------
|
|
161
|
-
scope.displayStartChange = function () {
|
|
162
|
-
scope.startTimeClass = "change";
|
|
163
|
-
$timeout(function () {
|
|
164
|
-
scope.startTimeClass = "";
|
|
165
|
-
}, 1000);
|
|
166
|
-
};
|
|
167
|
-
|
|
168
|
-
scope.displayEndChange = function () {
|
|
169
|
-
scope.endTimeClass = "change";
|
|
170
|
-
$timeout(function () {
|
|
171
|
-
scope.endTimeClass = "";
|
|
172
|
-
}, 1000);
|
|
173
|
-
};
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
// ------------------ Time changes ------------------
|
|
177
|
-
scope.startHourChange = function (value) {
|
|
178
|
-
scope.startDateHour = value;
|
|
179
|
-
scope.startDate = moment(scope.startDate).hours(scope.startDateHour);
|
|
180
|
-
scope.formCalendar.$setDirty();
|
|
181
|
-
scope.displayStartChange();
|
|
182
|
-
scope.handleUpdate();
|
|
183
|
-
};
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
scope.startMinuteChange = function (value) {
|
|
187
|
-
scope.startDateMinute = value;
|
|
188
|
-
scope.startDate = moment(scope.startDate).minutes(scope.startDateMinute);
|
|
189
|
-
scope.formCalendar.$setDirty();
|
|
190
|
-
scope.displayStartChange();
|
|
191
|
-
scope.handleUpdate();
|
|
192
|
-
};
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
scope.endHourChange = function (value) {
|
|
196
|
-
scope.endDateHour = value;
|
|
197
|
-
scope.endDate = moment(scope.endDate).hours(scope.endDateHour);
|
|
198
|
-
scope.formCalendar.$setDirty();
|
|
199
|
-
scope.displayEndChange();
|
|
200
|
-
scope.handleUpdate();
|
|
201
|
-
};
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
scope.endMinuteChange = function (value) {
|
|
205
|
-
scope.endDateMinute = value;
|
|
206
|
-
scope.endDate = moment(scope.endDate).minutes(scope.endDateMinute);
|
|
207
|
-
scope.formCalendar.$setDirty();
|
|
208
|
-
scope.displayEndChange();
|
|
209
|
-
scope.handleUpdate();
|
|
210
|
-
};
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
scope.handleUpdate = function () {
|
|
214
|
-
if (scope.onChange) scope.onChange({ model: { startDate: scope.startDate, endDate: scope.endDate }, element: element });
|
|
215
|
-
};
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
// ------------------ Go to next month ------------------
|
|
219
|
-
scope.next = function () {
|
|
220
|
-
var next = angular.copy(scope.month);
|
|
221
|
-
_removeTimeWithDate(next.month(next.month() + 1).date(0));
|
|
222
|
-
scope.month.month(scope.month.month() + 1);
|
|
223
|
-
_buildMonth(scope, next, scope.month);
|
|
224
|
-
};
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
// ------------------ Go to previous month ------------------
|
|
228
|
-
scope.previous = function () {
|
|
229
|
-
var previous = angular.copy(scope.month);
|
|
230
|
-
_removeTimeWithDate(previous.month(previous.month() - 1).date(0));
|
|
231
|
-
scope.month.month(scope.month.month() - 1);
|
|
232
|
-
_buildMonth(scope, previous, scope.month);
|
|
233
|
-
};
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
// ------------------ Check if dates are equal without time ------------------
|
|
237
|
-
scope.isSameDay = function (date1, date2) {
|
|
238
|
-
var d1 = _removeTime(angular.copy(date1));
|
|
239
|
-
var d2 = _removeTime(angular.copy(date2));
|
|
240
|
-
return d1.isSame(d2);
|
|
241
|
-
};
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
// ------------------ Check if date is between start and end date ------------------
|
|
245
|
-
scope.isBetweenRange = function (date) {
|
|
246
|
-
return (date.isBefore(moment(scope.endDate)) && date.isAfter(moment(scope.startDate)));
|
|
247
|
-
};
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
// ------------------ Format date ------------------
|
|
251
|
-
scope.formatDate = function (date) {
|
|
252
|
-
if (scope.time) return moment(date).format('D.M.YYYY • H:mm');
|
|
253
|
-
else return moment(date).format('D.M.YYYY');
|
|
254
|
-
};
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
// ------------------ Lighten color by 20% ------------------
|
|
258
|
-
scope.lighten = function (col) {
|
|
259
|
-
var amt = 20;
|
|
260
|
-
var usePound = false;
|
|
261
|
-
|
|
262
|
-
if (col[0] == "#") {
|
|
263
|
-
col = col.slice(1);
|
|
264
|
-
usePound = true;
|
|
265
|
-
}
|
|
266
|
-
|
|
267
|
-
var num = parseInt(col, 16);
|
|
268
|
-
var r = (num >> 16) + amt;
|
|
269
|
-
|
|
270
|
-
if (r > 255) r = 255;
|
|
271
|
-
else if (r < 0) r = 0;
|
|
272
|
-
|
|
273
|
-
var b = ((num >> 8) & 0x00FF) + amt;
|
|
274
|
-
if (b > 255) b = 255;
|
|
275
|
-
else if (b < 0) b = 0;
|
|
276
|
-
|
|
277
|
-
var g = (num & 0x0000FF) + amt;
|
|
278
|
-
if (g > 255) g = 255;
|
|
279
|
-
else if (g < 0) g = 0;
|
|
280
|
-
|
|
281
|
-
return (usePound ? "#" : "") + (g | (b << 8) | (r << 16)).toString(16);
|
|
282
|
-
};
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
// ------------------ Remove time from date ------------------
|
|
286
|
-
function _removeTime(date) {
|
|
287
|
-
return moment(date).hour(0).minute(0).second(0).millisecond(0);
|
|
288
|
-
}
|
|
289
|
-
|
|
290
|
-
function _removeTimeWithDate(date) {
|
|
291
|
-
return date.day(0).hour(0).minute(0).second(0).millisecond(0);
|
|
292
|
-
}
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
// ------------------ Build month ------------------
|
|
297
|
-
function _buildMonth(scope, start, month) {
|
|
298
|
-
scope.weeks = [];
|
|
299
|
-
var done = false, date = start.clone().startOf('week').isoWeekday(1), monthIndex = date.month(), count = 0;
|
|
300
|
-
date.add(1, "w");
|
|
301
|
-
while (!done) {
|
|
302
|
-
scope.weeks.push({ days: _buildWeek(date.clone(), month) });
|
|
303
|
-
date.add(1, "w");
|
|
304
|
-
done = count++ > 2 && monthIndex !== date.month();
|
|
305
|
-
monthIndex = date.month();
|
|
306
|
-
}
|
|
307
|
-
}
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
// ------------------ Build week ------------------
|
|
311
|
-
function _buildWeek(date, month) {
|
|
312
|
-
var days = [];
|
|
313
|
-
for (var i = 0; i < 7; i++) {
|
|
314
|
-
var day = {
|
|
315
|
-
name: date.format("dd"),
|
|
316
|
-
number: date.date(),
|
|
317
|
-
isCurrentMonth: date.month() === month.month(),
|
|
318
|
-
isToday: date.isSame(new Date(), "day"),
|
|
319
|
-
isWeekday: date.weekday() == 0 || date.weekday() == 6,
|
|
320
|
-
date: date
|
|
321
|
-
};
|
|
322
|
-
|
|
323
|
-
if (scope.minDate) day.isDisabled = date.isBefore(moment(scope.minDate));
|
|
324
|
-
if (scope.maxDate) day.isDisabled = date.isAfter(moment(scope.maxDate));
|
|
325
|
-
if (scope.minDate && scope.maxDate) day.isDisabled = !date.isBetween(moment(scope.minDate), moment(scope.maxDate));
|
|
326
|
-
|
|
327
|
-
days.push(day);
|
|
328
|
-
date = date.clone();
|
|
329
|
-
date.add(1, "d");
|
|
330
|
-
}
|
|
331
|
-
|
|
332
|
-
return days;
|
|
333
|
-
}
|
|
334
|
-
}
|
|
335
|
-
};
|
|
336
|
-
});
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @ngdoc directive
|
|
5
|
+
* @name niceElements.directive:niceCalendar
|
|
6
|
+
* @description
|
|
7
|
+
* # niceCalendar
|
|
8
|
+
*/
|
|
9
|
+
angular.module('niceElements')
|
|
10
|
+
.directive("niceCalendar", function ($timeout, gettextCatalog) {
|
|
11
|
+
return {
|
|
12
|
+
restrict: "E",
|
|
13
|
+
templateUrl: "src/components/nice-calendar/nice-calendar.html",
|
|
14
|
+
scope: {
|
|
15
|
+
niceTitle: '@',
|
|
16
|
+
title: '@',
|
|
17
|
+
fieldWidth: '@',
|
|
18
|
+
labelWidth: '@',
|
|
19
|
+
minDate: '=',
|
|
20
|
+
maxDate: '=',
|
|
21
|
+
hideHover: '=',
|
|
22
|
+
time: '=',
|
|
23
|
+
noMargin: '@',
|
|
24
|
+
color: '@',
|
|
25
|
+
endDate: '=',
|
|
26
|
+
startDate: '=',
|
|
27
|
+
isDisabled: '=',
|
|
28
|
+
help: '@',
|
|
29
|
+
isInline: '=',
|
|
30
|
+
onChange: '&?',
|
|
31
|
+
required: '='
|
|
32
|
+
},
|
|
33
|
+
link: function (scope, element) {
|
|
34
|
+
// ------------------ Init default values ------------------
|
|
35
|
+
scope.selectStart = true;
|
|
36
|
+
scope.popupText = gettextCatalog.getString("Select start date", null, "Nice");
|
|
37
|
+
|
|
38
|
+
scope.hours = [
|
|
39
|
+
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
|
+
];
|
|
41
|
+
|
|
42
|
+
scope.minutes = [
|
|
43
|
+
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
|
|
44
|
+
];
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
// ------------------ Check if attributes are set ------------------
|
|
48
|
+
if (!scope.startDate) scope.startDate = moment().minutes(0).second(0).millisecond(0);
|
|
49
|
+
if (!scope.endDate) scope.endDate = moment().minutes(0).second(0).millisecond(0);
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
// ------------------ Look for model changes ------------------
|
|
53
|
+
scope.$watch("startDate", function (value, valueOld) {
|
|
54
|
+
bootstrap();
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
scope.$watch("endDate", function (value, valueOld) {
|
|
58
|
+
bootstrap();
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
scope.$watch("minDate", function (value, valueOld) {
|
|
62
|
+
bootstrap();
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
scope.$watch("maxDate", function (value, valueOld) {
|
|
66
|
+
bootstrap();
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
// ------------------ Bootstrap calendar ------------------
|
|
71
|
+
function bootstrap() {
|
|
72
|
+
// scope.startDate = moment(scope.startDate.second(0).millisecond(0));
|
|
73
|
+
// scope.endDate = moment(scope.endDate.second(0).millisecond(0));
|
|
74
|
+
|
|
75
|
+
if (!scope.time) {
|
|
76
|
+
scope.startDateHour = 0;
|
|
77
|
+
scope.startDateMinute = 0;
|
|
78
|
+
scope.startDate.hours(0);
|
|
79
|
+
scope.startDate.minutes(0);
|
|
80
|
+
scope.startDate.seconds(0);
|
|
81
|
+
scope.startDate.millisecond(0);
|
|
82
|
+
scope.endDateHour = 0;
|
|
83
|
+
scope.endDateMinut = 0;
|
|
84
|
+
scope.endDate.hours(23);
|
|
85
|
+
scope.endDate.minutes(59);
|
|
86
|
+
scope.endDate.seconds(59);
|
|
87
|
+
scope.endDate.millisecond(999);
|
|
88
|
+
} else {
|
|
89
|
+
scope.startDateHour = moment(scope.startDate).hours();
|
|
90
|
+
scope.startDateMinute = moment(scope.startDate).minutes();
|
|
91
|
+
scope.endDateHour = moment(scope.endDate).hours();
|
|
92
|
+
scope.endDateMinute = moment(scope.endDate).minutes();
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
scope.month = angular.copy(moment(scope.startDate));
|
|
96
|
+
var start = angular.copy(moment(scope.startDate));
|
|
97
|
+
_removeTimeWithDate(start.date(0));
|
|
98
|
+
_buildMonth(scope, start, scope.month);
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
bootstrap();
|
|
102
|
+
|
|
103
|
+
|
|
104
|
+
// ------------------ Day was selected ------------------
|
|
105
|
+
scope.select = function (day) {
|
|
106
|
+
if (!day.isDisabled) {
|
|
107
|
+
var selectedDate = angular.copy(day.date);
|
|
108
|
+
|
|
109
|
+
if (scope.selectStart) {
|
|
110
|
+
if (!scope.time) {
|
|
111
|
+
selectedDate.hours(0);
|
|
112
|
+
selectedDate.minutes(0);
|
|
113
|
+
selectedDate.seconds(0);
|
|
114
|
+
selectedDate.millisecond(0);
|
|
115
|
+
} else {
|
|
116
|
+
selectedDate.hours(scope.startDateHour);
|
|
117
|
+
selectedDate.minutes(scope.startDateMinute);
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
// Set start date
|
|
121
|
+
scope.startDate = selectedDate;
|
|
122
|
+
scope.selectStart = false;
|
|
123
|
+
scope.popupText = gettextCatalog.getString("Select end date", null, "Nice");
|
|
124
|
+
scope.formCalendar.$setDirty();
|
|
125
|
+
scope.displayStartChange();
|
|
126
|
+
|
|
127
|
+
// If start date is after end date
|
|
128
|
+
if (scope.startDate.isAfter(scope.endDate)) {
|
|
129
|
+
scope.endDate = angular.copy(scope.startDate);
|
|
130
|
+
}
|
|
131
|
+
} else {
|
|
132
|
+
if (!scope.time) {
|
|
133
|
+
selectedDate.hours(23);
|
|
134
|
+
selectedDate.minutes(59);
|
|
135
|
+
selectedDate.seconds(59);
|
|
136
|
+
selectedDate.millisecond(999);
|
|
137
|
+
} else {
|
|
138
|
+
selectedDate.hours(scope.endDateHour);
|
|
139
|
+
selectedDate.minutes(scope.endDateMinute);
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
// Set end date
|
|
143
|
+
scope.endDate = selectedDate;
|
|
144
|
+
scope.selectStart = true;
|
|
145
|
+
scope.popupText = gettextCatalog.getString("Select start date", null, "Nice");
|
|
146
|
+
scope.formCalendar.$setDirty();
|
|
147
|
+
scope.displayEndChange();
|
|
148
|
+
|
|
149
|
+
// If end date is before start date
|
|
150
|
+
if (scope.endDate.isBefore(scope.startDate)) {
|
|
151
|
+
scope.startDate = angular.copy(scope.endDate);
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
if (scope.onChange) scope.onChange({ model: { startDate: scope.startDate, endDate: scope.endDate }, element: element });
|
|
156
|
+
}
|
|
157
|
+
};
|
|
158
|
+
|
|
159
|
+
|
|
160
|
+
// ------------------ Display date changes ------------------
|
|
161
|
+
scope.displayStartChange = function () {
|
|
162
|
+
scope.startTimeClass = "change";
|
|
163
|
+
$timeout(function () {
|
|
164
|
+
scope.startTimeClass = "";
|
|
165
|
+
}, 1000);
|
|
166
|
+
};
|
|
167
|
+
|
|
168
|
+
scope.displayEndChange = function () {
|
|
169
|
+
scope.endTimeClass = "change";
|
|
170
|
+
$timeout(function () {
|
|
171
|
+
scope.endTimeClass = "";
|
|
172
|
+
}, 1000);
|
|
173
|
+
};
|
|
174
|
+
|
|
175
|
+
|
|
176
|
+
// ------------------ Time changes ------------------
|
|
177
|
+
scope.startHourChange = function (value) {
|
|
178
|
+
scope.startDateHour = value;
|
|
179
|
+
scope.startDate = moment(scope.startDate).hours(scope.startDateHour);
|
|
180
|
+
scope.formCalendar.$setDirty();
|
|
181
|
+
scope.displayStartChange();
|
|
182
|
+
scope.handleUpdate();
|
|
183
|
+
};
|
|
184
|
+
|
|
185
|
+
|
|
186
|
+
scope.startMinuteChange = function (value) {
|
|
187
|
+
scope.startDateMinute = value;
|
|
188
|
+
scope.startDate = moment(scope.startDate).minutes(scope.startDateMinute);
|
|
189
|
+
scope.formCalendar.$setDirty();
|
|
190
|
+
scope.displayStartChange();
|
|
191
|
+
scope.handleUpdate();
|
|
192
|
+
};
|
|
193
|
+
|
|
194
|
+
|
|
195
|
+
scope.endHourChange = function (value) {
|
|
196
|
+
scope.endDateHour = value;
|
|
197
|
+
scope.endDate = moment(scope.endDate).hours(scope.endDateHour);
|
|
198
|
+
scope.formCalendar.$setDirty();
|
|
199
|
+
scope.displayEndChange();
|
|
200
|
+
scope.handleUpdate();
|
|
201
|
+
};
|
|
202
|
+
|
|
203
|
+
|
|
204
|
+
scope.endMinuteChange = function (value) {
|
|
205
|
+
scope.endDateMinute = value;
|
|
206
|
+
scope.endDate = moment(scope.endDate).minutes(scope.endDateMinute);
|
|
207
|
+
scope.formCalendar.$setDirty();
|
|
208
|
+
scope.displayEndChange();
|
|
209
|
+
scope.handleUpdate();
|
|
210
|
+
};
|
|
211
|
+
|
|
212
|
+
|
|
213
|
+
scope.handleUpdate = function () {
|
|
214
|
+
if (scope.onChange) scope.onChange({ model: { startDate: scope.startDate, endDate: scope.endDate }, element: element });
|
|
215
|
+
};
|
|
216
|
+
|
|
217
|
+
|
|
218
|
+
// ------------------ Go to next month ------------------
|
|
219
|
+
scope.next = function () {
|
|
220
|
+
var next = angular.copy(scope.month);
|
|
221
|
+
_removeTimeWithDate(next.month(next.month() + 1).date(0));
|
|
222
|
+
scope.month.month(scope.month.month() + 1);
|
|
223
|
+
_buildMonth(scope, next, scope.month);
|
|
224
|
+
};
|
|
225
|
+
|
|
226
|
+
|
|
227
|
+
// ------------------ Go to previous month ------------------
|
|
228
|
+
scope.previous = function () {
|
|
229
|
+
var previous = angular.copy(scope.month);
|
|
230
|
+
_removeTimeWithDate(previous.month(previous.month() - 1).date(0));
|
|
231
|
+
scope.month.month(scope.month.month() - 1);
|
|
232
|
+
_buildMonth(scope, previous, scope.month);
|
|
233
|
+
};
|
|
234
|
+
|
|
235
|
+
|
|
236
|
+
// ------------------ Check if dates are equal without time ------------------
|
|
237
|
+
scope.isSameDay = function (date1, date2) {
|
|
238
|
+
var d1 = _removeTime(angular.copy(date1));
|
|
239
|
+
var d2 = _removeTime(angular.copy(date2));
|
|
240
|
+
return d1.isSame(d2);
|
|
241
|
+
};
|
|
242
|
+
|
|
243
|
+
|
|
244
|
+
// ------------------ Check if date is between start and end date ------------------
|
|
245
|
+
scope.isBetweenRange = function (date) {
|
|
246
|
+
return (date.isBefore(moment(scope.endDate)) && date.isAfter(moment(scope.startDate)));
|
|
247
|
+
};
|
|
248
|
+
|
|
249
|
+
|
|
250
|
+
// ------------------ Format date ------------------
|
|
251
|
+
scope.formatDate = function (date) {
|
|
252
|
+
if (scope.time) return moment(date).format('D.M.YYYY • H:mm');
|
|
253
|
+
else return moment(date).format('D.M.YYYY');
|
|
254
|
+
};
|
|
255
|
+
|
|
256
|
+
|
|
257
|
+
// ------------------ Lighten color by 20% ------------------
|
|
258
|
+
scope.lighten = function (col) {
|
|
259
|
+
var amt = 20;
|
|
260
|
+
var usePound = false;
|
|
261
|
+
|
|
262
|
+
if (col[0] == "#") {
|
|
263
|
+
col = col.slice(1);
|
|
264
|
+
usePound = true;
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
var num = parseInt(col, 16);
|
|
268
|
+
var r = (num >> 16) + amt;
|
|
269
|
+
|
|
270
|
+
if (r > 255) r = 255;
|
|
271
|
+
else if (r < 0) r = 0;
|
|
272
|
+
|
|
273
|
+
var b = ((num >> 8) & 0x00FF) + amt;
|
|
274
|
+
if (b > 255) b = 255;
|
|
275
|
+
else if (b < 0) b = 0;
|
|
276
|
+
|
|
277
|
+
var g = (num & 0x0000FF) + amt;
|
|
278
|
+
if (g > 255) g = 255;
|
|
279
|
+
else if (g < 0) g = 0;
|
|
280
|
+
|
|
281
|
+
return (usePound ? "#" : "") + (g | (b << 8) | (r << 16)).toString(16);
|
|
282
|
+
};
|
|
283
|
+
|
|
284
|
+
|
|
285
|
+
// ------------------ Remove time from date ------------------
|
|
286
|
+
function _removeTime(date) {
|
|
287
|
+
return moment(date).hour(0).minute(0).second(0).millisecond(0);
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
function _removeTimeWithDate(date) {
|
|
291
|
+
return date.day(0).hour(0).minute(0).second(0).millisecond(0);
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
|
|
295
|
+
|
|
296
|
+
// ------------------ Build month ------------------
|
|
297
|
+
function _buildMonth(scope, start, month) {
|
|
298
|
+
scope.weeks = [];
|
|
299
|
+
var done = false, date = start.clone().startOf('week').isoWeekday(1), monthIndex = date.month(), count = 0;
|
|
300
|
+
date.add(1, "w");
|
|
301
|
+
while (!done) {
|
|
302
|
+
scope.weeks.push({ days: _buildWeek(date.clone(), month) });
|
|
303
|
+
date.add(1, "w");
|
|
304
|
+
done = count++ > 2 && monthIndex !== date.month();
|
|
305
|
+
monthIndex = date.month();
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
|
|
310
|
+
// ------------------ Build week ------------------
|
|
311
|
+
function _buildWeek(date, month) {
|
|
312
|
+
var days = [];
|
|
313
|
+
for (var i = 0; i < 7; i++) {
|
|
314
|
+
var day = {
|
|
315
|
+
name: date.format("dd"),
|
|
316
|
+
number: date.date(),
|
|
317
|
+
isCurrentMonth: date.month() === month.month(),
|
|
318
|
+
isToday: date.isSame(new Date(), "day"),
|
|
319
|
+
isWeekday: date.weekday() == 0 || date.weekday() == 6,
|
|
320
|
+
date: date
|
|
321
|
+
};
|
|
322
|
+
|
|
323
|
+
if (scope.minDate) day.isDisabled = date.isBefore(moment(scope.minDate));
|
|
324
|
+
if (scope.maxDate) day.isDisabled = date.isAfter(moment(scope.maxDate));
|
|
325
|
+
if (scope.minDate && scope.maxDate) day.isDisabled = !date.isBetween(moment(scope.minDate), moment(scope.maxDate));
|
|
326
|
+
|
|
327
|
+
days.push(day);
|
|
328
|
+
date = date.clone();
|
|
329
|
+
date.add(1, "d");
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
return days;
|
|
333
|
+
}
|
|
334
|
+
}
|
|
335
|
+
};
|
|
336
|
+
});
|