// Generated by CoffeeScript 1.12.7
/**
* Edit the form to grant authorization
* @module
*/
'use strict';
app.directive('partyEditGrantForm', [
'$location', 'constantService', 'modelService', 'messageService', 'displayService', function($location, constants, models, messages, display) {
return {
restrict: 'E',
templateUrl: 'party/editGrant.html',
link: function($scope) {
var authSearchSelectFn, form, p;
form = $scope.partyEditGrantForm;
form.data = $scope.party.children.slice();
(function($) {
$.fn.goTo = function(yoffset) {
var scrolloffset;
if (yoffset) {
scrolloffset = yoffset;
} else {
scrolloffset = 0;
}
$('html, body').animate({
scrollTop: $(this).offset().top + scrolloffset + 'px'
}, 'fast');
return this;
};
})(jQuery);
authSearchSelectFn = function(found, searchForm) {
var exp;
if (searchForm) {
messages.clear(searchForm);
}
exp = new Date();
exp.setFullYear(exp.getFullYear() + 1);
form.data.push({
"new": true,
party: found,
site: 0,
member: 0,
expires: exp.getTime()
});
if (angular.element('#expiredaff').is(':visible')) {
angular.element('#expiredaff').goTo(-150);
} else {
angular.element('article.permission-auth.cf.peg.anchor.clearfix:last').goTo(450);
}
};
$scope.authSearchNotFoundFn = function(name, searchForm) {
return messages.add({
type: 'yellow',
body: constants.message('auth.grant.notfound'),
owner: searchForm
});
};
$scope.authDenySuccessFn = function(auth) {
return form.data.remove(auth);
};
form.saveAll = function() {
return $scope.$broadcast('authGrantSave');
};
$scope.authSearchSelectFn = function(p, searchForm) {
if (form.data.some(function(auth) {
return auth.party.id === p.id;
})) {
angular.element('article#auth-' + p.id).goTo(-150);
} else if ($scope.party.parents.some(function(a) {
return a.party.id === p.id;
})) {
messages.add({
type: 'red',
body: constants.message('auth.grant.parent'),
owner: searchForm
});
} else {
authSearchSelectFn(p, searchForm);
}
};
$scope.getClass = function(date) {
var today;
today = Date.now();
if (new Date(date) > today) {
return true;
} else {
return false;
}
};
$scope.$watch(function() {
angular.element('.affiliatediv').each(function() {
if ($(this).next().is('article')) {
$(this).show();
} else {
$(this).hide();
}
});
});
if ((p = $location.search().party) != null) {
$location.search('party', null);
models.Party.get(p).then($scope.authSearchSelectFn);
}
}
};
}
]);
//# sourceMappingURL=editGrant.js.map