From 28f65de0c592c99604eb1ce42b6b12f5ef25760b Mon Sep 17 00:00:00 2001 From: sinavir Date: Mon, 6 Mar 2023 11:55:19 +0100 Subject: [PATCH] frontend (AJAX, hide button if no permission) --- hackens_orga/frontend/static/js/budget_list.js | 13 ++++++++++++- .../frontend/templates/frontend/base.html | 10 ++++++++++ .../templates/frontend/budget_list.html | 17 +++++++---------- 3 files changed, 29 insertions(+), 11 deletions(-) diff --git a/hackens_orga/frontend/static/js/budget_list.js b/hackens_orga/frontend/static/js/budget_list.js index 6f231f0..a120000 100644 --- a/hackens_orga/frontend/static/js/budget_list.js +++ b/hackens_orga/frontend/static/js/budget_list.js @@ -8,7 +8,9 @@ document.addEventListener('DOMContentLoaded', () => { // Get the target from the "data-target" attribute if ('lineid' in el.dataset) { const target = el.dataset.lineid; + const group = el.dataset.groupid; const tableLine = document.getElementById(`tableline-${target}`); + const budgetAmount = document.getElementById(`budget-amount-${group}`); if (confirm("Are you sure to delete this item ?")) { // Get csrf token const cookieValue = document.cookie @@ -16,6 +18,7 @@ document.addEventListener('DOMContentLoaded', () => { .find((row) => row.startsWith('csrftoken=')) ?.split('=')[1]; const url = `/api/budget/budgetline/${target}/`; + tableLine.classList.add("tr-disabled"); await fetch(url, { method: 'DELETE', headers: { @@ -24,8 +27,16 @@ document.addEventListener('DOMContentLoaded', () => { }).then((resp) => { if(resp.ok) { tableLine.remove(); - //TODO: Add a message (code a helper for that) for succes or error + const url = `/api/budget/budgetgroup/${group}`; + budgetAmount.innerHTML = "---"; + return fetch(url); + } else { + tableLine.classList.remove("tr-disabled"); } + }).then((resp) => + resp.json() + ).then((data) => { + budgetAmount.innerHTML = data.total; }).catch((e) => console.log(e)); } } diff --git a/hackens_orga/frontend/templates/frontend/base.html b/hackens_orga/frontend/templates/frontend/base.html index 41d760b..c50f4cb 100644 --- a/hackens_orga/frontend/templates/frontend/base.html +++ b/hackens_orga/frontend/templates/frontend/base.html @@ -42,6 +42,16 @@