-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathaccessRequestForm.js
More file actions
72 lines (66 loc) · 2.14 KB
/
accessRequestForm.js
File metadata and controls
72 lines (66 loc) · 2.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
let submitted_forms = 0
function handleButtonLoading(elem, status) {
if(status) {
elem.attr('disabled', true);
elem.html("");
let newSpan = $("#submitButtonLoading").clone(true, true);
newSpan.removeClass("collapse");
newSpan.appendTo(elem);
} else {
elem.attr('disabled', false);
elem.html("Submit request");
}
}
function submitRequest(event, elem, multi, access_tag, accesses="") {
event.preventDefault()
form = $(elem)
let actionUrl = form.attr('action');
let button = $(form.find("button#submitButton"));
handleButtonLoading(button, true);
$.ajax({
type: "POST",
url: actionUrl,
data: form.serialize(),
error: (xhr, statusText, data) => {
if(xhr.responseJSON) {
showNotification("failed", xhr.responseJSON["error"]["msg"], xhr.responseJSON["error"]["error_msg"]);
}
else {
showNotification("failed", "Failed to send the request", "Something went wrong");
}
handleButtonLoading(button, false);
}
}).done(function(data, statusText, xhr) {
let status = xhr.status;
if(status != 200) {
showNotification("failed", data["error"]["error_msg"], data["error"]["msg"]);
}
else {
if(multi) {
showNotification("success", data["status"]["title"], data["status"]["msg"]);
markedSubmitted(access_tag);
submitted_forms += 1;
if(submitted_forms == accesses) {
showRedirectModal("All Requests submitted");
}
}
else {
showRedirectModal("Request submitted");
}
}
handleButtonLoading(button, false);
})
}
function showRedirectModal(title, message="") {
$("#redirect_to_dashboard").show();
$("#modal-title").html(title);
$("#modal-message").html(message);
}
function markedSubmitted(access_tag) {
$(`#${access_tag}_dropdown`).prop("checked", false);
$(`#${access_tag}_dropdown`).attr("disabled", true);
$(`#${access_tag}_status`).removeClass("bg-gray-100").addClass("bg-emerald-100");
$(`#${access_tag}_status`).removeClass("text-gray-800").addClass("text-emerald-800");
$(`#${access_tag}_status`).html("Details submitted");
rotateArrowOnCheck(access_tag);
}