Update the submit report button

This commit is contained in:
sliang17 2019-02-18 20:14:48 -08:00
parent adc3b5863f
commit 440f54db85
3 changed files with 21 additions and 4 deletions

View file

@ -86,7 +86,7 @@
<div class="modal-footer"> <div class="modal-footer">
<button type="button" class="btn btn-danger delete-report">Delete Report</button> <button type="button" class="btn btn-danger delete-report">Delete Report</button>
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button> <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
<button type="button" class="btn btn-primary">Submit Report</button> <button type="button" class="btn btn-primary submit-report-button">Submit Report</button>
</div> </div>
</div> </div>
</div> </div>

View file

@ -225,6 +225,12 @@ function createReportForm(parsedData, type) {
const accordion = document.createElement("div"); const accordion = document.createElement("div");
accordion.classList.add("accordion"); accordion.classList.add("accordion");
//submit button
const submitButton = document.querySelector(".submit-report-button");
if (submitButton) {
submitButton.setAttribute("data-rid", parsedData.report_pk);
}
if (type === reportType.EDIT) { if (type === reportType.EDIT) {
modalBody = document.querySelector("#editReportModalBody"); modalBody = document.querySelector("#editReportModalBody");
modalLabel = document.querySelector("#editReportModalLabel"); modalLabel = document.querySelector("#editReportModalLabel");
@ -295,7 +301,7 @@ function displayListOfReports(parsedData) {
const cardBody = document.querySelector(".card-body"); const cardBody = document.querySelector(".card-body");
const table = document.querySelector("table"); const table = document.querySelector("table");
cardBody.removeChild(cardBody.firstElementChild); // remove loading spinner cardBody.removeChild(cardBody.firstElementChild); // remove loading spinner
if (reports.length === 0) { if (reports.length === 0) {
cardBody.removeChild(table); cardBody.removeChild(table);
const h5 = document.createElement("h5"); const h5 = document.createElement("h5");
@ -427,6 +433,17 @@ document.addEventListener("click", function(event) {
console.log("View button clicked"); console.log("View button clicked");
const url = getEndpointDomain() + "api/v1/report/" + event.target.dataset.rid; const url = getEndpointDomain() + "api/v1/report/" + event.target.dataset.rid;
makeAjaxRequest("GET", url, displayReport); makeAjaxRequest("GET", url, displayReport);
} else if (event.target.classList.contains("submit-report-button")) {
event.preventDefault();
//const title = document.querySelector("#editReportModalLabel").textContent;
const result = confirm("Are you sure you want to submit the report ?");
if (result) {
const url = getEndpointDomain() + "api/v1/report/" + event.target.dataset.rid;
makeAjaxRequest("PUT", url, function(parsedData) {
alert(parsedData.message);
location.reload(true);
});
}
} else if (event.target.classList.contains("delete-report")) { } else if (event.target.classList.contains("delete-report")) {
event.preventDefault(); event.preventDefault();
const title = document.querySelector("#editReportModalLabel").textContent; const title = document.querySelector("#editReportModalLabel").textContent;
@ -473,7 +490,7 @@ document.addEventListener("submit", function(event) {
saveButton.innerHTML = ""; saveButton.innerHTML = "";
let span = document.createElement("span"); let span = document.createElement("span");
span.classList.add("spinner-border", "spinner-border-sm"); span.classList.add("spinner-border", "spinner-border-sm");
saveButton.appendChild(span); saveButton.appendChild(span);
saveButton.appendChild(document.createTextNode(" Saving...")); 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;

View file

@ -76,7 +76,7 @@
</div> </div>
<div class="modal-footer"> <div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button> <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
<button type="button" class="btn btn-primary">Submit Report</button> <button type="button" class="btn btn-primary submit-report-button" >Submit Report</button>
</div> </div>
</div> </div>
</div> </div>