2018-07-06 07:18:51 +02:00
|
|
|
class ConfirmHandler {
|
2018-08-25 21:21:54 +02:00
|
|
|
executeRequest(url, redirectURL) {
|
2018-07-06 07:18:51 +02:00
|
|
|
let request = new RequestBuilder(url);
|
2018-08-25 21:21:54 +02:00
|
|
|
|
|
|
|
request.withCallback(() => {
|
|
|
|
if (redirectURL) {
|
|
|
|
window.location.href = redirectURL;
|
|
|
|
} else {
|
|
|
|
window.location.reload();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2018-07-06 07:18:51 +02:00
|
|
|
request.execute();
|
|
|
|
}
|
|
|
|
|
|
|
|
handle(event) {
|
|
|
|
let questionElement = document.createElement("span");
|
|
|
|
let linkElement = event.target;
|
|
|
|
let containerElement = linkElement.parentNode;
|
|
|
|
linkElement.style.display = "none";
|
|
|
|
|
|
|
|
let yesElement = document.createElement("a");
|
|
|
|
yesElement.href = "#";
|
|
|
|
yesElement.appendChild(document.createTextNode(linkElement.dataset.labelYes));
|
|
|
|
yesElement.onclick = (event) => {
|
|
|
|
event.preventDefault();
|
|
|
|
|
|
|
|
let loadingElement = document.createElement("span");
|
|
|
|
loadingElement.className = "loading";
|
|
|
|
loadingElement.appendChild(document.createTextNode(linkElement.dataset.labelLoading));
|
|
|
|
|
|
|
|
questionElement.remove();
|
|
|
|
containerElement.appendChild(loadingElement);
|
|
|
|
|
2018-08-25 21:21:54 +02:00
|
|
|
this.executeRequest(linkElement.dataset.url, linkElement.dataset.redirectUrl);
|
2018-07-06 07:18:51 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
let noElement = document.createElement("a");
|
|
|
|
noElement.href = "#";
|
|
|
|
noElement.appendChild(document.createTextNode(linkElement.dataset.labelNo));
|
|
|
|
noElement.onclick = (event) => {
|
|
|
|
event.preventDefault();
|
|
|
|
linkElement.style.display = "inline";
|
|
|
|
questionElement.remove();
|
|
|
|
};
|
|
|
|
|
|
|
|
questionElement.className = "confirm";
|
|
|
|
questionElement.appendChild(document.createTextNode(linkElement.dataset.labelQuestion + " "));
|
|
|
|
questionElement.appendChild(yesElement);
|
|
|
|
questionElement.appendChild(document.createTextNode(", "));
|
|
|
|
questionElement.appendChild(noElement);
|
|
|
|
|
|
|
|
containerElement.appendChild(questionElement);
|
|
|
|
}
|
|
|
|
}
|