commit
adc3b5863f
2 changed files with 32 additions and 11 deletions
|
@ -45,6 +45,9 @@
|
|||
<h3>Your Report History</h3>
|
||||
</div>
|
||||
<div class="card-body">
|
||||
<div class="text-center">
|
||||
<i class="fas fa-spinner fa-3x fa-spin"></i>
|
||||
</div>
|
||||
<table class="table table-striped table-responsive-sm" style="visibility:hidden">
|
||||
<thead>
|
||||
<tr>
|
||||
|
|
|
@ -9,11 +9,13 @@ function getEndpointDomain() {
|
|||
return "https://" + window.location.hostname + ":8444/";
|
||||
}
|
||||
|
||||
function alertCallback(parsedData) {
|
||||
function saveSectionCallback(parsedData, saveButton) {
|
||||
alert(JSON.stringify(parsedData));
|
||||
saveButton.innerHTML = "Save";
|
||||
saveButton.disabled = false;
|
||||
}
|
||||
|
||||
function makeAjaxRequest(method, url, callback, type, payload) {
|
||||
function makeAjaxRequest(method, url, callback, optional, payload) {
|
||||
const token = localStorage.getItem("token");
|
||||
const xhr = new XMLHttpRequest();
|
||||
|
||||
|
@ -39,7 +41,7 @@ function makeAjaxRequest(method, url, callback, type, payload) {
|
|||
console.log(method + " SUCCESS!");
|
||||
console.log("Server response:\n" + this.response);
|
||||
let parsedData = JSON.parse(this.response);
|
||||
type ? callback(parsedData, type) : callback(parsedData);
|
||||
optional ? callback(parsedData, optional) : callback(parsedData);
|
||||
} else {
|
||||
console.error(method + " FAILURE!");
|
||||
console.error("Server status: " + this.status);
|
||||
|
@ -290,14 +292,17 @@ function createReportForm(parsedData, type) {
|
|||
|
||||
function displayListOfReports(parsedData) {
|
||||
const reports = parsedData.reports;
|
||||
const cardBody = document.querySelector(".card-body");
|
||||
const table = document.querySelector("table");
|
||||
cardBody.removeChild(cardBody.firstElementChild); // remove loading spinner
|
||||
|
||||
if (reports.length === 0) {
|
||||
const cardBody = document.querySelector(".card-body");
|
||||
const p = document.createElement("p");
|
||||
p.innerHTML = "No reports found.";
|
||||
cardBody.appendChild(p);
|
||||
cardBody.removeChild(table);
|
||||
const h5 = document.createElement("h5");
|
||||
h5.innerHTML = "No reports found.";
|
||||
h5.classList.add("text-center");
|
||||
cardBody.appendChild(h5);
|
||||
} else {
|
||||
const table = document.querySelector("table");
|
||||
const tbody = document.querySelector("tbody");
|
||||
|
||||
// Insert data into the table row
|
||||
|
@ -463,9 +468,22 @@ document.addEventListener("input", function(event) {
|
|||
document.addEventListener("submit", function(event) {
|
||||
if (event.target.classList.contains("section-form")) {
|
||||
event.preventDefault();
|
||||
console.log(event.target);
|
||||
let saveButton = event.target.lastElementChild;
|
||||
saveButton.disabled = true;
|
||||
saveButton.innerHTML = "";
|
||||
let span = document.createElement("span");
|
||||
span.classList.add("spinner-border", "spinner-border-sm");
|
||||
saveButton.appendChild(span);
|
||||
saveButton.appendChild(document.createTextNode(" Saving..."));
|
||||
const formData = new FormData(event.target);
|
||||
const url = getEndpointDomain() + "api/v1/report/" + event.target.dataset.rid + "/section/" + event.target.dataset.sid;
|
||||
makeAjaxRequest("PUT", url, alertCallback, null, formData);
|
||||
makeAjaxRequest("PUT", url, saveSectionCallback, saveButton, formData);
|
||||
}
|
||||
});
|
||||
|
||||
// Jquery is required to handle this modal event
|
||||
$(document).ready(function(){
|
||||
$("#newReportModal").on('hidden.bs.modal', function() {
|
||||
location.reload(true);
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Reference in a new issue