Adds effective enrol/unerol POST request on related button click.

This commit is contained in:
Daru13 2018-11-22 22:34:09 +01:00
parent 3ebb89c1c6
commit 555fa8fb7c

View file

@ -787,12 +787,37 @@ class EventDetails {
// On click, switch the subscription state
// and update objects related to the perm count
let event = this.event;
buttonNode.on("click", () => {
// TODO: subscribe or unsubscribe
event.subscribedByUser = ! event.subscribedByUser;
let goal = event.subscribedByUser ? "unenrol" : "enrol";
let url = event.calendar.subscriptionURLFormat
.replace("999999", event.id);
$.ajax(url, {
method: "POST",
dataType: "json",
headers: {
"X-CSRFToken": event.calendar.csrfToken
},
data: {
"goal": goal
},
success: (jsonAnswer) => {
event.subscribedByUser = jsonAnswer.enrolled;
event.nbPerms = jsonAnswer.number;
this.updatePermManagementArea();
event.updatePermCounter();
event.updateNodeStyle();
},
error: (_, message) => {
alert(message);
}
});
});
return buttonNode;