// Generated by CoffeeScript 1.12.7
/**
* Edit notifications
* @module
*/
'use strict';
app.directive('partyEditNotifications', [
'constantService', 'routerService', 'messageService', function(constants, router, messages) {
return {
restrict: 'E',
templateUrl: 'party/editNotifications.html',
link: function($scope) {
var Delivery, Notice, delivery, getDelivery, n, options;
Notice = constants.notice;
Delivery = constants.delivery;
options = [Delivery.none, Delivery.site, Delivery.weekly, Delivery.daily, Delivery.async];
$scope.notifications = [
{
name: "Account changes",
subgroup: [
{
name: "Your email or password changed",
notice: [Notice.AccountChange],
options: [Delivery.async]
}
]
}, {
name: "Your authorization status",
subgroup: [
{
name: "You submitted an authorization request",
notice: [Notice.AuthorizeRequest],
options: [Delivery.site, Delivery.async]
}, {
name: "You were authorized",
notice: [Notice.AuthorizeGranted],
options: [Delivery.site, Delivery.weekly, Delivery.daily, Delivery.async]
}, {
name: "Your authorization is expiring",
notice: [Notice.AuthorizeExpiring, Notice.AuthorizeExpired],
options: [Delivery.site, Delivery.weekly, Delivery.daily]
}
]
}, {
name: "Your affiliates",
subgroup: [
{
name: "Someone requested authorization",
notice: [Notice.AuthorizeChildRequest],
options: [Delivery.async]
}, {
name: "You authorized someone",
notice: [Notice.AuthorizeChildGranted],
options: options
}, {
name: "Your affiliate's authorization is expiring",
notice: [Notice.AuthorizeChildExpiring, Notice.AuthorizeChildExpired],
options: [Delivery.none, Delivery.site, Delivery.weekly, Delivery.daily]
}
]
}, {
name: "Your volume activity",
subgroup: [
{
name: "An assistance request was submitted for your volume",
notice: [Notice.VolumeAssist],
options: options
}, {
name: "Someone created a volume on your behalf",
notice: [Notice.VolumeCreated],
options: options
}, {
name: "Someone changed the access permissions on your volume",
notice: [Notice.VolumeSharing, Notice.VolumeAccessOther, Notice.VolumeAccess],
options: options
}, {
name: "Someone marked data on your volume publicly releasable",
notice: [Notice.ReleaseSlot, Notice.ReleaseAsset, Notice.ReleaseExcerpt],
options: options
}, {
name: "Someone created a highlight on your volume",
notice: [Notice.ExcerptVolume],
options: options
}, {
name: "Someone commented on your volume or replied to your comment",
notice: [Notice.CommentVolume, Notice.CommentReply],
options: options
}, {
name: "Someone added a tag on your volume",
notice: [Notice.TagVolume],
options: options
}
]
}, {
name: "Sitewide activity",
subgroup: [
{
name: "A new volume was shared",
notice: [Notice.SharedVolume],
options: [Delivery.none, Delivery.site, Delivery.weekly, Delivery.daily]
}
]
}, {
name: "Newsletter subscription",
subgroup: [
{
name: "Subscribe to the newsletter",
notice: [Notice.Newsletter],
options: [Delivery.none, Delivery.async]
}
]
}
];
$scope.delivery = (function() {
var i, len, ref, results;
ref = constants.delivery;
results = [];
for (i = 0, len = ref.length; i < len; i++) {
n = ref[i];
results.push(constants.message('notice.delivery.' + n));
}
return results;
})();
delivery = void 0;
getDelivery = function(n) {
var d, i, len, ref, t;
d = void 0;
ref = n.notice;
for (i = 0, len = ref.length; i < len; i++) {
t = ref[i];
if (d === void 0) {
d = delivery[t];
} else if (d !== delivery[t]) {
d = null;
}
}
return n.delivery = d;
};
router.http(router.controllers.getNotify).then(function(res) {
var i, j, len, len1, nl, ref, ref1;
delivery = res.data;
ref = $scope.notifications;
for (i = 0, len = ref.length; i < len; i++) {
nl = ref[i];
ref1 = nl.subgroup;
for (j = 0, len1 = ref1.length; j < len1; j++) {
n = ref1[j];
getDelivery(n);
}
}
});
$scope.save = function(n) {
var d;
$scope.partyEditNotificationsForm.$setSubmitted();
d = n.delivery;
router.http(router.controllers.postNotify, {
notice: n.notice,
delivery: d
}).then(function() {
var i, len, ref, t;
ref = n.notice;
for (i = 0, len = ref.length; i < len; i++) {
t = ref[i];
delivery[t] = d;
}
getDelivery(n);
$scope.partyEditNotificationsForm.$setPristine();
}, function(res) {
$scope.partyEditNotificationsForm.$setUnsubmitted();
messages.addError({
type: 'red',
body: 'An error occured saving your notification preferences',
report: res
});
getDelivery(n);
});
};
}
};
}
]);
//# sourceMappingURL=editNotifications.js.map