// Generated by CoffeeScript 1.12.7
/**
* Edit the form to request authorization
* @module
*/
'use strict';
app.directive('partyEditApplyForm', [
'$location', 'constantService', 'modelService', 'messageService', 'displayService', function($location, constants, models, messages, display) {
return {
restrict: 'E',
templateUrl: 'party/editApply.html',
link: function($scope) {
var authSearchSelectFn, form, p;
form = $scope.partyEditApplyForm;
form.data = $scope.party.parents.slice();
authSearchSelectFn = function(found) {
form.data.push({
"new": true,
party: found
});
display.scrollTo('fieldset article.permission-auth.pef:last');
};
$scope.authSearchNotFoundFn = function(query) {
form.data.push({
"new": true,
query: query
});
display.scrollTo('fieldset article.permission-auth.pef:last');
};
$scope.authApplySuccessFn = function(auth) {
messages.add({
body: constants.message('auth.apply.save.success'),
type: 'green',
owner: form
});
if (!auth.party) {
form.data.remove(auth);
}
};
$scope.authApplyCancelFn = function(auth) {
messages.add({
body: constants.message('auth.apply.remove.success'),
type: 'green',
owner: form
});
form.data.remove(auth);
};
$scope.authSearchSelectFn = function(p) {
if (form.data.some(function(auth) {
return auth.party.id === p.id;
})) {
display.scrollTo("#auth-" + p.id);
} else if ($scope.party.children.some(function(a) {
return a.party.id === p.id;
})) {
messages.add({
type: 'red',
body: constants.message('auth.apply.child')
});
} else {
authSearchSelectFn(p);
}
};
if ((p = $location.search().party) != null) {
$location.search('party', null);
models.Party.get(p).then($scope.authSearchSelectFn);
}
}
};
}
]);
//# sourceMappingURL=editApply.js.map