Skip to content

Commit c310a4c

Browse files
committed
Fix formatting
1 parent ef0a602 commit c310a4c

File tree

1 file changed

+97
-94
lines changed

1 file changed

+97
-94
lines changed

src/angular-schema-form-dynamic-select.js

Lines changed: 97 additions & 94 deletions
Original file line numberDiff line numberDiff line change
@@ -38,67 +38,69 @@ angular.module('schemaForm').config(
3838

3939

4040
}])
41-
.directive("toggleSingleModel", function() {
42-
// some how we get this to work ...
43-
return {
44-
require: 'ngModel',
45-
restrict: "A",
46-
scope: {},
47-
replace: true,
48-
controller: ['$scope', function($scope) {
49-
$scope.$parent.$watch('select_model.selected',function(){
50-
if($scope.$parent.select_model.selected != undefined) {
51-
$scope.$parent.insideModel = $scope.$parent.select_model.selected.value;
52-
$scope.$parent.ngModel.$setViewValue($scope.$parent.select_model.selected.value);
53-
}
54-
});
55-
}]
56-
};
57-
})
58-
59-
.directive('multipleOn', function() {
60-
return {
61-
link: function($scope, $element, $attrs) {
62-
$scope.$watch(
63-
function () { return $element.attr('multiple-on'); },
64-
function (newVal) {
65-
66-
if(newVal == "true") {
67-
var select_scope = angular.element($element).scope().$$childTail;
68-
select_scope.$isMultiple = true;
69-
select_scope.options.multiple = true;
70-
select_scope.$select.$element.addClass('select-multiple');
71-
}
72-
else {
73-
angular.element($element).scope().$$childTail.$isMultiple = false;
74-
}
41+
.directive("toggleSingleModel", function () {
42+
// some how we get this to work ...
43+
return {
44+
require: 'ngModel',
45+
restrict: "A",
46+
scope: {},
47+
replace: true,
48+
controller: ['$scope', function ($scope) {
49+
$scope.$parent.$watch('select_model.selected', function () {
50+
if ($scope.$parent.select_model.selected != undefined) {
51+
$scope.$parent.insideModel = $scope.$parent.select_model.selected.value;
52+
$scope.$parent.ngModel.$setViewValue($scope.$parent.select_model.selected.value);
53+
}
54+
});
55+
}]
56+
};
57+
})
58+
59+
.directive('multipleOn', function () {
60+
return {
61+
link: function ($scope, $element, $attrs) {
62+
$scope.$watch(
63+
function () {
64+
return $element.attr('multiple-on');
65+
},
66+
function (newVal) {
67+
68+
if (newVal == "true") {
69+
var select_scope = angular.element($element).scope().$$childTail;
70+
select_scope.$isMultiple = true;
71+
select_scope.options.multiple = true;
72+
select_scope.$select.$element.addClass('select-multiple');
73+
}
74+
else {
75+
angular.element($element).scope().$$childTail.$isMultiple = false;
76+
}
77+
}
78+
);
7579
}
76-
);
77-
}
78-
};
79-
})
80-
.filter('whereMulti', function() {
81-
return function(items, key, values) {
82-
var out = [];
83-
84-
if (angular.isArray(values) && items !== undefined) {
85-
values.forEach(function (value) {
86-
for (var i = 0; i < items.length; i++) {
87-
if (value == items[i][key]) {
88-
out.push(items[i]);
89-
break;
90-
}
91-
}
92-
});
93-
} else {
94-
// Let the output be the input untouched
95-
out = items;
96-
}
97-
98-
return out;
99-
};
100-
})
101-
.filter('propsFilter', function() {
80+
};
81+
})
82+
.filter('whereMulti', function () {
83+
return function (items, key, values) {
84+
var out = [];
85+
86+
if (angular.isArray(values) && items !== undefined) {
87+
values.forEach(function (value) {
88+
for (var i = 0; i < items.length; i++) {
89+
if (value == items[i][key]) {
90+
out.push(items[i]);
91+
break;
92+
}
93+
}
94+
});
95+
} else {
96+
// Let the output be the input untouched
97+
out = items;
98+
}
99+
100+
return out;
101+
};
102+
})
103+
.filter('propsFilter', function () {
102104
return function (items, props) {
103105
var out = [];
104106

@@ -148,7 +150,9 @@ angular.module('schemaForm').controller('dynamicSelectController', ['$scope', '$
148150
console.log("listener triggered");
149151
// Ugly workaround to trigger titleMap expression re-evaluation so that the selectFilter it reapplied.
150152
$scope.form.titleMap.push({"value": "345890u340598u3405u9", "name": "34095u3p4ouij"})
151-
$timeout(function () { $scope.form.titleMap.pop() })
153+
$timeout(function () {
154+
$scope.form.titleMap.pop()
155+
})
152156

153157
};
154158

@@ -160,7 +164,7 @@ angular.module('schemaForm').controller('dynamicSelectController', ['$scope', '$
160164
});
161165
}
162166
// This is set here, as the model value may become unitialized and typeless if validation fails.
163-
$scope.localModelType = Object.prototype.toString.call(localModel);
167+
$scope.localModelType = Object.prototype.toString.call(localModel);
164168
$scope.filteringInitialized = true;
165169
};
166170

@@ -170,25 +174,27 @@ angular.module('schemaForm').controller('dynamicSelectController', ['$scope', '$
170174

171175
form.titleMap = [];
172176

173-
if (newOptions && "map" in newOptions && newOptions .map) {
177+
if (newOptions && "map" in newOptions && newOptions.map) {
174178
var current_row = null,
175-
final = newOptions.map.nameProperty.length - 1,
176-
separator = newOptions.map.separatorValue ? newOptions.map.separatorValue : ' - ';
177-
data.forEach(function (current_row) {
178-
current_row["value"] = current_row[newOptions .map.valueProperty];
179-
current_row["name"] = ""; //init the 'name' property
180-
//check if the value passed is a string or not
181-
if(typeof newOptions.map.nameProperty != 'string'){
182-
//loop through the object/array
183-
for (var i in newOptions.map.nameProperty) {
184-
current_row["name"] += current_row[newOptions .map.nameProperty[i]];
185-
if(i != final){current_row["name"] += separator};
186-
}
187-
}
188-
else{
189-
//if it is a string
190-
current_row["name"] = current_row[newOptions .map.nameProperty];
191-
}
179+
final = newOptions.map.nameProperty.length - 1,
180+
separator = newOptions.map.separatorValue ? newOptions.map.separatorValue : ' - ';
181+
data.forEach(function (current_row) {
182+
current_row["value"] = current_row[newOptions.map.valueProperty];
183+
current_row["name"] = ""; //init the 'name' property
184+
//check if the value passed is a string or not
185+
if (typeof newOptions.map.nameProperty != 'string') {
186+
//loop through the object/array
187+
for (var i in newOptions.map.nameProperty) {
188+
current_row["name"] += current_row[newOptions.map.nameProperty[i]];
189+
if (i != final) {
190+
current_row["name"] += separator
191+
};
192+
}
193+
}
194+
else {
195+
//if it is a string
196+
current_row["name"] = current_row[newOptions.map.nameProperty];
197+
}
192198
form.titleMap.push(current_row);
193199
});
194200

@@ -204,7 +210,7 @@ angular.module('schemaForm').controller('dynamicSelectController', ['$scope', '$
204210
}
205211

206212
if ($scope.insideModel && $scope.select_model.selected === undefined) {
207-
$scope.select_model.selected = $scope.find_in_titleMap($scope.insideModel);
213+
$scope.select_model.selected = $scope.find_in_titleMap($scope.insideModel);
208214
}
209215

210216
// The ui-selects needs to be reinitialized (UI select sets the internalModel and externalModel.
@@ -286,7 +292,7 @@ angular.module('schemaForm').controller('dynamicSelectController', ['$scope', '$
286292
}
287293
else if (form.options.callback) {
288294
form.titleMap = $scope.getCallback(form.options.callback)(form.options, search);
289-
$scope.finalizeTitleMap(form,form.titleMap, form.options);
295+
$scope.finalizeTitleMap(form, form.titleMap, form.options);
290296
console.log("callback items: ", form.titleMap);
291297
}
292298
else if (form.options.asyncCallback) {
@@ -301,7 +307,7 @@ angular.module('schemaForm').controller('dynamicSelectController', ['$scope', '$
301307
}
302308
else {
303309
alert("Loading select items failed(Key(field): " + form.key + "Options: '" + String(form.options) +
304-
"\nError: " + status);
310+
"\nError: " + status);
305311
}
306312

307313
});
@@ -321,7 +327,7 @@ angular.module('schemaForm').controller('dynamicSelectController', ['$scope', '$
321327
}
322328
else {
323329
alert("Loading select items failed (Key(field): " + form.key + " URL: '" + String(finalOptions.httpPost.url) +
324-
"' Parameter: " + String(finalOptions.httpPost.parameter) + "\nStatus: " + status);
330+
"' Parameter: " + String(finalOptions.httpPost.parameter) + "\nStatus: " + status);
325331
}
326332

327333
});
@@ -355,15 +361,14 @@ angular.module('schemaForm').controller('dynamicSelectController', ['$scope', '$
355361

356362
};
357363

358-
$scope.uiMultiSelectInitInternalModel = function(supplied_model)
359-
{
364+
$scope.uiMultiSelectInitInternalModel = function (supplied_model) {
360365

361366

362-
console.log("$scope.externalModel: Key: " +$scope.form.key.toString() + " Model: " + supplied_model.toString());
367+
console.log("$scope.externalModel: Key: " + $scope.form.key.toString() + " Model: " + supplied_model.toString());
363368
$scope.externalModel = supplied_model;
364369
$scope.internalModel = [];
365370
if ($scope.form.titleMap) {
366-
if (supplied_model !== undefined && angular.isArray(supplied_model)){
371+
if (supplied_model !== undefined && angular.isArray(supplied_model)) {
367372
supplied_model.forEach(function (value) {
368373
$scope.internalModel.push($scope.find_in_titleMap(value));
369374
}
@@ -381,14 +386,12 @@ angular.module('schemaForm').filter('selectFilter', [function ($filter) {
381386
// its string representation as well as we do not know its name. A typical value if strLocalModel is model['groups']
382387
// This is very ugly, though. TODO: Find out why the model is set to undefined after validation failure.
383388

384-
if (!angular.isDefined(inputArray) || !angular.isDefined(controller.form.options) ||
385-
!angular.isDefined(controller.form.options.filter) || controller.form.options.filter == '') {
389+
if (!angular.isDefined(inputArray) || !angular.isDefined(controller.form.options) || !angular.isDefined(controller.form.options.filter) || controller.form.options.filter == '') {
386390
return inputArray;
387391
}
388392

389393

390-
391-
console.log("----- In filtering for " + controller.form.key + "(" + controller.form.title +"), model value: " + JSON.stringify( localModel) + "----");
394+
console.log("----- In filtering for " + controller.form.key + "(" + controller.form.title + "), model value: " + JSON.stringify(localModel) + "----");
392395
console.log("Filter:" + controller.form.options.filter);
393396
if (!controller.filteringInitialized) {
394397
console.log("Initialize filter");
@@ -412,15 +415,15 @@ angular.module('schemaForm').filter('selectFilter', [function ($filter) {
412415
localModel.splice(localModel.indexOf(curr_item.value), 1);
413416
}
414417
else if (localModel == curr_item.value) {
415-
console.log("Setting model of type " + controller.localModelType + "to null.");
418+
console.log("Setting model of type " + controller.localModelType + "to null.");
416419
localModel = null;
417420
}
418421
}
419422
});
420423

421424
if (controller.localModelType == "[object Array]" && !localModel) {
422425
// An undefined local model seems to mess up bootstrap select's indicators
423-
console.log("Resetting model of type " + controller.localModelType + " to [].");
426+
console.log("Resetting model of type " + controller.localModelType + " to [].");
424427

425428
controller.$eval(strLocalModel + "=[]");
426429
}

0 commit comments

Comments
 (0)