From 0c1e1c6359b388890802b8538a8cb16a55b14f3e Mon Sep 17 00:00:00 2001 From: Preston Doman Date: Wed, 6 Mar 2019 21:10:51 -0800 Subject: [PATCH 1/5] Add finalize and submit for review buttons --- front/static/edit_report.html | 3 ++- front/static/js/viewHistory.js | 38 +++++++++++++++++++++++----------- 2 files changed, 28 insertions(+), 13 deletions(-) diff --git a/front/static/edit_report.html b/front/static/edit_report.html index b052a56..f192a08 100644 --- a/front/static/edit_report.html +++ b/front/static/edit_report.html @@ -86,7 +86,8 @@ diff --git a/front/static/js/viewHistory.js b/front/static/js/viewHistory.js index 97b4884..8b2619a 100644 --- a/front/static/js/viewHistory.js +++ b/front/static/js/viewHistory.js @@ -86,7 +86,7 @@ function updateSection(parsedData, saveButton) { saveButton.innerHTML = "Save"; saveButton.disabled = false; - + } // Wraps a Bootstrap form group around a field @@ -214,7 +214,7 @@ function createCollapsibleCard(sectionIdStr, sectionTitle, sectionCompleted, rul sectionState.classList.add("fas", "fa-exclamation-triangle"); } } - + // Create h2, button. Append button to h2, h2 to header, and header to card const h2 = document.createElement("h2"); h2.classList.add("mb-0"); @@ -284,7 +284,7 @@ function createCardFooter(ruleViolations) { violation.appendChild(ruleBreakText); violationMessage.appendChild(violation); } - + cardFooter.appendChild(violationMessage); return cardFooter; } @@ -295,12 +295,6 @@ 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"); @@ -317,6 +311,15 @@ function createReportForm(parsedData, type) { return; } + const reviewButton = document.querySelector(".review-report"); + if (reviewButton) { + reviewButton.setAttribute("data-rid", parsedData.report_pk); + } + const finalizeButton = document.querySelector(".finalize-report"); + if (finalizeButton) { + finalizeButton.setAttribute("data-rid", parsedData.report_pk); + } + while (modalBody.firstChild) { modalBody.removeChild(modalBody.firstChild); } @@ -529,10 +532,10 @@ 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")) { + } else if (event.target.classList.contains("review-report")) { event.preventDefault(); - //const title = document.querySelector("#editReportModalLabel").textContent; - const result = confirm("Are you sure you want to submit the report ?"); + console.log("review-report"); + const result = confirm("Are you sure you want to submit this report for review?"); if (result) { const url = getEndpointDomain() + "api/v1/report/" + event.target.dataset.rid; makeAjaxRequest("PUT", url, function(parsedData) { @@ -540,6 +543,17 @@ document.addEventListener("click", function(event) { location.reload(true); }); } + } else if (event.target.classList.contains("finalize-report")) { + event.preventDefault(); + console.log("finalize-report"); + const result = confirm("Are you sure you want to finalize this report? This means you will no longer be able to modify it."); + if (result) { + const url = getEndpointDomain() + "api/v1/report/" + event.target.dataset.rid + "/final"; + 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; From 84210d6dacf656b8ad3b52f9bbcbb3885c4c54e5 Mon Sep 17 00:00:00 2001 From: Preston Doman Date: Wed, 6 Mar 2019 23:13:09 -0800 Subject: [PATCH 2/5] Add button animations --- front/static/js/viewHistory.js | 28 ++++++++++++++++++++-------- front/static/new_report.html | 9 +++++---- 2 files changed, 25 insertions(+), 12 deletions(-) diff --git a/front/static/js/viewHistory.js b/front/static/js/viewHistory.js index 6752fb4..6ebac84 100644 --- a/front/static/js/viewHistory.js +++ b/front/static/js/viewHistory.js @@ -50,6 +50,16 @@ function makeAjaxRequest(method, url, callback, optional, payload) { xhr.send(payload); } +function animateButton(target, buttonText) { + let button = target; + button.disabled = true; + button.innerHTML = ""; + let span = document.createElement("span"); + span.classList.add("spinner-border", "spinner-border-sm"); + button.appendChild(span); + button.appendChild(document.createTextNode(buttonText)); +} + function updateSection(parsedData, saveButton) { const sectionIdStr = "#section-" + parsedData.id + "-"; const sectionState = document.querySelector(sectionIdStr + "state"); @@ -58,7 +68,6 @@ function updateSection(parsedData, saveButton) { // A completed section gets a header icon if (parsedData.completed) { const sectionAlert = collapseDiv.querySelector(".section-alert"); - console.log(sectionAlert); if (sectionAlert) { collapseDiv.firstChild.removeChild(sectionAlert); } @@ -527,12 +536,14 @@ document.addEventListener("click", function(event) { makeAjaxRequest("GET", url, displayReport); } else if (event.target.classList.contains("review-report")) { event.preventDefault(); - console.log("review-report"); const result = confirm("Are you sure you want to submit this report for review?"); if (result) { + animateButton(event.target, " Submitting..."); const url = getEndpointDomain() + "api/v1/report/" + event.target.dataset.rid; makeAjaxRequest("PUT", url, function(parsedData) { alert(parsedData.message); + event.target.disabled = false; + event.target.innerHTML = "Submit for Review"; location.reload(true); }); } @@ -541,9 +552,12 @@ document.addEventListener("click", function(event) { console.log("finalize-report"); const result = confirm("Are you sure you want to finalize this report? This means you will no longer be able to modify it."); if (result) { + animateButton(event.target, " Submitting..."); const url = getEndpointDomain() + "api/v1/report/" + event.target.dataset.rid + "/final"; makeAjaxRequest("PUT", url, function(parsedData) { alert(parsedData.message); + event.target.disabled = false; + event.target.innerHTML = "Finalize Report"; location.reload(true); }); } @@ -552,9 +566,12 @@ document.addEventListener("click", function(event) { const title = document.querySelector("#editReportModalLabel").textContent; const result = confirm("Are you sure you want to delete the report \"" + title + "\"?"); if (result) { + animateButton(event.target, " Deleting..."); const url = getEndpointDomain() + "api/v1/report/" + event.target.dataset.rid; makeAjaxRequest("DELETE", url, function(parsedData) { alert(parsedData.message); + event.target.disabled = false; + event.target.innerHTML = "Delete Report"; location.reload(true); }); } @@ -588,12 +605,7 @@ document.addEventListener("submit", function(event) { if (event.target.classList.contains("section-form")) { event.preventDefault(); 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...")); + animateButton(saveButton, " 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, updateSection, saveButton, formData); diff --git a/front/static/new_report.html b/front/static/new_report.html index cda82ca..60eec45 100644 --- a/front/static/new_report.html +++ b/front/static/new_report.html @@ -43,16 +43,16 @@
-

