Adds effective enrol/unerol POST request on related button click.
This commit is contained in:
parent
3ebb89c1c6
commit
555fa8fb7c
1 changed files with 30 additions and 5 deletions
|
@ -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;
|
||||
|
|
Loading…
Reference in a new issue