46 lines
1.7 KiB
JavaScript
46 lines
1.7 KiB
JavaScript
;
|
|
var standardCancelButton = {
|
|
message: "Cancel",
|
|
onClick: function () { }
|
|
};
|
|
function DoHTTPRequest(url, method = "GET") {
|
|
var request = new XMLHttpRequest();
|
|
request.onreadystatechange = function () {
|
|
// console.log(this);
|
|
if (this.readyState == 4) {
|
|
if (this.status == 200) {
|
|
return { success: true, response: this.responseText };
|
|
}
|
|
else {
|
|
return { success: false, response: `HTTP status ${this.status}` };
|
|
}
|
|
}
|
|
};
|
|
request.open(method, url);
|
|
request.send();
|
|
return { success: false, response: "Unknown error" };
|
|
}
|
|
function dgel(id) {
|
|
return document.getElementById(id);
|
|
}
|
|
function MessageBox(title, message, buttons, data) {
|
|
dgel("msgbox-title").textContent = title;
|
|
dgel("msgbox-message").textContent = message;
|
|
dgel("msgbox-buttons").innerHTML = "";
|
|
buttons.forEach(button => {
|
|
var htmlButton = document.createElement("button");
|
|
htmlButton.className = "inverted";
|
|
htmlButton.textContent = button.message;
|
|
htmlButton.addEventListener("click", function () { dgel("msgbox-holder").style.display = "none"; button.onClick(data); });
|
|
dgel("msgbox-buttons").appendChild(htmlButton);
|
|
});
|
|
dgel("msgbox-holder").style.display = "flex";
|
|
}
|
|
function PromptForDeletion(id, filename) {
|
|
MessageBox("Delete document?", `Are you sure you want to delete ${filename}?`, [{ message: "Delete", onClick: DeleteDocument }, standardCancelButton], id);
|
|
}
|
|
function DeleteDocument(id) {
|
|
DoHTTPRequest(`/api/Document/${id}`, "DELETE");
|
|
window.location = window.location;
|
|
}
|
|
//# sourceMappingURL=script.js.map
|