Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: adds spinners on loading for buttons #229

Open
wants to merge 3 commits into
base: ui-improvements
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions static/js/accessRequestForm.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,24 @@
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,
Expand All @@ -15,6 +30,7 @@ function submitRequest(event, elem, multi, access_tag, accesses="") {
else {
showNotification("failed", "Failed to send the request", "Something went wrong");
}
handleButtonLoading(button, false);
}
}).done(function(data, statusText, xhr) {
let status = xhr.status;
Expand All @@ -36,6 +52,7 @@ function submitRequest(event, elem, multi, access_tag, accesses="") {
showRedirectModal("Request submitted");
}
}
handleButtonLoading(button, false);
})
}

Expand Down
17 changes: 17 additions & 0 deletions static/js/addUserToGroup.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,10 +113,25 @@ const handleUserSelection = (elem) => {
updateSelectedUser();
};

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) {
event.preventDefault();
form = $(elem);
let actionUrl = form.attr('action');
let button = $(form.find("button#submitButton"));
handleButtonLoading(button, true);
$.ajax({
type: "POST",
url: actionUrl,
Expand All @@ -128,6 +143,7 @@ function submitRequest(event, elem) {
else {
showNotification("failed", "Failed to send the request", "Something went wrong");
}
handleButtonLoading(button, false);
}
}).done(function(data, statusText, xhr) {
let status = xhr.status;
Expand All @@ -137,6 +153,7 @@ function submitRequest(event, elem) {
else {
showRedirectModal("Request submitted");
}
handleButtonLoading(button, false);
})
};

Expand Down
19 changes: 18 additions & 1 deletion static/js/createNewGroup.js
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,19 @@ function showRedirectModal(title, message="") {
$("#modal-message").html(message);
}

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() {
const members = $('#member-selection-table').children('tr');
const emails = [];
Expand All @@ -219,6 +232,8 @@ function submitRequest() {
return;
}
else {
let button = $('#submitNewGroup');
handleButtonLoading(button, true);
$.ajax({
url: urlBuilder,
type: "POST",
Expand All @@ -231,7 +246,8 @@ function submitRequest() {
"selectAllUsers": selectAllUsers,
},
success: function (result) {
showRedirectModal("Request Submitted", result.status.msg)
showRedirectModal("Request Submitted", result.status.msg);
handleButtonLoading(button, false);
},
error: function (XMLHttpRequest, textStatus, errorThrown) {
if(XMLHttpRequest.responseJSON) {
Expand All @@ -240,6 +256,7 @@ function submitRequest() {
} else {
showNotification("failed", "Something when wrong while creating the group, contact admin.", "Internal Error")
}
handleButtonLoading(button, false);
}
});
}
Expand Down
34 changes: 31 additions & 3 deletions static/js/failureActions.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,31 @@
function sendAPICall(requestId, url, messageId, desc) {
url =`${url}?requestId=${requestId}`
function handleButtonLoading(elem, status) {
let parentElem = $(elem.parentElement);
let text = $(elem).html();
let button = $(elem);
if(status) {
parentElem.find("button#resolveButton").attr('disabled', true);
parentElem.find("button#declineButton").attr('disabled', true);
parentElem.find("button#actionButton").attr('disabled', true);
button.html("");
let newSpan;
if (text == "Resolve") {
newSpan = $("#resolveButtonLoading").clone(true, true);
} else {
newSpan = $("#actionButtonLoading").clone(true, true);
}
newSpan.removeClass("collapse");
newSpan.appendTo(button);
} else {
parentElem.find("button#resolveButton").attr('disabled', false);
parentElem.find("button#declineButton").attr('disabled', false);
parentElem.find("button#actionButton").attr('disabled', false);
button.html(text);
}
}

function sendAPICall(elem, requestId, url, messageId, desc) {
url =`${url}?requestId=${requestId}`;
handleButtonLoading(elem, true);
$.ajax({
url: url,
error: (xhr, statusText, data) => {
Expand All @@ -9,10 +35,12 @@ function sendAPICall(requestId, url, messageId, desc) {
else {
showNotification("failed", "Failed to send the request", "Something went wrong");
}
handleButtonLoading(elem, false);
}
}).done((data) => {
showNotification("success", data["status_list"][0]["title"], data["status_list"][0]["msg"]);
updateStatus(desc, messageId, requestId)
updateStatus(desc, messageId, requestId);
handleButtonLoading(elem, false);
})
}

Expand Down
17 changes: 17 additions & 0 deletions static/js/groupAccessRequestForm.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,24 @@
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,
Expand All @@ -15,6 +30,7 @@ function submitRequest(event, elem, multi, access_tag, accesses="") {
else {
showNotification("failed", "Failed to send the request", "Something went wrong");
}
handleButtonLoading(button, false);
}
}).done(function(data, statusText, xhr) {
let status = xhr.status;
Expand All @@ -36,6 +52,7 @@ function submitRequest(event, elem, multi, access_tag, accesses="") {
showRedirectModal("Request submitted");
}
}
handleButtonLoading(button, false);
})
}

Expand Down
36 changes: 30 additions & 6 deletions static/js/pendingRequests.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
function showDeclineModal(request_id, action, messageId) {
$('#decline_modal').show();
$("#declineHeading").html("<p class='text-lg leading-6 font-medium'>"+request_id+"<p/>")
$('#decline_modal').find("form").attr("onsubmit", `clickDeclineFinalButton('${request_id}', '${action}', '${messageId}');return false`)
$('#decline_modal').find("form").attr("onsubmit", `clickDeclineFinalButton(this, '${request_id}', '${action}', '${messageId}');return false`)
}

function closeDeclineModal() {
Expand All @@ -10,20 +10,24 @@ function closeDeclineModal() {
$('#decline_modal').hide();
}

const clickDeclineFinalButton = (requestId, action, messageId) => {
const clickDeclineFinalButton = (elem, requestId, action, messageId) => {
closeDeclineModal();
const declineReason = $("#declineReasonText").val();
const urlBuilder = `/decline/${action}/${requestId}`
const urlBuilder = `/decline/${action}/${requestId}`;
let button = $(elem);
handleButtonLoading(button, true);
$.ajax({
url: urlBuilder,
data: {"reason": declineReason},
error: function (XMLHttpRequest, textStatus, errorThrown) {
if(XMLHttpRequest.responseJSON) {
showNotification("failed", XMLHttpRequest.responseJSON["response"][requestId]["error"])
showNotification("failed", XMLHttpRequest.responseJSON["response"][requestId]["error"]);
}
handleButtonLoading(button, true, "Decline");
}
}).done(function (data) {
updateStatus(false, messageId, requestId)
updateStatus(false, messageId, requestId);
handleButtonLoading(button, true, "Decline");
})
}

Expand All @@ -43,6 +47,19 @@ function setDeclineReason(reason) {
$("#declineReasonText").val(reason);
}

function handleButtonLoading(elem, status, text=null) {
if(status) {
elem.attr('disabled', true);
elem.html("");
let svgElem = $("#buttonLoading").clone(true, true);
svgElem.removeClass("collapse");
svgElem.appendTo(elem);
} else {
elem.attr('disabled', false);
elem.html(text);
}
}

function updateStatus(type, id, requestId) {
const newMessageBox = $("#message-box").clone(true, true);
const item = $(`#${id}`);
Expand All @@ -62,16 +79,23 @@ function updateStatus(type, id, requestId) {
$(`#${id}-actions`).hide();
}

function approveAccess(requestId, action, messageId) {
function approveAccess(elem, requestId, action, messageId) {
const urlBuilder = `/accept_bulk/${action}?requestId=${encodeURIComponent(requestId)}`
let button = $(elem);
handleButtonLoading(button, true);
$(elem.parentElement).find("button#declineButton").attr('disabled', true);
$.ajax({
url: urlBuilder,
error: function (XMLHttpRequest, textStatus, errorThrown) {
if(XMLHttpRequest.responseJSON) {
showNotification("failed", XMLHttpRequest.responseJSON["response"][requestId]["error"])
}
handleButtonLoading(button, false, "Accept");
$(elem.parentElement).find("button#declineButton").attr('disabled', false);
}
}).done(() => {
updateStatus(true, messageId, requestId);
handleButtonLoading(button, false, "Accept");
$(elem.parentElement).find("button#declineButton").attr('disabled', false);
})
}
14 changes: 12 additions & 2 deletions templates/EnigmaOps/accessRequestForm.html
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,9 @@ <h1 class="text-xl font-semibold text-gray-900">Module details</h1>
</div>
<input type="text" class="hidden" name="access_tag" value="{{ each_access.accessTag }}">
</div>
<button type="submit" class=" mx-1 my-5 rounded-md border border-transparent bg-blue-500 px-4 py-2 text-sm font-medium text-blue-200 shadow-sm hover:bg-blue-700 focus:outline-none focus:ring-2 focus:ring-blue-600 focus:ring-offset-2">Submit request</button>
<button type="submit" id="submitButton" class="w-32 h-9 mx-1 my-5 rounded-md border border-transparent bg-blue-600 text-sm font-medium text-white shadow-sm hover:bg-blue-700 focus:outline-none focus:ring-2 focus:ring-blue-600 focus:ring-offset-2">
Submit request
</button>
</form>
</div>
</div>
Expand Down Expand Up @@ -119,10 +121,18 @@ <h1 class="text-xl font-semibold text-gray-900">{{ each_access.formDesc }} Modul
</div>
<input type="text" class="hidden" name="access_tag" value="{{ each_access.accessTag }}">
</div>
<button type="submit" class=" mx-1 my-5 rounded-md border border-transparent bg-blue-500 px-4 py-2 text-sm font-medium text-blue-200 shadow-sm hover:bg-blue-700 focus:outline-none focus:ring-2 focus:ring-blue-600 focus:ring-offset-2">Submit request</button>
<button type="submit" id="submitButton" class="w-32 h-9 mx-1 my-5 rounded-md border border-transparent bg-blue-600 text-sm font-medium text-white shadow-sm hover:bg-blue-700 focus:outline-none focus:ring-2 focus:ring-blue-600 focus:ring-offset-2 items-center">
Submit request
</button>
</form>
{% endfor %}
{% endif %}
<svg id="submitButtonLoading" class="collapse inline w-5 h-5 text-white animate-spin" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24">
<circle class="opacity-25" cx="12" cy="12" r="10" stroke="currentColor" stroke-width="4"></circle>
<path class="opacity-75" fill="currentColor"
d="M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z">
</path>
</svg>
</div>
<div id="redirect_to_dashboard" class="hidden">
{% include "EnigmaOps/shared/redirect_to_dashboard.html" %}
Expand Down
12 changes: 10 additions & 2 deletions templates/EnigmaOps/addUserToGroupForm.html
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ <h1 class="text-lg leading-7 font-medium text-gray-900">All group members</h1>
</table>
</div>
<div class="px-4 sm:px-6 lg:px-8 h-1/6 w-full">
<form action="{% url 'addUserToGroup' groupName %}" onsubmit="submitRequest(event, this)" method="post">
<form action="{% url 'addUserToGroup' groupName %}" onsubmit="submitRequest(event, this)" method="post">
{% csrf_token %}
<input type="text" class="hidden" name="groupName" value="{{ groupName }}">
<input type="hidden" id="selected-users" value="" name="selectedUserList", required>
Expand All @@ -175,14 +175,22 @@ <h1 class="text-lg leading-7 font-medium text-gray-900">All group members</h1>
<input type="text" name="memberReason" id="reason" class="block w-5/6 rounded-md border-0 py-1.5 text-gray-900 shadow-sm ring-1 ring-inset ring-gray-300 placeholder:text-gray-400 focus:ring-2 focus:ring-inset focus:ring-indigo-600 sm:text-sm sm:leading-6" placeholder="Please mention the reason for add new members to this group in detail" required>
</div>
</div>
<button type="submit" class="my-6 rounded-md border border-transparent bg-blue-600 px-4 py-2 text-sm font-medium text-white shadow-sm hover:bg-blue-600 focus:outline-none focus:ring-2 focus:ring-blue-600 focus:ring-offset-2">Submit request</button>
<button type="submit" id="submitButton" class="items-center w-32 h-9 my-6 rounded-md border border-transparent bg-blue-600 text-sm font-medium text-white shadow-sm hover:bg-blue-600 focus:outline-none focus:ring-2 focus:ring-blue-600 focus:ring-offset-2">Submit request</button>
</form>
</div>

<div id="redirect_to_dashboard" class="hidden">
{% include "EnigmaOps/shared/redirect_to_dashboard.html" %}
</div>

<svg id="submitButtonLoading" class="collapse inline w-5 h-5 text-white animate-spin" xmlns="http://www.w3.org/2000/svg" fill="none"
viewBox="0 0 24 24">
<circle class="opacity-25" cx="12" cy="12" r="10" stroke="currentColor" stroke-width="4"></circle>
<path class="opacity-75" fill="currentColor"
d="M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z">
</path>
</svg>

{% include "EnigmaOps/shared/notificationTemplate.html" %}

{% endblock %}
11 changes: 9 additions & 2 deletions templates/EnigmaOps/createNewGroup.html
Original file line number Diff line number Diff line change
Expand Up @@ -215,11 +215,10 @@ <h1 class="mt-1.5 text-sm text-center text-gray-700">Please select members from

<div class = "mb-5">
<button type="submit" id="submitNewGroup"
class="flex items-center place-content-center rounded-md border border-transparent w-40 bg-blue-500 mt-8 px-4 py-2 text-base font-medium text-white shadow-sm hover:bg-blue-700 focus:outline-none focus:ring-2 focus:ring-blue-500 focus:ring-offset-2"
class="flex items-center w-32 h-9 place-content-center rounded-md border border-transparent bg-blue-600 mt-8 text-sm leading-5 font-medium text-white shadow-sm hover:bg-blue-700 focus:outline-none focus:ring-2 focus:ring-blue-600 focus:ring-offset-2"
onclick="submitRequest()">
Submit request
</button>

</div>
</div>

Expand All @@ -244,6 +243,14 @@ <h1 class="mt-1.5 text-sm text-center text-gray-700">Please select members from
{% include "EnigmaOps/shared/redirect_to_dashboard.html" %}
</div>

<svg id="submitButtonLoading" class="collapse inline w-5 h-5 text-white animate-spin" xmlns="http://www.w3.org/2000/svg" fill="none"
viewBox="0 0 24 24">
<circle class="opacity-25" cx="12" cy="12" r="10" stroke="currentColor" stroke-width="4"></circle>
<path class="opacity-75" fill="currentColor"
d="M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z">
</path>
</svg>

{% include "EnigmaOps/shared/notificationTemplate.html" %}

{% endblock %}
Loading