From d998a402feca4d609953aa9dd5e58b70ee21a33a Mon Sep 17 00:00:00 2001
From: BonfaceKilz
Date: Thu, 12 May 2022 11:27:08 +0300
Subject: Make a POST request on data edit
* wqflask/wqflask/metadata_edits.py: When editing
a case-attribute, make a post request to the
relevant end-point.
---
wqflask/wqflask/templates/case_attributes.html | 42 ++++++++++++++++++++++++--
1 file changed, 39 insertions(+), 3 deletions(-)
diff --git a/wqflask/wqflask/templates/case_attributes.html b/wqflask/wqflask/templates/case_attributes.html
index 48efd8c8..7b6af57d 100644
--- a/wqflask/wqflask/templates/case_attributes.html
+++ b/wqflask/wqflask/templates/case_attributes.html
@@ -102,9 +102,9 @@
{% for id_, name, description in case_attributes %}
-
- {{ name }} |
- {{description}} |
+
+ {{ name }} |
+ {{description}} |
@@ -158,6 +158,42 @@
$(this).parents("tr").find(".add, .edit").toggle();
$(".add-new").removeAttr("disabled");
}
+
+ let nameNode = $(this).parents("tr").find(".name");
+ let descNode = $(this).parents("tr").find(".description");
+
+ let name = nameNode.html();
+ let desc = descNode.html();
+
+ let originalName = nameNode.data("original-value");
+ let originalDesc = descNode.data("original-value");
+ let diff = {};
+ if (name !== originalName) {
+ diff["Modifications"] = {
+ name: {
+ Original: originalName,
+ Current: name,
+ }};
+ }
+ if (desc !== originalDesc) {
+ let desc_ = {
+ Original: originalDesc,
+ Current: desc,
+ }
+ if (Object.keys(diff).length == 0) {
+ diff["Modifications"] = {
+ description: desc_
+ }
+ }
+ else {
+ diff["Modifications"].name = desc_;
+ }
+ }
+ if (!Object.keys(diff).length == 0) {
+ diff["id"] = $(this).parents("tr").data("id");
+ }
+ $.post('{{ url_for("metadata_edit.update_case_attributes") }}',
+ JSON.stringify(diff));
});
// Edit row on edit button click
$(document).on("click", ".edit", function(){
--
cgit v1.2.3
|