Create a new report

+

Create A New Report

- +
- +
@@ -81,7 +81,8 @@
From ec148d870dd62eb298a2adfb052cc0ab6d73f556 Mon Sep 17 00:00:00 2001 From: Preston Doman Date: Wed, 6 Mar 2019 23:26:55 -0800 Subject: [PATCH 3/5] Fix argument to animateButton --- front/static/js/viewHistory.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/front/static/js/viewHistory.js b/front/static/js/viewHistory.js index 6ebac84..264d77b 100644 --- a/front/static/js/viewHistory.js +++ b/front/static/js/viewHistory.js @@ -50,8 +50,7 @@ function makeAjaxRequest(method, url, callback, optional, payload) { xhr.send(payload); } -function animateButton(target, buttonText) { - let button = target; +function animateButton(button, buttonText) { button.disabled = true; button.innerHTML = ""; let span = document.createElement("span"); From 66bb614e74a8fedb77c290dcab0ca7cd6361475d Mon Sep 17 00:00:00 2001 From: Preston Doman Date: Thu, 7 Mar 2019 00:20:10 -0800 Subject: [PATCH 4/5] Change order of alert and button update --- front/static/js/viewHistory.js | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/front/static/js/viewHistory.js b/front/static/js/viewHistory.js index 264d77b..8f3bac5 100644 --- a/front/static/js/viewHistory.js +++ b/front/static/js/viewHistory.js @@ -540,9 +540,9 @@ document.addEventListener("click", function(event) { animateButton(event.target, " Submitting..."); const url = getEndpointDomain() + "api/v1/report/" + event.target.dataset.rid; makeAjaxRequest("PUT", url, function(parsedData) { - alert(parsedData.message); event.target.disabled = false; event.target.innerHTML = "Submit for Review"; + alert(parsedData.message); location.reload(true); }); } @@ -554,9 +554,9 @@ document.addEventListener("click", function(event) { animateButton(event.target, " Submitting..."); const url = getEndpointDomain() + "api/v1/report/" + event.target.dataset.rid + "/final"; makeAjaxRequest("PUT", url, function(parsedData) { - alert(parsedData.message); event.target.disabled = false; event.target.innerHTML = "Finalize Report"; + alert(parsedData.message); location.reload(true); }); } @@ -568,9 +568,9 @@ document.addEventListener("click", function(event) { animateButton(event.target, " Deleting..."); const url = getEndpointDomain() + "api/v1/report/" + event.target.dataset.rid; makeAjaxRequest("DELETE", url, function(parsedData) { - alert(parsedData.message); event.target.disabled = false; event.target.innerHTML = "Delete Report"; + alert(parsedData.message); location.reload(true); }); } @@ -578,6 +578,11 @@ document.addEventListener("click", function(event) { } }); +function successMessage(parsedData) { + alert(parsedData.message); + location.reload(true); +} + const newReportForm = document.querySelector(".new-report-form"); if (newReportForm) { newReportForm.addEventListener("submit", function(event) { From c7b7e8f1f5afdc736d68774d9e8b304d99ec2da1 Mon Sep 17 00:00:00 2001 From: Preston Doman Date: Thu, 7 Mar 2019 13:16:46 -0800 Subject: [PATCH 5/5] Fix stuff --- front/static/js/viewHistory.js | 5 ----- 1 file changed, 5 deletions(-) diff --git a/front/static/js/viewHistory.js b/front/static/js/viewHistory.js index 8f3bac5..b3f5d46 100644 --- a/front/static/js/viewHistory.js +++ b/front/static/js/viewHistory.js @@ -578,11 +578,6 @@ document.addEventListener("click", function(event) { } }); -function successMessage(parsedData) { - alert(parsedData.message); - location.reload(true); -} - const newReportForm = document.querySelector(".new-report-form"); if (newReportForm) { newReportForm.addEventListener("submit", function(event) {