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">
<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-primary">Submit Report</button>
<button type="button" class="btn btn-primary submit-report-button">Submit Report</button>
</div>
</div>
</div>

View file

@ -225,6 +225,12 @@ function createReportForm(parsedData, type) {
const accordion = document.createElement("div");
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) {
modalBody = document.querySelector("#editReportModalBody");
modalLabel = document.querySelector("#editReportModalLabel");
@ -427,6 +433,17 @@ document.addEventListener("click", function(event) {
console.log("View button clicked");
const url = getEndpointDomain() + "api/v1/report/" + event.target.dataset.rid;
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")) {
event.preventDefault();
const title = document.querySelector("#editReportModalLabel").textContent;

View file

@ -76,7 +76,7 @@
</div>
<div class="modal-footer">
<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>