fng-ui-select 0.12.0-beta.217 → 0.12.0-beta.218
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/package.json +1 -1
- package/src/fng-ui-select.js +19 -18
package/package.json
CHANGED
package/src/fng-ui-select.js
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
|
|
4
4
|
var uiSelectModule = angular.module('fng.uiSelect', ['ui.select']);
|
|
5
5
|
|
|
6
|
-
uiSelectModule.factory('
|
|
6
|
+
uiSelectModule.factory('FngUISelectHelperService', ['$rootScope', '$q', 'RecordHandlerService', 'SubmissionsService', function ($rootScope, $q, RecordHandlerService, SubmissionsService) {
|
|
7
7
|
var lastW, lastH;
|
|
8
8
|
const localLookups = {};
|
|
9
9
|
// this ultra-simple cache stores { [id: string]: stringValue } as a means of avoiding unnecessary network round-trips, and the UI refresh
|
|
@@ -40,6 +40,7 @@
|
|
|
40
40
|
}
|
|
41
41
|
}
|
|
42
42
|
|
|
43
|
+
// NB: the type defs for this service (IFngUISelectHelperService) are in the forms-angular's index.d.ts
|
|
43
44
|
return {
|
|
44
45
|
windowChanged: function (w, h) {
|
|
45
46
|
var result = false;
|
|
@@ -106,17 +107,17 @@
|
|
|
106
107
|
}
|
|
107
108
|
},
|
|
108
109
|
doOwnConversion: function(scope, processedAttrs, ref) {
|
|
109
|
-
var id =
|
|
110
|
+
var id = RecordHandlerService.getData(scope.record, processedAttrs.info.name, scope.$index);
|
|
110
111
|
if (id) {
|
|
111
112
|
id = id.id || id; // in case it's already been converted
|
|
112
|
-
useCacheOrLookItUp(ref, id, (text) => {
|
|
113
|
+
useCacheOrLookItUp(ref, id, (text) => { RecordHandlerService.setData(scope.record, processedAttrs.info.name, scope.$index, { id, text }) });
|
|
113
114
|
}
|
|
114
115
|
}
|
|
115
116
|
};
|
|
116
117
|
}]);
|
|
117
118
|
|
|
118
119
|
|
|
119
|
-
uiSelectModule.controller('FngUISelectCtrl', ['$scope', '$window', '$timeout', '$http', '
|
|
120
|
+
uiSelectModule.controller('FngUISelectCtrl', ['$scope', '$window', '$timeout', '$http', 'FngUISelectHelperService', function ($scope, $window, $timeout, $http, FngUISelectHelperService) {
|
|
120
121
|
|
|
121
122
|
$scope.uiSelect = $scope.uiSelect || [];
|
|
122
123
|
|
|
@@ -124,7 +125,7 @@
|
|
|
124
125
|
// This is to stop the resize firing too often. Really horrible way of doing it caused by some very regrettable
|
|
125
126
|
// design choices which will be factored out later
|
|
126
127
|
// Actually not choices - just not knowing any better
|
|
127
|
-
if (!checkResize ||
|
|
128
|
+
if (!checkResize || FngUISelectHelperService.windowChanged($window.innerWidth, $window.innerHeight)) {
|
|
128
129
|
for (var i = 0; i < $scope.uiSelect.length; i++) {
|
|
129
130
|
var selectId = $scope.uiSelect[i].selectId;
|
|
130
131
|
var select = document.getElementById(selectId);
|
|
@@ -213,8 +214,8 @@
|
|
|
213
214
|
$timeout($scope.windowResizeUiSelect);
|
|
214
215
|
}]);
|
|
215
216
|
|
|
216
|
-
uiSelectModule.directive('fngUiSelect', ['$compile', '
|
|
217
|
-
function ($compile,
|
|
217
|
+
uiSelectModule.directive('fngUiSelect', ['$compile', 'PluginHelperService', 'CssFrameworkService', 'FngUISelectHelperService', '$timeout',
|
|
218
|
+
function ($compile, PluginHelperService, CssFrameworkService, FngUISelectHelperService, $timeout) {
|
|
218
219
|
return {
|
|
219
220
|
restrict: 'E',
|
|
220
221
|
controller: 'FngUISelectCtrl',
|
|
@@ -236,7 +237,7 @@
|
|
|
236
237
|
}
|
|
237
238
|
}
|
|
238
239
|
|
|
239
|
-
const processedAttrs =
|
|
240
|
+
const processedAttrs = PluginHelperService.extractFromAttr(attrs, 'fngUiSelect');
|
|
240
241
|
const id = processedAttrs.info.id;
|
|
241
242
|
const uniqueId = scope.$index !== undefined ? processedAttrs.info.id + "_" + scope.$index : id;
|
|
242
243
|
const elemScope = angular.extend({selectId: uniqueId}, processedAttrs.directiveOptions);
|
|
@@ -251,7 +252,7 @@
|
|
|
251
252
|
// and not with animate (see https://github.com/angular-ui/ui-select/issues/1731 and others)
|
|
252
253
|
var theme = processedAttrs.directiveOptions.theme || 'select2';
|
|
253
254
|
if (theme === 'bootstrap') {
|
|
254
|
-
if (
|
|
255
|
+
if (CssFrameworkService.framework() !== 'bs3') {
|
|
255
256
|
theme = 'select2';
|
|
256
257
|
} else {
|
|
257
258
|
try {
|
|
@@ -269,7 +270,7 @@
|
|
|
269
270
|
if (multi && (processedAttrs.directiveOptions.fngajax || processedAttrs.directiveOptions.forcemultiple)) {
|
|
270
271
|
// We need the array to be an array of objects with a x property. This tells forms-angular to convert it by
|
|
271
272
|
// adding an attribute to the schema.
|
|
272
|
-
|
|
273
|
+
PluginHelperService.findIdInSchemaAndFlagNeedX(scope.baseSchema(), id);
|
|
273
274
|
multiControl = true;
|
|
274
275
|
} else {
|
|
275
276
|
multiStr = multi ? 'multiple close-on-select reset-search-input ' : '';
|
|
@@ -284,7 +285,7 @@
|
|
|
284
285
|
} else {
|
|
285
286
|
allowClearStr = ' allow-clear';
|
|
286
287
|
}
|
|
287
|
-
let disabledStr =
|
|
288
|
+
let disabledStr = PluginHelperService.genIdAndDisabledStr(scope, processedAttrs, "", { forceNg: true });
|
|
288
289
|
|
|
289
290
|
// First of all add a hidden input field which we will use to set the width of the select
|
|
290
291
|
if (!angular.element(`#${uniqueId}_width-helper`).length > 0) {
|
|
@@ -296,7 +297,7 @@
|
|
|
296
297
|
if (processedAttrs.info.size) {
|
|
297
298
|
hiddenInputInfo.size = processedAttrs.info.size;
|
|
298
299
|
}
|
|
299
|
-
input =
|
|
300
|
+
input = PluginHelperService.buildInputMarkup(
|
|
300
301
|
scope,
|
|
301
302
|
attrs,
|
|
302
303
|
{
|
|
@@ -315,8 +316,8 @@
|
|
|
315
316
|
function optionsFromArray(multiControl, multi, array, arrayGetter) {
|
|
316
317
|
var isObjects = scope[array] && (scope[array].isObjects || typeof scope[array][0] === "object");
|
|
317
318
|
if (isObjects) {
|
|
318
|
-
addToConversions(processedAttrs.info.name, {fngajax:
|
|
319
|
-
|
|
319
|
+
addToConversions(processedAttrs.info.name, {fngajax: FngUISelectHelperService.lookupFunc});
|
|
320
|
+
FngUISelectHelperService.addClientLookup(arrayGetter, scope[array]);
|
|
320
321
|
}
|
|
321
322
|
var select = '';
|
|
322
323
|
if (multiControl) {
|
|
@@ -330,7 +331,7 @@
|
|
|
330
331
|
return select;
|
|
331
332
|
}
|
|
332
333
|
|
|
333
|
-
elementHtml =
|
|
334
|
+
elementHtml = PluginHelperService.buildInputMarkup(
|
|
334
335
|
scope,
|
|
335
336
|
attrs,
|
|
336
337
|
{
|
|
@@ -366,7 +367,7 @@
|
|
|
366
367
|
// if we have a hard-coded ref (processedAttrs.info.ref), forms-angular can perform the lookup conversion for us.
|
|
367
368
|
// where processedAttrs.directiveOptions.refprop is being used instead, the ref is 'variable' - it comes from a property of scope.record, and
|
|
368
369
|
// in this case, we'll need to handle the conversions ourselves.
|
|
369
|
-
addToConversions(processedAttrs.info.name, {fngajax:
|
|
370
|
+
addToConversions(processedAttrs.info.name, {fngajax: FngUISelectHelperService.lookupFunc, noconvert: !!processedAttrs.directiveOptions.refprop});
|
|
370
371
|
if (processedAttrs.directiveOptions.refprop) {
|
|
371
372
|
// the property that we'll be getting the ref from may not be populated yet, and might conceivably change at any time, so we
|
|
372
373
|
// need to $watch it. buildingBlocks.modelString will be something like "record.<array>[$index].<field>". replacing <field>
|
|
@@ -375,7 +376,7 @@
|
|
|
375
376
|
scope.$watch(watchStr, (newValue) => {
|
|
376
377
|
if (newValue && elemScope.ref !== newValue) {
|
|
377
378
|
elemScope.ref = newValue;
|
|
378
|
-
|
|
379
|
+
FngUISelectHelperService.doOwnConversion(scope, processedAttrs, elemScope.ref);
|
|
379
380
|
}
|
|
380
381
|
});
|
|
381
382
|
// we also need to re-do the conversion if the user cancels changes. this event does fire on more than just user cancellation,
|
|
@@ -383,7 +384,7 @@
|
|
|
383
384
|
scope.$on("fngCancel", () => {
|
|
384
385
|
$timeout(() => {
|
|
385
386
|
if (elemScope.ref) {
|
|
386
|
-
|
|
387
|
+
FngUISelectHelperService.doOwnConversion(scope, processedAttrs, elemScope.ref);
|
|
387
388
|
}
|
|
388
389
|
});
|
|
389
390
|
});
|