nice-elements 1.12.10 → 1.12.12

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 +589 -580
  3. package/LICENSE.md +21 -21
  4. package/README.md +102 -102
  5. package/bower.json +17 -17
  6. package/dist/nice.js +9200 -11639
  7. package/dist/nice.min.js +1 -1
  8. package/dist/style.css +12 -12
  9. package/dist/style.css.map +1 -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.js +122 -122
  17. package/src/components/nice-avatar/nice-avatar.scss +4 -4
  18. package/src/components/nice-button/nice-button.html +4 -4
  19. package/src/components/nice-button/nice-button.js +41 -41
  20. package/src/components/nice-button/nice-button.scss +16 -16
  21. package/src/components/nice-button-toggle/nice-button-toggle.html +9 -9
  22. package/src/components/nice-button-toggle/nice-button-toggle.js +23 -23
  23. package/src/components/nice-button-toggle/nice-button-toggle.scss +2 -2
  24. package/src/components/nice-calendar/nice-calendar.html +91 -91
  25. package/src/components/nice-calendar/nice-calendar.js +346 -346
  26. package/src/components/nice-calendar/nice-calendar.scss +288 -288
  27. package/src/components/nice-checkbox/nice-checkbox.html +20 -9
  28. package/src/components/nice-checkbox/nice-checkbox.js +38 -37
  29. package/src/components/nice-checkbox/nice-checkbox.scss +120 -120
  30. package/src/components/nice-choice/nice-choice.html +18 -18
  31. package/src/components/nice-choice/nice-choice.js +211 -211
  32. package/src/components/nice-choice/nice-choice.scss +110 -110
  33. package/src/components/nice-comment/nice-comment.html +10 -10
  34. package/src/components/nice-comment/nice-comment.js +71 -71
  35. package/src/components/nice-comment/nice-comment.scss +39 -39
  36. package/src/components/nice-date/nice-date.html +82 -82
  37. package/src/components/nice-date/nice-date.js +350 -350
  38. package/src/components/nice-date/nice-date.scss +305 -305
  39. package/src/components/nice-date-input/nice-date-input.html +56 -56
  40. package/src/components/nice-date-input/nice-date-input.js +143 -143
  41. package/src/components/nice-date-input/nice-date-input.scss +55 -55
  42. package/src/components/nice-date-range/nice-date-range.html +15 -15
  43. package/src/components/nice-date-range/nice-date-range.js +78 -78
  44. package/src/components/nice-date-range/nice-date-range.scss +390 -390
  45. package/src/components/nice-datetime-picker/nice-datetime-picker.html +29 -29
  46. package/src/components/nice-datetime-picker/nice-datetime-picker.js +89 -89
  47. package/src/components/nice-datetime-picker/nice-datetime-picker.scss +428 -428
  48. package/src/components/nice-datetimerange-picker/nice-datetimerange-picker.html +55 -55
  49. package/src/components/nice-datetimerange-picker/nice-datetimerange-picker.js +248 -248
  50. package/src/components/nice-datetimerange-picker/nice-datetimerange-picker.scss +73 -73
  51. package/src/components/nice-datetimerange-picker-2/nice-datetimerange-picker-2.html +44 -44
  52. package/src/components/nice-datetimerange-picker-2/nice-datetimerange-picker-2.js +175 -175
  53. package/src/components/nice-datetimerange-picker-2/nice-datetimerange-picker-2.scss +127 -127
  54. package/src/components/nice-dropdown/nice-dropdown.html +61 -61
  55. package/src/components/nice-dropdown/nice-dropdown.js +518 -517
  56. package/src/components/nice-dropdown/nice-dropdown.scss +262 -262
  57. package/src/components/nice-dropdown-date/nice-dropdown-date.html +28 -28
  58. package/src/components/nice-dropdown-date/nice-dropdown-date.js +132 -132
  59. package/src/components/nice-dropdown-date/nice-dropdown-date.scss +87 -87
  60. package/src/components/nice-dropdown-old/nice-dropdown-old.html +44 -44
  61. package/src/components/nice-dropdown-old/nice-dropdown-old.js +330 -330
  62. package/src/components/nice-dropdown-old/nice-dropdown-old.scss +129 -129
  63. package/src/components/nice-dtp/nice-dtp.html +91 -91
  64. package/src/components/nice-dtp/nice-dtp.js +835 -835
  65. package/src/components/nice-help/nice-help.html +6 -6
  66. package/src/components/nice-help/nice-help.js +58 -58
  67. package/src/components/nice-help/nice-help.scss +78 -78
  68. package/src/components/nice-input/nice-input.html +47 -47
  69. package/src/components/nice-input/nice-input.js +251 -251
  70. package/src/components/nice-input/nice-input.scss +130 -130
  71. package/src/components/nice-label/nice-label.html +10 -10
  72. package/src/components/nice-label/nice-label.js +32 -32
  73. package/src/components/nice-loader/nice-loader.html +6 -6
  74. package/src/components/nice-loader/nice-loader.js +28 -28
  75. package/src/components/nice-loader/nice-loader.scss +47 -47
  76. package/src/components/nice-no-data/nice-no-data.html +3 -3
  77. package/src/components/nice-no-data/nice-no-data.js +27 -27
  78. package/src/components/nice-no-data/nice-no-data.scss +26 -26
  79. package/src/components/nice-notification/nice-notification.html +3 -3
  80. package/src/components/nice-notification/nice-notification.js +124 -124
  81. package/src/components/nice-notification/nice-notification.scss +66 -66
  82. package/src/components/nice-number/nice-number.html +40 -40
  83. package/src/components/nice-number/nice-number.js +172 -172
  84. package/src/components/nice-number/nice-number.scss +18 -18
  85. package/src/components/nice-on-scroll/nice-on-scroll.js +17 -17
  86. package/src/components/nice-percent/nice-percent.html +24 -24
  87. package/src/components/nice-percent/nice-percent.js +95 -95
  88. package/src/components/nice-pill/nice-pill.html +3 -3
  89. package/src/components/nice-pill/nice-pill.js +29 -29
  90. package/src/components/nice-pill/nice-pill.scss +25 -25
  91. package/src/components/nice-popup/nice-popup.html +6 -6
  92. package/src/components/nice-popup/nice-popup.js +122 -122
  93. package/src/components/nice-popup/nice-popup.scss +43 -43
  94. package/src/components/nice-progress-bar/nice-progress-bar.html +15 -15
  95. package/src/components/nice-progress-bar/nice-progress-bar.js +55 -55
  96. package/src/components/nice-progress-bar/nice-progress-bar.scss +47 -47
  97. package/src/components/nice-quantity/nice-quantity.html +22 -22
  98. package/src/components/nice-quantity/nice-quantity.js +57 -57
  99. package/src/components/nice-quantity/nice-quantity.scss +51 -51
  100. package/src/components/nice-search/nice-search.html +44 -44
  101. package/src/components/nice-search/nice-search.js +243 -243
  102. package/src/components/nice-search/nice-search.scss +90 -90
  103. package/src/components/nice-search2/nice-search2.html +32 -32
  104. package/src/components/nice-search2/nice-search2.js +267 -267
  105. package/src/components/nice-search2/nice-search2.scss +80 -80
  106. package/src/components/nice-slot/nice-slot.html +10 -10
  107. package/src/components/nice-slot/nice-slot.js +31 -31
  108. package/src/components/nice-steps/nice-steps.scss +81 -81
  109. package/src/components/nice-svgs/nice-svgs.html +1332 -1332
  110. package/src/components/nice-svgs/nice-svgs.js +19 -19
  111. package/src/components/nice-table/nice-table.html +38 -38
  112. package/src/components/nice-table/nice-table.js +60 -60
  113. package/src/components/nice-table/nice-table.scss +112 -112
  114. package/src/components/nice-time-picker/nice-time-picker.html +43 -43
  115. package/src/components/nice-time-picker/nice-time-picker.js +85 -85
  116. package/src/components/nice-time-picker/nice-time-picker.scss +37 -37
  117. package/src/components/nice-title/nice-title.html +6 -6
  118. package/src/components/nice-title/nice-title.js +22 -22
  119. package/src/components/nice-toast/nice-toast.html +2 -2
  120. package/src/components/nice-toast/nice-toast.js +56 -56
  121. package/src/components/nice-toast/nice-toast.scss +74 -74
  122. package/src/components/nice-toggle/nice-toggle.html +12 -12
  123. package/src/components/nice-toggle/nice-toggle.js +57 -57
  124. package/src/components/nice-toggle/nice-toggle.scss +131 -131
  125. package/src/components/nice-upload/nice-upload.html +22 -22
  126. package/src/components/nice-upload/nice-upload.js +160 -160
  127. package/src/components/nice-upload/nice-upload.scss +85 -85
  128. package/src/components/nice-view/_nice-view.scss +63 -63
  129. package/src/components/nice-view/nice-view.html +12 -12
  130. package/src/components/nice-view/nice-view.js +29 -30
  131. package/src/components/nice-virtual-scroll/_nice-virtual-scroll.scss +17 -17
  132. package/src/components/nice-virtual-scroll/nice-virtual-scroll.html +12 -12
  133. package/src/components/nice-virtual-scroll/nice-virtual-scroll.js +70 -70
  134. package/src/components/nice-wrapper/_nice-wrapper.scss +87 -87
  135. package/src/components/nice-wrapper/nice-wrapper.html +12 -12
  136. package/src/components/nice-wrapper/nice-wrapper.js +44 -44
  137. package/src/components/nice-yesno/nice-yesno.html +14 -14
  138. package/src/components/nice-yesno/nice-yesno.js +111 -111
  139. package/src/components/nice-yesno/nice-yesno.scss +95 -95
  140. package/src/directives/nice-click-outside.js +105 -105
  141. package/src/directives/nice-infinite-loader.js +27 -27
  142. package/src/directives/nice-tooltip/_nice-tooltip.scss +55 -55
  143. package/src/directives/nice-tooltip/nice-tooltip.js +84 -84
  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 +75 -75
  157. package/src/styles/_variables.scss +194 -194
