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