commit
adc3b5863f
2 changed files with 32 additions and 11 deletions
|
@ -45,6 +45,9 @@
|
||||||
<h3>Your Report History</h3>
|
<h3>Your Report History</h3>
|
||||||
</div>
|
</div>
|
||||||
<div class="card-body">
|
<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">
|
<table class="table table-striped table-responsive-sm" style="visibility:hidden">
|
||||||
<thead>
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
|
|
|
@ -9,11 +9,13 @@ function getEndpointDomain() {
|
||||||
return "https://" + window.location.hostname + ":8444/";
|
return "https://" + window.location.hostname + ":8444/";
|
||||||
}
|
}
|
||||||
|
|
||||||
function alertCallback(parsedData) {
|
function saveSectionCallback(parsedData, saveButton) {
|
||||||
alert(JSON.stringify(parsedData));
|
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 token = localStorage.getItem("token");
|
||||||
const xhr = new XMLHttpRequest();
|
const xhr = new XMLHttpRequest();
|
||||||
|
|
||||||
|
@ -39,7 +41,7 @@ function makeAjaxRequest(method, url, callback, type, payload) {
|
||||||
console.log(method + " SUCCESS!");
|
console.log(method + " SUCCESS!");
|
||||||
console.log("Server response:\n" + this.response);
|
console.log("Server response:\n" + this.response);
|
||||||
let parsedData = JSON.parse(this.response);
|
let parsedData = JSON.parse(this.response);
|
||||||
type ? callback(parsedData, type) : callback(parsedData);
|
optional ? callback(parsedData, optional) : callback(parsedData);
|
||||||
} else {
|
} else {
|
||||||
console.error(method + " FAILURE!");
|
console.error(method + " FAILURE!");
|
||||||
console.error("Server status: " + this.status);
|
console.error("Server status: " + this.status);
|
||||||
|
@ -290,14 +292,17 @@ function createReportForm(parsedData, type) {
|
||||||
|
|
||||||
function displayListOfReports(parsedData) {
|
function displayListOfReports(parsedData) {
|
||||||
const reports = parsedData.reports;
|
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) {
|
if (reports.length === 0) {
|
||||||
const cardBody = document.querySelector(".card-body");
|
cardBody.removeChild(table);
|
||||||
const p = document.createElement("p");
|
const h5 = document.createElement("h5");
|
||||||
p.innerHTML = "No reports found.";
|
h5.innerHTML = "No reports found.";
|
||||||
cardBody.appendChild(p);
|
h5.classList.add("text-center");
|
||||||
|
cardBody.appendChild(h5);
|
||||||
} else {
|
} else {
|
||||||
const table = document.querySelector("table");
|
|
||||||
const tbody = document.querySelector("tbody");
|
const tbody = document.querySelector("tbody");
|
||||||
|
|
||||||
// Insert data into the table row
|
// Insert data into the table row
|
||||||
|
@ -463,9 +468,22 @@ document.addEventListener("input", function(event) {
|
||||||
document.addEventListener("submit", function(event) {
|
document.addEventListener("submit", function(event) {
|
||||||
if (event.target.classList.contains("section-form")) {
|
if (event.target.classList.contains("section-form")) {
|
||||||
event.preventDefault();
|
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 formData = new FormData(event.target);
|
||||||
const url = getEndpointDomain() + "api/v1/report/" + event.target.dataset.rid + "/section/" + event.target.dataset.sid;
|
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