@@ -1,518 +1,519 @@
1
- 'use strict';
2
-
3
- /**
4
- * @ngdoc directive
5
- * @name niceElements.directive:nice-dropdown
6
- * @description
7
- * # nice-dropdown
8
- */
9
- angular.module('niceElements')
10
- .directive('niceDropdown', function () {
11
- return {
12
- templateUrl: 'src/components/nice-dropdown/nice-dropdown.html',
13
- restrict: 'E',
14
- transclude: {
15
- 'button': '?niceDropdownButton',
16
- 'option': '?niceDropdownOption'
17
- },
18
- scope: {
19
- niceTitle: '@',
20
- title: '@', // Title of the field
21
- model: '=', // Aka model
22
- list: '=', // List of options
23
- onChange: '&?',
24
- onSelect: '&?', // Like onChange but always return objects
25
- onClose: '&?',
26
- onOpen: '&?',
27
- isDisabled: '=',
28
- fieldWidth: '@',
29
- labelWidth: '@',
30
- loading: '=?',
31
- addButtonFunction: '=?',
32
- objValue: '@', // Optional - default is 'value'
33
- objKey: '@?', // Optional - default is 'id'. Used only when returnOnlyKey=true.
34
- selectedIsKey: '@?',
35
- nullable: '@', // No selection is possible
36
- required: '=', // Model cannot be NULL
37
- noMargin: '@', // margin-bottom: 0px
38
- multiple: '@', // Can select multiple items
39
- help: '@',
40
- noOptionsText: '@',
41
- noDataText: '@',
42
- selectText: '@',
43
- searchText: '@',
44
- noSearch: '=',
45
- nullableText: '@',
46
- selectedText: '@',
47
- dropdownDistance: '@',
48
- searchFunction: '=?',
49
- filterFunction: '=?',
50
- isInline: '=',
51
- clearOnSelect: '@',
52
- enableLoadMore: '@', // Enable load more
53
- placement: '@', // Describes the preferred placement of the popper
54
- },
55
- controller: function ($scope, $http, $element, $timeout, gettextCatalog, NiceService) {
56
- $scope.id = Math.random().toString(36).substring(7);
57
- if (!$scope.dropdownDistance) { $scope.dropdownDistance = 5; }
58
- if (!$scope.objValue) { $scope.objValue = 'value'; }
59
- if (!$scope.objKey) { $scope.objKey = 'id'; }
60
- if (!$scope.noOptionsText) { $scope.noOptionsText = gettextCatalog.getString("No options", null, "Nice"); }
61
- if (!$scope.noDataText) { $scope.noDataText = gettextCatalog.getString("No options", null, "Nice"); }
62
- if (!$scope.searchText) { $scope.searchText = gettextCatalog.getString("Search...", null, "Nice"); }
63
- if (!$scope.nullableText) { $scope.nullableText = gettextCatalog.getString("None", null, "Nice"); }
64
- if (!$scope.selectText) { $scope.selectText = gettextCatalog.getString("None", null, "Nice"); }
65
- if (!$scope.selectedText) { $scope.selectedText = gettextCatalog.getString("selected", null, "Nice"); }
66
- if (!$scope.addButtonFunction) { $scope.addButtonFunction = null; }
67
- if (!$scope.placement) { $scope.placement = "bottom-start"; }
68
- $scope.nullable = $scope.nullable === 'true' || $scope.nullable === true;
69
- $scope.noMargin = $scope.noMargin === 'true' || $scope.noMargin === true;
70
- $scope.multiple = $scope.multiple === 'true' || $scope.multiple === true;
71
- $scope.clearOnSelect = $scope.clearOnSelect === 'true' || $scope.clearOnSelect === true;
72
- $scope.isOpen = false;
73
- $scope.selected = null;
74
- // $scope.selectedIndex = 0;
75
- $scope.popper = null;
76
-
77
- $scope.internal = {
78
- search: ""
79
- };
80
-
81
- if ($scope.list) {
82
- $scope.originalList = angular.copy($scope.list);
83
- }
84
-
85
- // Setup popper
86
- // https://popper.js.org/docs/v2/constructors/
87
- $scope.setupPopper = function () {
88
- const button = $element[0].getElementsByClassName('btn-dropdown')[0];
89
- const tooltip = $element[0].getElementsByClassName('nice-dropdown-menu-wrapper')[0];
90
- $scope.popper = Popper.createPopper(button, tooltip, {
91
- strategy: 'fixed',
92
- placement: $scope.placement,
93
- scroll: true,
94
- resize: true,
95
- modifiers: [
96
- {
97
- name: 'offset',
98
- options: {
99
- offset: [0, $scope.dropdownDistance],
100
- },
101
- },
102
- {
103
- name: "sameWidth",
104
- enabled: true,
105
- phase: "beforeWrite",
106
- requires: ["computeStyles"],
107
- fn: function (e) {
108
- const state = e.state;
109
- let width = state.rects.reference.width;
110
- if (width < 200) width = 200;
111
- state.styles.popper.width = width + "px";
112
- },
113
- effect: function (e) {
114
- const state = e.state;
115
- let width = state.elements.reference.width;
116
- if (width < 200) width = 200;
117
- state.elements.popper.style.width = width + "px";
118
- }
119
- }
120
- ],
121
- });
122
- };
123
-
124
- $timeout(function () {
125
- $scope.setupPopper();
126
- });
127
-
128
-
129
- // ----------------------------------- Open -----------------------------------
130
- $scope.toggle = function () {
131
- if ($scope.isOpen) {
132
- $scope.close();
133
- } else {
134
- $scope.open();
135
- }
136
- };
137
-
138
- $scope.close = function () {
139
- $scope.isOpen = false;
140
- if ($scope.onClose) $scope.onClose();
141
- };
142
-
143
- $scope.open = function () {
144
- $scope.popper.update();
145
- if ($scope.filterFunction) $scope.internalList = $scope.filterFunction($scope.originalList, $scope.model);
146
- $timeout(function () {
147
- $scope.isOpen = true;
148
- if ($scope.onOpen) $scope.onOpen();
149
- $timeout(function () {
150
- $scope.popper.update();
151
- });
152
- });
153
- $timeout(function () {
154
- $scope.focusInput();
155
- $scope.scrollToHover(true);
156
- if ($scope.enableLoadMore) $scope.handleScrollToBottom();
157
- }, 100);
158
- };
159
-
160
-
161
- // ----------------------------------- Handle scroll to bottom -----------------------------------
162
- let lastScrollPosition = Infinity;
163
- $scope.handleScrollToBottom = function () {
164
- lastScrollPosition = Infinity;
165
- const element = angular.element($element[0].getElementsByClassName("nice-dropdown-items")[0]);
166
- element.bind("scroll mousewheel", function (e) {
167
- const scrollPosition = element[0].scrollHeight - element[0].scrollTop;
168
- if (scrollPosition === element[0].clientHeight && lastScrollPosition != scrollPosition) {
169
- $scope.loadMore();
170
- }
171
- if (scrollPosition <= lastScrollPosition) lastScrollPosition = scrollPosition;
172
- });
173
- }
174
-
175
-
176
- // ----------------------------------- Load more -----------------------------------
177
- $scope.loadMore = function () {
178
- if (!$scope.internalList || !$scope.internalList._metadata || !$scope.internalList._metadata.next) return;
179
- $scope.loading = true;
180
- $http({
181
- method: 'GET',
182
- url: $scope.internalList._metadata.next,
183
- headers: NiceService.getHeader()
184
- }).then(function (response) {
185
- response = response.data;
186
- const metadata = {
187
- count: response.count,
188
- previous: response.previous,
189
- next: response.next,
190
- };
191
- $scope.internalList._metadata = metadata;
192
- angular.forEach(response.results, function (item) {
193
- $scope.internalList.push(item);
194
- });
195
- lastScrollPosition = Infinity;
196
- $scope.loading = false;
197
- return response;
198
- }, function (error) {
199
- $scope.loading = false;
200
- return error;
201
- });
202
- }
203
-
204
-
205
- // ----------------------------------- Focus input -----------------------------------
206
- $scope.focusInput = function () {
207
- $timeout(function () {
208
- const input = $element[0].getElementsByClassName("search-bar-input")[0];
209
- if (input) input.focus();
210
- });
211
- };
212
-
213
-
214
- // $scope.onInputFocus = function () {
215
- // $timeout(function () {
216
- // const input = $element[0].getElementsByClassName("btn-dropdown")[0];
217
- // if (input) input.focus();
218
- // });
219
- // }
220
-
221
-
222
- // ------------------- On blur -------------------
223
- $scope.onBlur = function () {
224
- $scope.close();
225
- };
226
-
227
-
228
- $scope.handleNewInternalList = function (items) {
229
- $scope.originalList = angular.copy(items);
230
- if ($scope.filterFunction) $scope.internalList = $scope.filterFunction($scope.originalList, $scope.model);
231
- else $scope.internalList = items;
232
- }
233
-
234
-
235
- // ----------------------------------- Scroll to hover -----------------------------------
236
- $scope.scrollToHover = function (notSmooth) {
237
- const dropdownMenu = $element[0].getElementsByClassName("nice-dropdown-menu")[0];
238
- if (!dropdownMenu) return;
239
- const dropdownList = dropdownMenu.getElementsByClassName("nice-dropdown-items")[0];
240
- const hoverItem = dropdownList.getElementsByClassName("hover")[0];
241
- if (!hoverItem) return
242
- const topPos = hoverItem.offsetTop;
243
- dropdownList.scroll({
244
- top: topPos - 120,
245
- left: 0,
246
- behavior: notSmooth ? 'auto' : 'smooth'
247
- });
248
- };
249
-
250
-
251
- // ----------------------------------- Search -----------------------------------
252
- $scope.handleSearch = function () {
253
- if (!$scope.searchFunction) return;
254
- $scope.loading = true;
255
- $scope.searchFunction($scope.internal.search).then(function (response) {
256
- $scope.handleNewInternalList(response);
257
- $scope.loading = false;
258
- $scope.handleDefault();
259
- }, function () {
260
- $scope.internalList = null;
261
- $scope.loading = false;
262
- });
263
- };
264
-
265
- $scope.clearSearch = function () {
266
- $scope.internal.search = "";
267
- $scope.handleSearch();
268
- }
269
-
270
-
271
- // ----------------------------------- Item clicked -----------------------------------
272
- $scope.handleSelected = function (item, index) {
273
- $scope.formDropdown.$setDirty();
274
-
275
- if (item != null) {
276
- if ($scope.multiple) {
277
- $scope.handleMultipleSelect(item, index);
278
- } else {
279
- $scope.handleSingleSelect(item, index);
280
- }
281
- } else {
282
- $scope.handleSingleSelect(undefined, -1);
283
- }
284
- };
285
-
286
-
287
- // ----------------------------------- Handle multiple select -----------------------------------
288
- $scope.handleMultipleSelect = function (item, index) {
289
- if (!$scope.selected) $scope.selected = [];
290
-
291
- if (item._selected) {
292
- $scope.selected = $scope.selected.filter(function (s) {
293
- return s[$scope.objKey] != item[$scope.objKey];
294
- });
295
- } else {
296
- $scope.selected.push(item);
297
- }
298
-
299
- $scope.handleSetModel();
300
- };
301
-
302
-
303
- // ----------------------------------- Select all -----------------------------------
304
- $scope.selectAll = function () {
305
- if (!$scope.multiple) return;
306
- $scope.selected = $scope.internalList;
307
- angular.forEach($scope.internalList, function (o) {
308
- o._selected = true;
309
- });
310
- $scope.handleSetModel();
311
- }
312
-
313
-
314
- // ----------------------------------- Select none -----------------------------------
315
- $scope.selectNone = function () {
316
- if (!$scope.multiple) return;
317
- $scope.selected = [];
318
- angular.forEach($scope.internalList, function (o) {
319
- o._selected = false;
320
- });
321
- $scope.handleSetModel();
322
- }
323
-
324
-
325
- // ----------------------------------- Handle single slect -----------------------------------
326
- $scope.handleSingleSelect = function (item, index) {
327
- $scope.selected = item;
328
- $scope.close();
329
- $scope.handleSetModel();
330
- };
331
-
332
-
333
- // ----------------------------------- Handle set model -----------------------------------
334
- $scope.handleSetModel = function () {
335
- let obj = angular.copy($scope.selected);
336
-
337
- if ($scope.selected != null) {
338
- // Remove selected flag
339
- if (!$scope.selectedIsKey) {
340
- if ($scope.multiple) {
341
- angular.forEach(obj, function (o) {
342
- o._selected = undefined;
343
- });
344
- } else {
345
- obj._selected = undefined;
346
- }
347
- }
348
-
349
- // Selected is object
350
- if ($scope.selectedIsKey) {
351
- if ($scope.multiple) {
352
- obj = obj.map(function (o) {
353
- return o[$scope.objKey];
354
- });
355
- } else {
356
- obj = obj[$scope.objKey];
357
- }
358
- }
359
- }
360
-
361
- if ($scope.clearOnSelect) {
362
- // Clear on select
363
- $scope.model = null;
364
- } else {
365
- // Set model
366
- $scope.model = obj;
367
- }
368
-
369
- // Trigger on change
370
- $timeout(function () {
371
- if ($scope.onChange) $scope.onChange({ model: obj });
372
- if ($scope.onSelect) $scope.onSelect({ model: angular.copy($scope.selected) });
373
- })
374
- };
375
-
376
-
377
- // ----------------------------------- Handle default -----------------------------------
378
- $scope.handleDefault = function () {
379
- if ($scope.model) $scope.handleModelChange();
380
- if (!$scope.nullable && !$scope.model && !$scope.clearOnSelect && $scope.internalList && $scope.internalList.length > 0) {
381
- $scope.handleSelected($scope.internalList[0], 0);
382
- }
383
- };
384
-
385
- // ----------------------------------- Watch for list change -----------------------------------
386
- $scope.$watchCollection('list', function (value_new, value_old) {
387
- $scope.handleNewInternalList(angular.copy($scope.list));
388
- $scope.handleDefault();
389
- });
390
-
391
-
392
- // ----------------------------------- Watch for model change -----------------------------------
393
- $scope.$watch('model', function (value_new, value_old) {
394
- $scope.handleModelChange();
395
- });
396
-
397
- $scope.handleModelChange = function () {
398
- $scope.selected = angular.copy($scope.model);
399
- angular.forEach($scope.internalList, function (i, index) {
400
- i._selected = false;
401
-
402
- if ($scope.selectedIsKey) {
403
- // Not object
404
- if ($scope.multiple) {
405
- // Multiple
406
- angular.forEach($scope.selected, function (s, index) {
407
- if (i[$scope.objKey] == s) {
408
- i._selected = true;
409
- // $scope.selected.push(i);
410
- $scope.selected[index] = i
411
- // $scope.selectedIndex = index;
412
- }
413
- });
414
- } else {
415
- // Single
416
- if ($scope.selected != null && i[$scope.objKey] == $scope.selected) {
417
- i._selected = true;
418
- $scope.selected = i;
419
- // $scope.selectedIndex = index;
420
- $scope.scrollToHover();
421
- }
422
- }
423
- } else {
424
- // Is object
425
- if ($scope.multiple) {
426
- // Multiple
427
- angular.forEach($scope.selected, function (s) {
428
- if (i[$scope.objKey] == s[$scope.objKey]) {
429
- i._selected = true;
430
- // $scope.selected.push(i);
431
- // $scope.selectedIndex = index;
432
- }
433
- });
434
- } else {
435
- // Single
436
- if ($scope.selected != null && i[$scope.objKey] == $scope.selected[$scope.objKey]) {
437
- i._selected = true;
438
- $scope.selected = i;
439
- // $scope.selectedIndex = index;
440
- $scope.scrollToHover();
441
- }
442
- }
443
- }
444
- });
445
-
446
- // Handle required
447
- $timeout(function () {
448
- if ($scope.formDropdown) $scope.formDropdown.$setValidity('required', !(!$scope.selected && $scope.required));
449
- });
450
- }
451
-
452
- // ----------------------------------- Watch for keydown and keypress -----------------------------------
453
- // $element.bind("keydown keypress", function (event) {
454
- // // Arrow Up
455
- // if (event.keyCode == 38) {
456
- // event.preventDefault();
457
- // $timeout(function () {
458
- // if ($scope.selectedIndex > 0) {
459
- // $scope.selectedIndex -= 1;
460
- // $timeout(function () {
461
- // $scope.scrollToHover();
462
- // });
463
- // }
464
- // });
465
- // }
466
-
467
- // // Arrow Down
468
- // if (event.keyCode == 40) {
469
- // event.preventDefault();
470
- // $timeout(function () {
471
- // if ($scope.internalList && $scope.selectedIndex < $scope.internalList.length - 1) {
472
- // $scope.selectedIndex += 1;
473
- // $timeout(function () {
474
- // $scope.scrollToHover();
475
- // });
476
- // }
477
- // });
478
- // }
479
-
480
- // // Enter
481
- // if (event.keyCode == 13) {
482
- // event.preventDefault();
483
- // $timeout(function () {
484
- // $scope.handleSelected($scope.internalList[$scope.selectedIndex], $scope.selectedIndex);
485
- // });
486
- // }
487
-
488
- // // Escape
489
- // if (event.keyCode == 27) {
490
- // $timeout(function () {
491
- // $scope.close();
492
- // });
493
- // }
494
- // });
495
-
496
- $scope.handleDefault();
497
-
498
- // ----------------------------------- Init search -----------------------------------
499
- if ($scope.searchFunction) {
500
- $scope.handleSearch();
501
- }
502
-
503
-
504
- // ----------------------------------- Handle add button function -----------------------------------
505
- $scope.handleAddButton = function ($event) {
506
- let element = $event.target;
507
- while (true) {
508
- if (element.nodeName == 'BUTTON') {
509
- element.blur();
510
- break;
511
- }
512
- element = element.parentElement;
513
- }
514
- $scope.addButtonFunction();
515
- }
516
- }
517
- };
1
+ 'use strict';
2
+
3
+ /**
4
+ * @ngdoc directive
5
+ * @name niceElements.directive:nice-dropdown
6
+ * @description
7
+ * # nice-dropdown
8
+ */
9
+ angular.module('niceElements')
10
+ .directive('niceDropdown', function () {
11
+ return {
12
+ templateUrl: 'src/components/nice-dropdown/nice-dropdown.html',
13
+ restrict: 'E',
14
+ transclude: {
15
+ 'button': '?niceDropdownButton',
16
+ 'option': '?niceDropdownOption'
17
+ },
18
+ scope: {
19
+ niceTitle: '@',
20
+ title: '@', // Title of the field
21
+ model: '=', // Aka model
22
+ list: '=', // List of options
23
+ onChange: '&?',
24
+ onSelect: '&?', // Like onChange but always return objects
25
+ onClose: '&?',
26
+ onOpen: '&?',
27
+ isDisabled: '=',
28
+ fieldWidth: '@',
29
+ labelWidth: '@',
30
+ loading: '=?',
31
+ addButtonFunction: '=?',
32
+ addButtonDisabled: '=?',
33
+ objValue: '@', // Optional - default is 'value'
34
+ objKey: '@?', // Optional - default is 'id'. Used only when returnOnlyKey=true.
35
+ selectedIsKey: '@?',
36
+ nullable: '@', // No selection is possible
37
+ required: '=', // Model cannot be NULL
38
+ noMargin: '@', // margin-bottom: 0px
39
+ multiple: '@', // Can select multiple items
40
+ help: '@',
41
+ noOptionsText: '@',
42
+ noDataText: '@',
43
+ selectText: '@',
44
+ searchText: '@',
45
+ noSearch: '=',
46
+ nullableText: '@',
47
+ selectedText: '@',
48
+ dropdownDistance: '@',
49
+ searchFunction: '=?',
50
+ filterFunction: '=?',
51
+ isInline: '=',
52
+ clearOnSelect: '@',
53
+ enableLoadMore: '@', // Enable load more
54
+ placement: '@', // Describes the preferred placement of the popper
55
+ },
56
+ controller: function ($scope, $http, $element, $timeout, gettextCatalog, NiceService) {
57
+ $scope.id = Math.random().toString(36).substring(7);
58
+ if (!$scope.dropdownDistance) { $scope.dropdownDistance = 5; }
59
+ if (!$scope.objValue) { $scope.objValue = 'value'; }
60
+ if (!$scope.objKey) { $scope.objKey = 'id'; }
61
+ if (!$scope.noOptionsText) { $scope.noOptionsText = gettextCatalog.getString("No options", null, "Nice"); }
62
+ if (!$scope.noDataText) { $scope.noDataText = gettextCatalog.getString("No options", null, "Nice"); }
63
+ if (!$scope.searchText) { $scope.searchText = gettextCatalog.getString("Search...", null, "Nice"); }
64
+ if (!$scope.nullableText) { $scope.nullableText = gettextCatalog.getString("None", null, "Nice"); }
65
+ if (!$scope.selectText) { $scope.selectText = gettextCatalog.getString("None", null, "Nice"); }
66
+ if (!$scope.selectedText) { $scope.selectedText = gettextCatalog.getString("selected", null, "Nice"); }
67
+ if (!$scope.addButtonFunction) { $scope.addButtonFunction = null; }
68
+ if (!$scope.placement) { $scope.placement = "bottom-start"; }
69
+ $scope.nullable = $scope.nullable === 'true' || $scope.nullable === true;
70
+ $scope.noMargin = $scope.noMargin === 'true' || $scope.noMargin === true;
71
+ $scope.multiple = $scope.multiple === 'true' || $scope.multiple === true;
72
+ $scope.clearOnSelect = $scope.clearOnSelect === 'true' || $scope.clearOnSelect === true;
73
+ $scope.isOpen = false;
74
+ $scope.selected = null;
75
+ // $scope.selectedIndex = 0;
76
+ $scope.popper = null;
77
+
78
+ $scope.internal = {
79
+ search: ""
80
+ };
81
+
82
+ if ($scope.list) {
83
+ $scope.originalList = angular.copy($scope.list);
84
+ }
85
+
86
+ // Setup popper
87
+ // https://popper.js.org/docs/v2/constructors/
88
+ $scope.setupPopper = function () {
89
+ const button = $element[0].getElementsByClassName('btn-dropdown')[0];
90
+ const tooltip = $element[0].getElementsByClassName('nice-dropdown-menu-wrapper')[0];
91
+ $scope.popper = Popper.createPopper(button, tooltip, {
92
+ strategy: 'fixed',
93
+ placement: $scope.placement,
94
+ scroll: true,
95
+ resize: true,
96
+ modifiers: [
97
+ {
98
+ name: 'offset',
99
+ options: {
100
+ offset: [0, $scope.dropdownDistance],
101
+ },
102
+ },
103
+ {
104
+ name: "sameWidth",
105
+ enabled: true,
106
+ phase: "beforeWrite",
107
+ requires: ["computeStyles"],
108
+ fn: function (e) {
109
+ const state = e.state;
110
+ let width = state.rects.reference.width;
111
+ if (width < 200) width = 200;
112
+ state.styles.popper.width = width + "px";
113
+ },
114
+ effect: function (e) {
115
+ const state = e.state;
116
+ let width = state.elements.reference.width;
117
+ if (width < 200) width = 200;
118
+ state.elements.popper.style.width = width + "px";
119
+ }
120
+ }
121
+ ],
122
+ });
123
+ };
124
+
125
+ $timeout(function () {
126
+ $scope.setupPopper();
127
+ });
128
+
129
+
130
+ // ----------------------------------- Open -----------------------------------
131
+ $scope.toggle = function () {
132
+ if ($scope.isOpen) {
133
+ $scope.close();
134
+ } else {
135
+ $scope.open();
136
+ }
137
+ };
138
+
139
+ $scope.close = function () {
140
+ $scope.isOpen = false;
141
+ if ($scope.onClose) $scope.onClose();
142
+ };
143
+
144
+ $scope.open = function () {
145
+ $scope.popper.update();
146
+ if ($scope.filterFunction) $scope.internalList = $scope.filterFunction($scope.originalList, $scope.model);
147
+ $timeout(function () {
148
+ $scope.isOpen = true;
149
+ if ($scope.onOpen) $scope.onOpen();
150
+ $timeout(function () {
151
+ $scope.popper.update();
152
+ });
153
+ });
154
+ $timeout(function () {
155
+ $scope.focusInput();
156
+ $scope.scrollToHover(true);
157
+ if ($scope.enableLoadMore) $scope.handleScrollToBottom();
158
+ }, 100);
159
+ };
160
+
161
+
162
+ // ----------------------------------- Handle scroll to bottom -----------------------------------
163
+ let lastScrollPosition = Infinity;
164
+ $scope.handleScrollToBottom = function () {
165
+ lastScrollPosition = Infinity;
166
+ const element = angular.element($element[0].getElementsByClassName("nice-dropdown-items")[0]);
167
+ element.bind("scroll mousewheel", function (e) {
168
+ const scrollPosition = element[0].scrollHeight - element[0].scrollTop;
169
+ if (scrollPosition === element[0].clientHeight && lastScrollPosition != scrollPosition) {
170
+ $scope.loadMore();
171
+ }
172
+ if (scrollPosition <= lastScrollPosition) lastScrollPosition = scrollPosition;
173
+ });
174
+ }
175
+
176
+
177
+ // ----------------------------------- Load more -----------------------------------
178
+ $scope.loadMore = function () {
179
+ if (!$scope.internalList || !$scope.internalList._metadata || !$scope.internalList._metadata.next) return;
180
+ $scope.loading = true;
181
+ $http({
182
+ method: 'GET',
183
+ url: $scope.internalList._metadata.next,
184
+ headers: NiceService.getHeader()
185
+ }).then(function (response) {
186
+ response = response.data;
187
+ const metadata = {
188
+ count: response.count,
189
+ previous: response.previous,
190
+ next: response.next,
191
+ };
192
+ $scope.internalList._metadata = metadata;
193
+ angular.forEach(response.results, function (item) {
194
+ $scope.internalList.push(item);
195
+ });
196
+ lastScrollPosition = Infinity;
197
+ $scope.loading = false;
198
+ return response;
199
+ }, function (error) {
200
+ $scope.loading = false;
201
+ return error;
202
+ });
203
+ }
204
+
205
+
206
+ // ----------------------------------- Focus input -----------------------------------
207
+ $scope.focusInput = function () {
208
+ $timeout(function () {
209
+ const input = $element[0].getElementsByClassName("search-bar-input")[0];
210
+ if (input) input.focus();
211
+ });
212
+ };
213
+
214
+
215
+ // $scope.onInputFocus = function () {
216
+ // $timeout(function () {
217
+ // const input = $element[0].getElementsByClassName("btn-dropdown")[0];
218
+ // if (input) input.focus();
219
+ // });
220
+ // }
221
+
222
+
223
+ // ------------------- On blur -------------------
224
+ $scope.onBlur = function () {
225
+ $scope.close();
226
+ };
227
+
228
+
229
+ $scope.handleNewInternalList = function (items) {
230
+ $scope.originalList = angular.copy(items);
231
+ if ($scope.filterFunction) $scope.internalList = $scope.filterFunction($scope.originalList, $scope.model);
232
+ else $scope.internalList = items;
233
+ }
234
+
235
+
236
+ // ----------------------------------- Scroll to hover -----------------------------------
237
+ $scope.scrollToHover = function (notSmooth) {
238
+ const dropdownMenu = $element[0].getElementsByClassName("nice-dropdown-menu")[0];
239
+ if (!dropdownMenu) return;
240
+ const dropdownList = dropdownMenu.getElementsByClassName("nice-dropdown-items")[0];
241
+ const hoverItem = dropdownList.getElementsByClassName("hover")[0];
242
+ if (!hoverItem) return
243
+ const topPos = hoverItem.offsetTop;
244
+ dropdownList.scroll({
245
+ top: topPos - 120,
246
+ left: 0,
247
+ behavior: notSmooth ? 'auto' : 'smooth'
248
+ });
249
+ };
250
+
251
+
252
+ // ----------------------------------- Search -----------------------------------
253
+ $scope.handleSearch = function () {
254
+ if (!$scope.searchFunction) return;
255
+ $scope.loading = true;
256
+ $scope.searchFunction($scope.internal.search).then(function (response) {
257
+ $scope.handleNewInternalList(response);
258
+ $scope.loading = false;
259
+ $scope.handleDefault();
260
+ }, function () {
261
+ $scope.internalList = null;
262
+ $scope.loading = false;
263
+ });
264
+ };
265
+
266
+ $scope.clearSearch = function () {
267
+ $scope.internal.search = "";
268
+ $scope.handleSearch();
269
+ }
270
+
271
+
272
+ // ----------------------------------- Item clicked -----------------------------------
273
+ $scope.handleSelected = function (item, index) {
274
+ $scope.formDropdown.$setDirty();
275
+
276
+ if (item != null) {
277
+ if ($scope.multiple) {
278
+ $scope.handleMultipleSelect(item, index);
279
+ } else {
280
+ $scope.handleSingleSelect(item, index);
281
+ }
282
+ } else {
283
+ $scope.handleSingleSelect(undefined, -1);
284
+ }
285
+ };
286
+
287
+
288
+ // ----------------------------------- Handle multiple select -----------------------------------
289
+ $scope.handleMultipleSelect = function (item, index) {
290
+ if (!$scope.selected) $scope.selected = [];
291
+
292
+ if (item._selected) {
293
+ $scope.selected = $scope.selected.filter(function (s) {
294
+ return s[$scope.objKey] != item[$scope.objKey];
295
+ });
296
+ } else {
297
+ $scope.selected.push(item);
298
+ }
299
+
300
+ $scope.handleSetModel();
301
+ };
302
+
303
+
304
+ // ----------------------------------- Select all -----------------------------------
305
+ $scope.selectAll = function () {
306
+ if (!$scope.multiple) return;
307
+ $scope.selected = $scope.internalList;
308
+ angular.forEach($scope.internalList, function (o) {
309
+ o._selected = true;
310
+ });
311
+ $scope.handleSetModel();
312
+ }
313
+
314
+
315
+ // ----------------------------------- Select none -----------------------------------
316
+ $scope.selectNone = function () {
317
+ if (!$scope.multiple) return;
318
+ $scope.selected = [];
319
+ angular.forEach($scope.internalList, function (o) {
320
+ o._selected = false;
321
+ });
322
+ $scope.handleSetModel();
323
+ }
324
+
325
+
326
+ // ----------------------------------- Handle single slect -----------------------------------
327
+ $scope.handleSingleSelect = function (item, index) {
328
+ $scope.selected = item;
329
+ $scope.close();
330
+ $scope.handleSetModel();
331
+ };
332
+
333
+
334
+ // ----------------------------------- Handle set model -----------------------------------
335
+ $scope.handleSetModel = function () {
336
+ let obj = angular.copy($scope.selected);
337
+
338
+ if ($scope.selected != null) {
339
+ // Remove selected flag
340
+ if (!$scope.selectedIsKey) {
341
+ if ($scope.multiple) {
342
+ angular.forEach(obj, function (o) {
343
+ o._selected = undefined;
344
+ });
345
+ } else {
346
+ obj._selected = undefined;
347
+ }
348
+ }
349
+
350
+ // Selected is object
351
+ if ($scope.selectedIsKey) {
352
+ if ($scope.multiple) {
353
+ obj = obj.map(function (o) {
354
+ return o[$scope.objKey];
355
+ });
356
+ } else {
357
+ obj = obj[$scope.objKey];
358
+ }
359
+ }
360
+ }
361
+
362
+ if ($scope.clearOnSelect) {
363
+ // Clear on select
364
+ $scope.model = null;
365
+ } else {
366
+ // Set model
367
+ $scope.model = obj;
368
+ }
369
+
370
+ // Trigger on change
371
+ $timeout(function () {
372
+ if ($scope.onChange) $scope.onChange({ model: obj });
373
+ if ($scope.onSelect) $scope.onSelect({ model: angular.copy($scope.selected) });
374
+ })
375
+ };
376
+
377
+
378
+ // ----------------------------------- Handle default -----------------------------------
379
+ $scope.handleDefault = function () {
380
+ if ($scope.model) $scope.handleModelChange();
381
+ if (!$scope.nullable && !$scope.model && !$scope.clearOnSelect && $scope.internalList && $scope.internalList.length > 0) {
382
+ $scope.handleSelected($scope.internalList[0], 0);
383
+ }
384
+ };
385
+
386
+ // ----------------------------------- Watch for list change -----------------------------------
387
+ $scope.$watchCollection('list', function (value_new, value_old) {
388
+ $scope.handleNewInternalList(angular.copy($scope.list));
389
+ $scope.handleDefault();
390
+ });
391
+
392
+
393
+ // ----------------------------------- Watch for model change -----------------------------------
394
+ $scope.$watch('model', function (value_new, value_old) {
395
+ $scope.handleModelChange();
396
+ });
397
+
398
+ $scope.handleModelChange = function () {
399
+ $scope.selected = angular.copy($scope.model);
400
+ angular.forEach($scope.internalList, function (i, index) {
401
+ i._selected = false;
402
+
403
+ if ($scope.selectedIsKey) {
404
+ // Not object
405
+ if ($scope.multiple) {
406
+ // Multiple
407
+ angular.forEach($scope.selected, function (s, index) {
408
+ if (i[$scope.objKey] == s) {
409
+ i._selected = true;
410
+ // $scope.selected.push(i);
411
+ $scope.selected[index] = i
412
+ // $scope.selectedIndex = index;
413
+ }
414
+ });
415
+ } else {
416
+ // Single
417
+ if ($scope.selected != null && i[$scope.objKey] == $scope.selected) {
418
+ i._selected = true;
419
+ $scope.selected = i;
420
+ // $scope.selectedIndex = index;
421
+ $scope.scrollToHover();
422
+ }
423
+ }
424
+ } else {
425
+ // Is object
426
+ if ($scope.multiple) {
427
+ // Multiple
428
+ angular.forEach($scope.selected, function (s) {
429
+ if (i[$scope.objKey] == s[$scope.objKey]) {
430
+ i._selected = true;
431
+ // $scope.selected.push(i);
432
+ // $scope.selectedIndex = index;
433
+ }
434
+ });
435
+ } else {
436
+ // Single
437
+ if ($scope.selected != null && i[$scope.objKey] == $scope.selected[$scope.objKey]) {
438
+ i._selected = true;
439
+ $scope.selected = i;
440
+ // $scope.selectedIndex = index;
441
+ $scope.scrollToHover();
442
+ }
443
+ }
444
+ }
445
+ });
446
+
447
+ // Handle required
448
+ $timeout(function () {
449
+ if ($scope.formDropdown) $scope.formDropdown.$setValidity('required', !(!$scope.selected && $scope.required));
450
+ });
451
+ }
452
+
453
+ // ----------------------------------- Watch for keydown and keypress -----------------------------------
454
+ // $element.bind("keydown keypress", function (event) {
455
+ // // Arrow Up
456
+ // if (event.keyCode == 38) {
457
+ // event.preventDefault();
458
+ // $timeout(function () {
459
+ // if ($scope.selectedIndex > 0) {
460
+ // $scope.selectedIndex -= 1;
461
+ // $timeout(function () {
462
+ // $scope.scrollToHover();
463
+ // });
464
+ // }
465
+ // });
466
+ // }
467
+
468
+ // // Arrow Down
469
+ // if (event.keyCode == 40) {
470
+ // event.preventDefault();
471
+ // $timeout(function () {
472
+ // if ($scope.internalList && $scope.selectedIndex < $scope.internalList.length - 1) {
473
+ // $scope.selectedIndex += 1;
474
+ // $timeout(function () {
475
+ // $scope.scrollToHover();
476
+ // });
477
+ // }
478
+ // });
479
+ // }
480
+
481
+ // // Enter
482
+ // if (event.keyCode == 13) {
483
+ // event.preventDefault();
484
+ // $timeout(function () {
485
+ // $scope.handleSelected($scope.internalList[$scope.selectedIndex], $scope.selectedIndex);
486
+ // });
487
+ // }
488
+
489
+ // // Escape
490
+ // if (event.keyCode == 27) {
491
+ // $timeout(function () {
492
+ // $scope.close();
493
+ // });
494
+ // }
495
+ // });
496
+
497
+ $scope.handleDefault();
498
+
499
+ // ----------------------------------- Init search -----------------------------------
500
+ if ($scope.searchFunction) {
501
+ $scope.handleSearch();
502
+ }
503
+
504
+
505
+ // ----------------------------------- Handle add button function -----------------------------------
506
+ $scope.handleAddButton = function ($event) {
507
+ let element = $event.target;
508
+ while (true) {
509
+ if (element.nodeName == 'BUTTON') {
510
+ element.blur();
511
+ break;
512
+ }
513
+ element = element.parentElement;
514
+ }
515
+ $scope.addButtonFunction();
516
+ }
517
+ }
518
+ };
518
519
  });