nice-elements 1.9.14 → 1.9.16
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.vscode/settings.json +17 -17
- package/CHANGELOG.md +401 -390
- package/LICENSE.md +21 -21
- package/README.md +93 -93
- package/bower.json +10 -10
- package/dist/nice.js +7930 -7954
- package/dist/nice.min.js +1 -1
- package/dist/style.css +7 -7
- package/dist/style.min.css +7 -7
- package/package.json +40 -40
- package/src/components/nice-button/nice-button.html +4 -4
- package/src/components/nice-button/nice-button.js +41 -41
- package/src/components/nice-button/nice-button.scss +16 -16
- package/src/components/nice-button-toggle/nice-button-toggle.html +9 -9
- package/src/components/nice-button-toggle/nice-button-toggle.js +23 -23
- package/src/components/nice-button-toggle/nice-button-toggle.scss +2 -2
- package/src/components/nice-calendar/nice-calendar.html +91 -91
- package/src/components/nice-calendar/nice-calendar.js +334 -334
- package/src/components/nice-calendar/nice-calendar.scss +285 -285
- package/src/components/nice-checkbox/nice-checkbox.html +5 -5
- package/src/components/nice-checkbox/nice-checkbox.js +33 -33
- package/src/components/nice-checkbox/nice-checkbox.scss +91 -91
- package/src/components/nice-choice/nice-choice.html +18 -18
- package/src/components/nice-choice/nice-choice.js +210 -210
- package/src/components/nice-choice/nice-choice.scss +110 -110
- package/src/components/nice-click-outside/nice-click-outside.js +105 -105
- package/src/components/nice-comment/nice-comment.html +10 -10
- package/src/components/nice-comment/nice-comment.js +69 -69
- package/src/components/nice-comment/nice-comment.scss +39 -39
- package/src/components/nice-date/nice-date.html +74 -74
- package/src/components/nice-date/nice-date.js +327 -327
- package/src/components/nice-date/nice-date.scss +302 -302
- package/src/components/nice-date-input/nice-date-input.html +41 -41
- package/src/components/nice-date-input/nice-date-input.js +109 -109
- package/src/components/nice-date-input/nice-date-input.scss +45 -45
- package/src/components/nice-date-range/nice-date-range.html +15 -15
- package/src/components/nice-date-range/nice-date-range.js +76 -76
- package/src/components/nice-date-range/nice-date-range.scss +390 -390
- package/src/components/nice-datetime-picker/nice-datetime-picker.html +29 -29
- package/src/components/nice-datetime-picker/nice-datetime-picker.js +87 -87
- package/src/components/nice-datetime-picker/nice-datetime-picker.scss +428 -428
- package/src/components/nice-datetimerange-picker/nice-datetimerange-picker.html +55 -55
- package/src/components/nice-datetimerange-picker/nice-datetimerange-picker.js +246 -246
- package/src/components/nice-datetimerange-picker/nice-datetimerange-picker.scss +73 -73
- package/src/components/nice-datetimerange-picker-2/nice-datetimerange-picker-2.html +44 -44
- package/src/components/nice-datetimerange-picker-2/nice-datetimerange-picker-2.js +172 -172
- package/src/components/nice-datetimerange-picker-2/nice-datetimerange-picker-2.scss +127 -127
- package/src/components/nice-dropdown/nice-dropdown.html +60 -60
- package/src/components/nice-dropdown/nice-dropdown.js +489 -489
- package/src/components/nice-dropdown/nice-dropdown.scss +249 -249
- package/src/components/nice-dropdown-date/nice-dropdown-date.html +28 -28
- package/src/components/nice-dropdown-date/nice-dropdown-date.js +126 -126
- package/src/components/nice-dropdown-date/nice-dropdown-date.scss +82 -82
- package/src/components/nice-dropdown-old/nice-dropdown-old.html +44 -44
- package/src/components/nice-dropdown-old/nice-dropdown-old.js +330 -330
- package/src/components/nice-dropdown-old/nice-dropdown-old.scss +129 -129
- package/src/components/nice-dtp/nice-dtp.html +91 -91
- package/src/components/nice-dtp/nice-dtp.js +833 -833
- package/src/components/nice-help/nice-help.html +6 -6
- package/src/components/nice-help/nice-help.js +55 -55
- package/src/components/nice-help/nice-help.scss +78 -78
- package/src/components/nice-input/nice-input.html +48 -48
- package/src/components/nice-input/nice-input.js +244 -231
- package/src/components/nice-input/nice-input.scss +130 -130
- package/src/components/nice-label/nice-label.html +10 -10
- package/src/components/nice-label/nice-label.js +30 -30
- package/src/components/nice-loader/nice-loader.html +6 -6
- package/src/components/nice-loader/nice-loader.js +28 -28
- package/src/components/nice-loader/nice-loader.scss +47 -47
- package/src/components/nice-notification/nice-notification.html +3 -3
- package/src/components/nice-notification/nice-notification.js +124 -124
- package/src/components/nice-notification/nice-notification.scss +66 -66
- package/src/components/nice-number/nice-number.html +40 -40
- package/src/components/nice-number/nice-number.js +169 -166
- package/src/components/nice-number/nice-number.scss +18 -18
- package/src/components/nice-percent/nice-percent.html +24 -24
- package/src/components/nice-percent/nice-percent.js +94 -94
- package/src/components/nice-pill/nice-pill.html +3 -3
- package/src/components/nice-pill/nice-pill.js +29 -29
- package/src/components/nice-pill/nice-pill.scss +25 -25
- package/src/components/nice-popup/nice-popup.html +6 -6
- package/src/components/nice-popup/nice-popup.js +122 -122
- package/src/components/nice-popup/nice-popup.scss +43 -43
- package/src/components/nice-progress-bar/nice-progress-bar.html +15 -15
- package/src/components/nice-progress-bar/nice-progress-bar.js +54 -54
- package/src/components/nice-progress-bar/nice-progress-bar.scss +47 -47
- package/src/components/nice-quantity/nice-quantity.html +22 -22
- package/src/components/nice-quantity/nice-quantity.js +55 -55
- package/src/components/nice-quantity/nice-quantity.scss +51 -51
- package/src/components/nice-search/nice-search.html +44 -44
- package/src/components/nice-search/nice-search.js +239 -239
- package/src/components/nice-search/nice-search.scss +90 -90
- package/src/components/nice-search2/nice-search2.html +32 -32
- package/src/components/nice-search2/nice-search2.js +264 -264
- package/src/components/nice-search2/nice-search2.scss +80 -80
- package/src/components/nice-slot/nice-slot.html +10 -10
- package/src/components/nice-slot/nice-slot.js +29 -29
- package/src/components/nice-steps/nice-steps.scss +81 -81
- package/src/components/nice-svgs/nice-svgs.html +1262 -1262
- package/src/components/nice-svgs/nice-svgs.js +16 -16
- package/src/components/nice-time-picker/nice-time-picker.html +43 -43
- package/src/components/nice-time-picker/nice-time-picker.js +83 -83
- package/src/components/nice-time-picker/nice-time-picker.scss +37 -37
- package/src/components/nice-title/nice-title.html +3 -3
- package/src/components/nice-title/nice-title.js +21 -21
- package/src/components/nice-toast/nice-toast.html +2 -2
- package/src/components/nice-toast/nice-toast.js +56 -56
- package/src/components/nice-toast/nice-toast.scss +74 -74
- package/src/components/nice-toggle/nice-toggle.html +12 -12
- package/src/components/nice-toggle/nice-toggle.js +95 -95
- package/src/components/nice-toggle/nice-toggle.scss +67 -67
- package/src/components/nice-tooltip/_nice-tooltip.scss +71 -71
- package/src/components/nice-tooltip/nice-tooltip.js +23 -23
- package/src/components/nice-upload/nice-upload.html +22 -22
- package/src/components/nice-upload/nice-upload.js +157 -157
- package/src/components/nice-upload/nice-upload.scss +85 -85
- package/src/components/nice-wrapper/_nice-wrapper.scss +87 -87
- package/src/components/nice-wrapper/nice-wrapper.html +12 -12
- package/src/components/nice-wrapper/nice-wrapper.js +43 -43
- package/src/components/nice-yesno/nice-yesno.html +14 -14
- package/src/components/nice-yesno/nice-yesno.js +109 -109
- package/src/components/nice-yesno/nice-yesno.scss +95 -95
- package/src/filters/nice-date.js +17 -17
- package/src/filters/nice-highlight.js +16 -16
- package/src/modals/nice-multilangual-modal/nice-multilangual-modal.html +30 -30
- package/src/modals/nice-multilangual-modal/nice-multilangual-modal.js +67 -67
- package/src/modals/nice-multilangual-modal/nice-multilangual-modal.scss +19 -19
- package/src/nice.js +2 -2
- package/src/services/nice-service.js +19 -19
- package/src/styles/_bootstrap-variables.scss +178 -178
- package/src/styles/_nice-buttons.scss +403 -403
- package/src/styles/_nice-common.scss +471 -471
- package/src/styles/_nice-ngdialog.scss +85 -85
- package/src/styles/_nice-spacing.scss +283 -283
- package/src/styles/_nice.scss +65 -65
- package/src/styles/_variables.scss +195 -195
|
@@ -1,330 +1,330 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* @ngdoc directive
|
|
5
|
-
* @name niceElements.directive:niceDropdownOld
|
|
6
|
-
* @description
|
|
7
|
-
* # niceDropdownOld
|
|
8
|
-
*/
|
|
9
|
-
angular.module('niceElements')
|
|
10
|
-
.directive('niceDropdownOld', function () {
|
|
11
|
-
return {
|
|
12
|
-
templateUrl: 'src/components/nice-dropdown-old/nice-dropdown-old.html',
|
|
13
|
-
restrict: 'E',
|
|
14
|
-
transclude: true,
|
|
15
|
-
scope: {
|
|
16
|
-
title: '@', // Title of the field
|
|
17
|
-
model: '=', // Aka model
|
|
18
|
-
list: '=', // List of options
|
|
19
|
-
isDisabled: '=',
|
|
20
|
-
fieldWidth: '@',
|
|
21
|
-
labelWidth: '@',
|
|
22
|
-
addButtonEnable: '=',
|
|
23
|
-
addButtonFunction: '&',
|
|
24
|
-
objValue: '@', // Optional - default is 'value'
|
|
25
|
-
objKey: '@?', // Optional - default is 'id'. Used only when returnOnlyKey=true
|
|
26
|
-
selectedIsObj: '@', // Optional parameter.
|
|
27
|
-
nullable: '@', // No selection is possible
|
|
28
|
-
required: '=', // Model cannot be NULL
|
|
29
|
-
showTax: '@', // Shows tax rate
|
|
30
|
-
noMargin: '@', // margin-bottom: 0px
|
|
31
|
-
multiple: '@', // Can select multiple items
|
|
32
|
-
help: '@',
|
|
33
|
-
listenKeydown: '@',
|
|
34
|
-
noOptionsText: '@',
|
|
35
|
-
isInline: '=',
|
|
36
|
-
onChange: '&?'
|
|
37
|
-
},
|
|
38
|
-
controller: function ($scope, $element, gettextCatalog) {
|
|
39
|
-
console.warn("[NICE ELEMENTS] nice-dropdown-old component is deprecated!");
|
|
40
|
-
|
|
41
|
-
if (!$scope.objValue) { $scope.objValue = 'value'; }
|
|
42
|
-
if (!$scope.objKey) { $scope.objKey = 'id'; }
|
|
43
|
-
if (!$scope.list) { $scope.list = []; }
|
|
44
|
-
if (!$scope.noOptionsText) { $scope.noOptionsText = gettextCatalog.getString("No options", null, "Nice"); }
|
|
45
|
-
if (!$scope.addButtonFunction) { $scope.addButtonFunction = null; }
|
|
46
|
-
if (!$scope.listenKeydown) { $scope.listenKeydown = false; }
|
|
47
|
-
$scope.valid = $scope.formDropdown;
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
$scope.selectedIsObj = $scope.selectedIsObj === 'true' || $scope.selectedIsObj === true;
|
|
51
|
-
$scope.nullable = $scope.nullable === 'true' || $scope.nullable === true;
|
|
52
|
-
$scope.required = $scope.required === 'true' || $scope.required === true;
|
|
53
|
-
$scope.showTax = $scope.showTax === 'true' || $scope.showTax === true;
|
|
54
|
-
$scope.noMargin = $scope.noMargin === 'true' || $scope.noMargin === true;
|
|
55
|
-
$scope.multiple = $scope.multiple === 'true' || $scope.multiple === true;
|
|
56
|
-
|
|
57
|
-
$scope.internalSelected = null;
|
|
58
|
-
$scope.id = Math.random().toString(36).substring(7);
|
|
59
|
-
|
|
60
|
-
$scope.isOpen = false;
|
|
61
|
-
$scope.toggle = function () { $scope.isOpen = !$scope.isOpen; };
|
|
62
|
-
$scope.close = function () { $scope.isOpen = false; };
|
|
63
|
-
$scope.open = function () { $scope.isOpen = true; };
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
// ----------------------------------- Get filter -----------------------------------
|
|
67
|
-
var getFilter = function (item) {
|
|
68
|
-
// Create filter for finding object by objValue with _.where()
|
|
69
|
-
var filter = {};
|
|
70
|
-
if (item.hasOwnProperty($scope.objKey))
|
|
71
|
-
filter[$scope.objKey] = item[$scope.objKey];
|
|
72
|
-
else
|
|
73
|
-
filter[$scope.objKey] = item;
|
|
74
|
-
return filter;
|
|
75
|
-
};
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
// ----------------------------------- Set internal list -----------------------------------
|
|
79
|
-
var _set_internal_list = function () {
|
|
80
|
-
$scope.internalList = angular.copy($scope.list);
|
|
81
|
-
};
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
// ----------------------------------- Add null object to internal list -----------------------------------
|
|
85
|
-
var _add_null_object_to_internal = function () {
|
|
86
|
-
if ($scope.nullable && !$scope.multiple) {
|
|
87
|
-
var nullObj = {};
|
|
88
|
-
nullObj[$scope.objKey] = null;
|
|
89
|
-
nullObj[$scope.objValue] = '-';
|
|
90
|
-
$scope.internalList = [nullObj].concat($scope.internalList);
|
|
91
|
-
}
|
|
92
|
-
};
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
// ----------------------------------- Get selected object -----------------------------------
|
|
96
|
-
var _get_selected_object = function (selected) {
|
|
97
|
-
if (!selected) return null;
|
|
98
|
-
if ($scope.selectedIsObj) {
|
|
99
|
-
return selected;
|
|
100
|
-
} else {
|
|
101
|
-
return _.find($scope.internalList, getFilter(selected));
|
|
102
|
-
}
|
|
103
|
-
};
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
// ----------------------------------- Init -----------------------------------
|
|
107
|
-
var _set_internal_selected_one = function (selected) {
|
|
108
|
-
var obj = {};
|
|
109
|
-
|
|
110
|
-
var selectedObj = _get_selected_object(selected);
|
|
111
|
-
// console.log('_set_internal_selected_one', selected, selectedObj);
|
|
112
|
-
if (selectedObj && _.find($scope.internalList, getFilter(selected))) {
|
|
113
|
-
obj = selectedObj;
|
|
114
|
-
} else {
|
|
115
|
-
obj = $scope.internalList[0];
|
|
116
|
-
}
|
|
117
|
-
$scope.internalSelected = obj;
|
|
118
|
-
_set_model(obj);
|
|
119
|
-
};
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
// ----------------------------------- Get selected objects -----------------------------------
|
|
123
|
-
var _get_selected_objects = function (selected) {
|
|
124
|
-
if (!selected)
|
|
125
|
-
return null;
|
|
126
|
-
|
|
127
|
-
if ($scope.selectedIsObj)
|
|
128
|
-
return selected;
|
|
129
|
-
else {
|
|
130
|
-
// from [1,2,3] get list of objects [{}, {}, {}]
|
|
131
|
-
return _.map(selected, function (val) {
|
|
132
|
-
return _.find($scope.internalList, getFilter(val));
|
|
133
|
-
});
|
|
134
|
-
}
|
|
135
|
-
};
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
// ----------------------------------- Set internal selected multiple -----------------------------------
|
|
139
|
-
var _set_internal_selected_multiple = function (item) {
|
|
140
|
-
var _selected_objects = _get_selected_objects(item);
|
|
141
|
-
if (_selected_objects) {
|
|
142
|
-
$scope.internalSelected = _selected_objects;
|
|
143
|
-
_set_model($scope.internalSelected);
|
|
144
|
-
} else {
|
|
145
|
-
$scope.internalSelected = [];
|
|
146
|
-
_set_model($scope.internalSelected);
|
|
147
|
-
}
|
|
148
|
-
};
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
// ----------------------------------- Set model -----------------------------------
|
|
152
|
-
var _set_model = function (value) {
|
|
153
|
-
var _new = angular.copy($scope.model);
|
|
154
|
-
|
|
155
|
-
if (!$scope.multiple) {
|
|
156
|
-
if (value[$scope.objKey] == null) {
|
|
157
|
-
_new = null;
|
|
158
|
-
} else {
|
|
159
|
-
if ($scope.selectedIsObj) {
|
|
160
|
-
_new = value;
|
|
161
|
-
} else {
|
|
162
|
-
_new = value[$scope.objKey];
|
|
163
|
-
}
|
|
164
|
-
}
|
|
165
|
-
} else {
|
|
166
|
-
if ($scope.selectedIsObj) {
|
|
167
|
-
_new = value;
|
|
168
|
-
} else {
|
|
169
|
-
_new = _.map(value, function (val) {
|
|
170
|
-
return val[$scope.objKey];
|
|
171
|
-
});
|
|
172
|
-
}
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
// update model only if it is changed
|
|
176
|
-
if (!_.isEqual(_new, $scope.model)) {
|
|
177
|
-
$scope.model = _new;
|
|
178
|
-
if ($scope.onChange) $scope.onChange({ model: $scope.model });
|
|
179
|
-
}
|
|
180
|
-
};
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
// ----------------------------------- Init -----------------------------------
|
|
184
|
-
var init = function () {
|
|
185
|
-
_set_internal_list();
|
|
186
|
-
_add_null_object_to_internal();
|
|
187
|
-
|
|
188
|
-
if ($scope.multiple && $scope.model) {
|
|
189
|
-
if ($scope.internalSelected) {
|
|
190
|
-
// remove already selected but not in list - this happens when list changes from outside
|
|
191
|
-
_set_internal_selected_multiple(_.filter($scope.internalSelected, function (obj) {
|
|
192
|
-
return _.find($scope.internalList, getFilter(obj));
|
|
193
|
-
}));
|
|
194
|
-
} else {
|
|
195
|
-
$scope.internalSelected = [];
|
|
196
|
-
}
|
|
197
|
-
}
|
|
198
|
-
|
|
199
|
-
// Set internalSelected
|
|
200
|
-
if ($scope.internalList && $scope.internalList.length > 0) {
|
|
201
|
-
$scope.emptyList = false;
|
|
202
|
-
|
|
203
|
-
if ($scope.multiple) {
|
|
204
|
-
_set_internal_selected_multiple($scope.model);
|
|
205
|
-
} else {
|
|
206
|
-
_set_internal_selected_one($scope.model);
|
|
207
|
-
}
|
|
208
|
-
|
|
209
|
-
if ($scope.formDropdown && $scope.required) {
|
|
210
|
-
$scope.formDropdown.$setValidity('required', true);
|
|
211
|
-
}
|
|
212
|
-
} else {
|
|
213
|
-
// Disable dropdown button if list of items is empty
|
|
214
|
-
$scope.emptyList = true;
|
|
215
|
-
var sel = {};
|
|
216
|
-
sel[$scope.objKey] = null;
|
|
217
|
-
sel[$scope.objValue] = $scope.noOptionsText;
|
|
218
|
-
$scope.internalList = [sel];
|
|
219
|
-
|
|
220
|
-
if ($scope.formDropdown && $scope.required) {
|
|
221
|
-
$scope.formDropdown.$setValidity('required', false); // Form is not valid because dropdown is empty and required
|
|
222
|
-
}
|
|
223
|
-
|
|
224
|
-
if ($scope.multiple) {
|
|
225
|
-
_set_internal_selected_multiple(sel);
|
|
226
|
-
} else {
|
|
227
|
-
_set_internal_selected_one([sel]);
|
|
228
|
-
}
|
|
229
|
-
}
|
|
230
|
-
};
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
// ----------------------------------- Is Item selected -----------------------------------
|
|
234
|
-
$scope.isItemSelected = function (item) {
|
|
235
|
-
if (!$scope.internalSelected) return false;
|
|
236
|
-
|
|
237
|
-
// Which item is selected
|
|
238
|
-
if ($scope.multiple) {
|
|
239
|
-
return _.where($scope.internalSelected, { 'id': item.id }).length > 0;
|
|
240
|
-
} else {
|
|
241
|
-
return $scope.internalSelected[$scope.objKey] == item[$scope.objKey];
|
|
242
|
-
}
|
|
243
|
-
};
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
// ----------------------------------- Item clicked -----------------------------------
|
|
247
|
-
$scope.clicked = function (item) {
|
|
248
|
-
$scope.formDropdown.$setDirty();
|
|
249
|
-
if ($scope.multiple) {
|
|
250
|
-
// This actually toggles selection
|
|
251
|
-
var _current = angular.copy($scope.internalSelected);
|
|
252
|
-
if (!_.find(_current, getFilter(item))) {
|
|
253
|
-
_current.push(item);
|
|
254
|
-
} else {
|
|
255
|
-
_current = _.reject(_current, getFilter(item[$scope.objKey]));
|
|
256
|
-
}
|
|
257
|
-
_set_internal_selected_multiple(_current);
|
|
258
|
-
} else {
|
|
259
|
-
_set_internal_selected_one(item);
|
|
260
|
-
$scope.close();
|
|
261
|
-
}
|
|
262
|
-
|
|
263
|
-
};
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
// ----------------------------------- Get label -----------------------------------
|
|
267
|
-
$scope.getLabel = function (item) {
|
|
268
|
-
if (item) {
|
|
269
|
-
return item[$scope.objValue];
|
|
270
|
-
} else {
|
|
271
|
-
return '-';
|
|
272
|
-
}
|
|
273
|
-
};
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
// ----------------------------------- Watch for list change -----------------------------------
|
|
277
|
-
$scope.$watch('list', function (value_new, value_old) {
|
|
278
|
-
init();
|
|
279
|
-
});
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
// ----------------------------------- Watch for model change -----------------------------------
|
|
283
|
-
$scope.$watch('model', function (value_new, value_old) {
|
|
284
|
-
if ($scope.multiple) {
|
|
285
|
-
var _new_model_object = _get_selected_object(value_new);
|
|
286
|
-
} else {
|
|
287
|
-
var _new_model_object = _get_selected_objects(value_new);
|
|
288
|
-
}
|
|
289
|
-
|
|
290
|
-
if (!_.isEqual(_new_model_object, $scope.internalSelected)) {
|
|
291
|
-
init();
|
|
292
|
-
}
|
|
293
|
-
});
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
// ----------------------------------- Listen keydown -----------------------------------
|
|
297
|
-
$scope.bindKeypress = function () {
|
|
298
|
-
if ($scope.listenKeydown) {
|
|
299
|
-
$element.bind('keyup', function (e) {
|
|
300
|
-
// bind to keypress events if dropdown list is opened
|
|
301
|
-
if ($scope.isOpen) {
|
|
302
|
-
var char = String.fromCharCode(e.which).toLowerCase();
|
|
303
|
-
|
|
304
|
-
// find first element with value starting on selected char
|
|
305
|
-
var index = _.findIndex($scope.internalList, function (item) {
|
|
306
|
-
var _name = item[$scope.objValue].toLowerCase();
|
|
307
|
-
return _name.indexOf(char) === 0;
|
|
308
|
-
});
|
|
309
|
-
|
|
310
|
-
if (index >= 0) {
|
|
311
|
-
// scroll within dropdown list to selected index
|
|
312
|
-
// var _id_name = '#' + $scope.id + '-' + index;
|
|
313
|
-
// var _id_first = '#' + $scope.id + '-0';
|
|
314
|
-
// var _relative_top = Math.abs($(_id_first).offset().top - $(_id_name).offset().top);
|
|
315
|
-
// if (_relative_top >= 0){
|
|
316
|
-
// $("#" + $scope.id).animate({scrollTop: _relative_top}, 100);
|
|
317
|
-
// }
|
|
318
|
-
}
|
|
319
|
-
}
|
|
320
|
-
});
|
|
321
|
-
}
|
|
322
|
-
};
|
|
323
|
-
|
|
324
|
-
$scope.unbindKeypress = function () {
|
|
325
|
-
$element.off('keyup', function (e) { });
|
|
326
|
-
};
|
|
327
|
-
|
|
328
|
-
}
|
|
329
|
-
};
|
|
330
|
-
});
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @ngdoc directive
|
|
5
|
+
* @name niceElements.directive:niceDropdownOld
|
|
6
|
+
* @description
|
|
7
|
+
* # niceDropdownOld
|
|
8
|
+
*/
|
|
9
|
+
angular.module('niceElements')
|
|
10
|
+
.directive('niceDropdownOld', function () {
|
|
11
|
+
return {
|
|
12
|
+
templateUrl: 'src/components/nice-dropdown-old/nice-dropdown-old.html',
|
|
13
|
+
restrict: 'E',
|
|
14
|
+
transclude: true,
|
|
15
|
+
scope: {
|
|
16
|
+
title: '@', // Title of the field
|
|
17
|
+
model: '=', // Aka model
|
|
18
|
+
list: '=', // List of options
|
|
19
|
+
isDisabled: '=',
|
|
20
|
+
fieldWidth: '@',
|
|
21
|
+
labelWidth: '@',
|
|
22
|
+
addButtonEnable: '=',
|
|
23
|
+
addButtonFunction: '&',
|
|
24
|
+
objValue: '@', // Optional - default is 'value'
|
|
25
|
+
objKey: '@?', // Optional - default is 'id'. Used only when returnOnlyKey=true
|
|
26
|
+
selectedIsObj: '@', // Optional parameter.
|
|
27
|
+
nullable: '@', // No selection is possible
|
|
28
|
+
required: '=', // Model cannot be NULL
|
|
29
|
+
showTax: '@', // Shows tax rate
|
|
30
|
+
noMargin: '@', // margin-bottom: 0px
|
|
31
|
+
multiple: '@', // Can select multiple items
|
|
32
|
+
help: '@',
|
|
33
|
+
listenKeydown: '@',
|
|
34
|
+
noOptionsText: '@',
|
|
35
|
+
isInline: '=',
|
|
36
|
+
onChange: '&?'
|
|
37
|
+
},
|
|
38
|
+
controller: function ($scope, $element, gettextCatalog) {
|
|
39
|
+
console.warn("[NICE ELEMENTS] nice-dropdown-old component is deprecated!");
|
|
40
|
+
|
|
41
|
+
if (!$scope.objValue) { $scope.objValue = 'value'; }
|
|
42
|
+
if (!$scope.objKey) { $scope.objKey = 'id'; }
|
|
43
|
+
if (!$scope.list) { $scope.list = []; }
|
|
44
|
+
if (!$scope.noOptionsText) { $scope.noOptionsText = gettextCatalog.getString("No options", null, "Nice"); }
|
|
45
|
+
if (!$scope.addButtonFunction) { $scope.addButtonFunction = null; }
|
|
46
|
+
if (!$scope.listenKeydown) { $scope.listenKeydown = false; }
|
|
47
|
+
$scope.valid = $scope.formDropdown;
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
$scope.selectedIsObj = $scope.selectedIsObj === 'true' || $scope.selectedIsObj === true;
|
|
51
|
+
$scope.nullable = $scope.nullable === 'true' || $scope.nullable === true;
|
|
52
|
+
$scope.required = $scope.required === 'true' || $scope.required === true;
|
|
53
|
+
$scope.showTax = $scope.showTax === 'true' || $scope.showTax === true;
|
|
54
|
+
$scope.noMargin = $scope.noMargin === 'true' || $scope.noMargin === true;
|
|
55
|
+
$scope.multiple = $scope.multiple === 'true' || $scope.multiple === true;
|
|
56
|
+
|
|
57
|
+
$scope.internalSelected = null;
|
|
58
|
+
$scope.id = Math.random().toString(36).substring(7);
|
|
59
|
+
|
|
60
|
+
$scope.isOpen = false;
|
|
61
|
+
$scope.toggle = function () { $scope.isOpen = !$scope.isOpen; };
|
|
62
|
+
$scope.close = function () { $scope.isOpen = false; };
|
|
63
|
+
$scope.open = function () { $scope.isOpen = true; };
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
// ----------------------------------- Get filter -----------------------------------
|
|
67
|
+
var getFilter = function (item) {
|
|
68
|
+
// Create filter for finding object by objValue with _.where()
|
|
69
|
+
var filter = {};
|
|
70
|
+
if (item.hasOwnProperty($scope.objKey))
|
|
71
|
+
filter[$scope.objKey] = item[$scope.objKey];
|
|
72
|
+
else
|
|
73
|
+
filter[$scope.objKey] = item;
|
|
74
|
+
return filter;
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
// ----------------------------------- Set internal list -----------------------------------
|
|
79
|
+
var _set_internal_list = function () {
|
|
80
|
+
$scope.internalList = angular.copy($scope.list);
|
|
81
|
+
};
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
// ----------------------------------- Add null object to internal list -----------------------------------
|
|
85
|
+
var _add_null_object_to_internal = function () {
|
|
86
|
+
if ($scope.nullable && !$scope.multiple) {
|
|
87
|
+
var nullObj = {};
|
|
88
|
+
nullObj[$scope.objKey] = null;
|
|
89
|
+
nullObj[$scope.objValue] = '-';
|
|
90
|
+
$scope.internalList = [nullObj].concat($scope.internalList);
|
|
91
|
+
}
|
|
92
|
+
};
|
|
93
|
+
|
|
94
|
+
|
|
95
|
+
// ----------------------------------- Get selected object -----------------------------------
|
|
96
|
+
var _get_selected_object = function (selected) {
|
|
97
|
+
if (!selected) return null;
|
|
98
|
+
if ($scope.selectedIsObj) {
|
|
99
|
+
return selected;
|
|
100
|
+
} else {
|
|
101
|
+
return _.find($scope.internalList, getFilter(selected));
|
|
102
|
+
}
|
|
103
|
+
};
|
|
104
|
+
|
|
105
|
+
|
|
106
|
+
// ----------------------------------- Init -----------------------------------
|
|
107
|
+
var _set_internal_selected_one = function (selected) {
|
|
108
|
+
var obj = {};
|
|
109
|
+
|
|
110
|
+
var selectedObj = _get_selected_object(selected);
|
|
111
|
+
// console.log('_set_internal_selected_one', selected, selectedObj);
|
|
112
|
+
if (selectedObj && _.find($scope.internalList, getFilter(selected))) {
|
|
113
|
+
obj = selectedObj;
|
|
114
|
+
} else {
|
|
115
|
+
obj = $scope.internalList[0];
|
|
116
|
+
}
|
|
117
|
+
$scope.internalSelected = obj;
|
|
118
|
+
_set_model(obj);
|
|
119
|
+
};
|
|
120
|
+
|
|
121
|
+
|
|
122
|
+
// ----------------------------------- Get selected objects -----------------------------------
|
|
123
|
+
var _get_selected_objects = function (selected) {
|
|
124
|
+
if (!selected)
|
|
125
|
+
return null;
|
|
126
|
+
|
|
127
|
+
if ($scope.selectedIsObj)
|
|
128
|
+
return selected;
|
|
129
|
+
else {
|
|
130
|
+
// from [1,2,3] get list of objects [{}, {}, {}]
|
|
131
|
+
return _.map(selected, function (val) {
|
|
132
|
+
return _.find($scope.internalList, getFilter(val));
|
|
133
|
+
});
|
|
134
|
+
}
|
|
135
|
+
};
|
|
136
|
+
|
|
137
|
+
|
|
138
|
+
// ----------------------------------- Set internal selected multiple -----------------------------------
|
|
139
|
+
var _set_internal_selected_multiple = function (item) {
|
|
140
|
+
var _selected_objects = _get_selected_objects(item);
|
|
141
|
+
if (_selected_objects) {
|
|
142
|
+
$scope.internalSelected = _selected_objects;
|
|
143
|
+
_set_model($scope.internalSelected);
|
|
144
|
+
} else {
|
|
145
|
+
$scope.internalSelected = [];
|
|
146
|
+
_set_model($scope.internalSelected);
|
|
147
|
+
}
|
|
148
|
+
};
|
|
149
|
+
|
|
150
|
+
|
|
151
|
+
// ----------------------------------- Set model -----------------------------------
|
|
152
|
+
var _set_model = function (value) {
|
|
153
|
+
var _new = angular.copy($scope.model);
|
|
154
|
+
|
|
155
|
+
if (!$scope.multiple) {
|
|
156
|
+
if (value[$scope.objKey] == null) {
|
|
157
|
+
_new = null;
|
|
158
|
+
} else {
|
|
159
|
+
if ($scope.selectedIsObj) {
|
|
160
|
+
_new = value;
|
|
161
|
+
} else {
|
|
162
|
+
_new = value[$scope.objKey];
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
} else {
|
|
166
|
+
if ($scope.selectedIsObj) {
|
|
167
|
+
_new = value;
|
|
168
|
+
} else {
|
|
169
|
+
_new = _.map(value, function (val) {
|
|
170
|
+
return val[$scope.objKey];
|
|
171
|
+
});
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
// update model only if it is changed
|
|
176
|
+
if (!_.isEqual(_new, $scope.model)) {
|
|
177
|
+
$scope.model = _new;
|
|
178
|
+
if ($scope.onChange) $scope.onChange({ model: $scope.model });
|
|
179
|
+
}
|
|
180
|
+
};
|
|
181
|
+
|
|
182
|
+
|
|
183
|
+
// ----------------------------------- Init -----------------------------------
|
|
184
|
+
var init = function () {
|
|
185
|
+
_set_internal_list();
|
|
186
|
+
_add_null_object_to_internal();
|
|
187
|
+
|
|
188
|
+
if ($scope.multiple && $scope.model) {
|
|
189
|
+
if ($scope.internalSelected) {
|
|
190
|
+
// remove already selected but not in list - this happens when list changes from outside
|
|
191
|
+
_set_internal_selected_multiple(_.filter($scope.internalSelected, function (obj) {
|
|
192
|
+
return _.find($scope.internalList, getFilter(obj));
|
|
193
|
+
}));
|
|
194
|
+
} else {
|
|
195
|
+
$scope.internalSelected = [];
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
// Set internalSelected
|
|
200
|
+
if ($scope.internalList && $scope.internalList.length > 0) {
|
|
201
|
+
$scope.emptyList = false;
|
|
202
|
+
|
|
203
|
+
if ($scope.multiple) {
|
|
204
|
+
_set_internal_selected_multiple($scope.model);
|
|
205
|
+
} else {
|
|
206
|
+
_set_internal_selected_one($scope.model);
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
if ($scope.formDropdown && $scope.required) {
|
|
210
|
+
$scope.formDropdown.$setValidity('required', true);
|
|
211
|
+
}
|
|
212
|
+
} else {
|
|
213
|
+
// Disable dropdown button if list of items is empty
|
|
214
|
+
$scope.emptyList = true;
|
|
215
|
+
var sel = {};
|
|
216
|
+
sel[$scope.objKey] = null;
|
|
217
|
+
sel[$scope.objValue] = $scope.noOptionsText;
|
|
218
|
+
$scope.internalList = [sel];
|
|
219
|
+
|
|
220
|
+
if ($scope.formDropdown && $scope.required) {
|
|
221
|
+
$scope.formDropdown.$setValidity('required', false); // Form is not valid because dropdown is empty and required
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
if ($scope.multiple) {
|
|
225
|
+
_set_internal_selected_multiple(sel);
|
|
226
|
+
} else {
|
|
227
|
+
_set_internal_selected_one([sel]);
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
};
|
|
231
|
+
|
|
232
|
+
|
|
233
|
+
// ----------------------------------- Is Item selected -----------------------------------
|
|
234
|
+
$scope.isItemSelected = function (item) {
|
|
235
|
+
if (!$scope.internalSelected) return false;
|
|
236
|
+
|
|
237
|
+
// Which item is selected
|
|
238
|
+
if ($scope.multiple) {
|
|
239
|
+
return _.where($scope.internalSelected, { 'id': item.id }).length > 0;
|
|
240
|
+
} else {
|
|
241
|
+
return $scope.internalSelected[$scope.objKey] == item[$scope.objKey];
|
|
242
|
+
}
|
|
243
|
+
};
|
|
244
|
+
|
|
245
|
+
|
|
246
|
+
// ----------------------------------- Item clicked -----------------------------------
|
|
247
|
+
$scope.clicked = function (item) {
|
|
248
|
+
$scope.formDropdown.$setDirty();
|
|
249
|
+
if ($scope.multiple) {
|
|
250
|
+
// This actually toggles selection
|
|
251
|
+
var _current = angular.copy($scope.internalSelected);
|
|
252
|
+
if (!_.find(_current, getFilter(item))) {
|
|
253
|
+
_current.push(item);
|
|
254
|
+
} else {
|
|
255
|
+
_current = _.reject(_current, getFilter(item[$scope.objKey]));
|
|
256
|
+
}
|
|
257
|
+
_set_internal_selected_multiple(_current);
|
|
258
|
+
} else {
|
|
259
|
+
_set_internal_selected_one(item);
|
|
260
|
+
$scope.close();
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
};
|
|
264
|
+
|
|
265
|
+
|
|
266
|
+
// ----------------------------------- Get label -----------------------------------
|
|
267
|
+
$scope.getLabel = function (item) {
|
|
268
|
+
if (item) {
|
|
269
|
+
return item[$scope.objValue];
|
|
270
|
+
} else {
|
|
271
|
+
return '-';
|
|
272
|
+
}
|
|
273
|
+
};
|
|
274
|
+
|
|
275
|
+
|
|
276
|
+
// ----------------------------------- Watch for list change -----------------------------------
|
|
277
|
+
$scope.$watch('list', function (value_new, value_old) {
|
|
278
|
+
init();
|
|
279
|
+
});
|
|
280
|
+
|
|
281
|
+
|
|
282
|
+
// ----------------------------------- Watch for model change -----------------------------------
|
|
283
|
+
$scope.$watch('model', function (value_new, value_old) {
|
|
284
|
+
if ($scope.multiple) {
|
|
285
|
+
var _new_model_object = _get_selected_object(value_new);
|
|
286
|
+
} else {
|
|
287
|
+
var _new_model_object = _get_selected_objects(value_new);
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
if (!_.isEqual(_new_model_object, $scope.internalSelected)) {
|
|
291
|
+
init();
|
|
292
|
+
}
|
|
293
|
+
});
|
|
294
|
+
|
|
295
|
+
|
|
296
|
+
// ----------------------------------- Listen keydown -----------------------------------
|
|
297
|
+
$scope.bindKeypress = function () {
|
|
298
|
+
if ($scope.listenKeydown) {
|
|
299
|
+
$element.bind('keyup', function (e) {
|
|
300
|
+
// bind to keypress events if dropdown list is opened
|
|
301
|
+
if ($scope.isOpen) {
|
|
302
|
+
var char = String.fromCharCode(e.which).toLowerCase();
|
|
303
|
+
|
|
304
|
+
// find first element with value starting on selected char
|
|
305
|
+
var index = _.findIndex($scope.internalList, function (item) {
|
|
306
|
+
var _name = item[$scope.objValue].toLowerCase();
|
|
307
|
+
return _name.indexOf(char) === 0;
|
|
308
|
+
});
|
|
309
|
+
|
|
310
|
+
if (index >= 0) {
|
|
311
|
+
// scroll within dropdown list to selected index
|
|
312
|
+
// var _id_name = '#' + $scope.id + '-' + index;
|
|
313
|
+
// var _id_first = '#' + $scope.id + '-0';
|
|
314
|
+
// var _relative_top = Math.abs($(_id_first).offset().top - $(_id_name).offset().top);
|
|
315
|
+
// if (_relative_top >= 0){
|
|
316
|
+
// $("#" + $scope.id).animate({scrollTop: _relative_top}, 100);
|
|
317
|
+
// }
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
});
|
|
321
|
+
}
|
|
322
|
+
};
|
|
323
|
+
|
|
324
|
+
$scope.unbindKeypress = function () {
|
|
325
|
+
$element.off('keyup', function (e) { });
|
|
326
|
+
};
|
|
327
|
+
|
|
328
|
+
}
|
|
329
|
+
};
|
|
330
|
+
});
|