// Generated by CoffeeScript 1.12.7
/**
* Search a party to request authorization from
* @module
*/
'use strict';
app.directive('authSearchForm', [
'modelService', 'constantService', function(models, constants) {
return {
restrict: 'E',
templateUrl: 'party/authSearch.html',
link: function($scope, $element, $attrs) {
var form, notfound, party, select;
party = $scope.party || models.Login.user;
form = $scope.authSearchForm;
form.principal = $attrs.principal;
form.apply = form.principal !== 'child';
$scope.$watch(function() {
return form.principal;
}, function(principal) {
form.validator.client({
name: {
tips: constants.message('auth.search.' + (principal || 'placeholder') + '.help')
}
}, true);
form.placeholderText = $attrs.placeholderText || constants.message('auth.search.' + (form.principal || 'placeholder') + '.prompt');
});
select = function(found) {
return function() {
$scope.authSearchSelectFn(found, form);
form.$setPristine();
return '';
};
};
notfound = {
text: constants.message('auth.notfound'),
select: function() {
$scope.authSearchNotFoundFn(form.nameVal, form);
form.$setPristine();
return '';
}
};
form.search = function(val) {
return models.Party.search({
query: val,
institution: form.principal === 'principal' || (form.principal === 'affiliate' ? false : void 0)
}).then(function(data) {
var found, l;
form.validator.server({});
l = (function() {
var i, len, results;
results = [];
for (i = 0, len = data.length; i < len; i++) {
found = data[i];
if (found.id !== party.id) {
results.push({
text: found.name,
select: select(found)
});
}
}
return results;
})();
l.push(notfound);
return l;
}, function(res) {
form.validator.server(res);
});
};
form.validator.client({
name: {
tips: constants.message('auth.search.name.help')
}
}, true);
}
};
}
]);
//# sourceMappingURL=authSearch.js.map