nice-elements 1.12.6 → 1.12.8

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