From b5494aadd60250fc7bdb4e474bc06cc5f6cd29e0 Mon Sep 17 00:00:00 2001 From: BonfaceKilz Date: Thu, 19 May 2022 12:58:31 +0300 Subject: POST new inserts --- wqflask/wqflask/templates/case_attributes.html | 75 ++++++++++++++++---------- 1 file changed, 47 insertions(+), 28 deletions(-) (limited to 'wqflask') diff --git a/wqflask/wqflask/templates/case_attributes.html b/wqflask/wqflask/templates/case_attributes.html index e5d5512c..c2db7ef8 100644 --- a/wqflask/wqflask/templates/case_attributes.html +++ b/wqflask/wqflask/templates/case_attributes.html @@ -210,43 +210,62 @@ let name = nameNode.html(); let desc = descNode.html(); - + let nodeId = $(this).parents("tr").data("id"); 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 (nodeId) { + if (name !== originalName) { + diff["Modification"] = { + name: { + Original: originalName, + Current: name, + }}; } - if (Object.keys(diff).length == 0) { - diff["Modifications"] = { - description: desc_ + if (desc !== originalDesc) { + let desc_ = { + Original: originalDesc, + Current: desc, + } + if (Object.keys(diff).length == 0) { + diff["Modification"] = { + description: desc_ + } } + else { + diff["Modification"].name = desc_; + } + } + if (!Object.keys(diff).length == 0) { + diff["id"] = nodeId; } - else { - diff["Modifications"].name = desc_; + } else { + if (name) { + diff["Insert"] = { + name: name, + } + } + if (desc) { + if (Object.keys(diff).length == 0) { + diff["Insert"] = { + description: desc, + } + } + else { + diff["Insert"].description = desc; + } } } - if (!Object.keys(diff).length == 0) { - diff["id"] = $(this).parents("tr").data("id"); + if(diff) { + $.ajax({ + type: "POST", + data: {"data": JSON.stringify(diff)}, + url: '{{ url_for("metadata_edit.update_case_attributes") }}', + /* contentType: "application/json", */ + success: function(data, status, xhr) { location.reload() } + } + ) } - $.ajax({ - type: "POST", - data: {"data": JSON.stringify(diff)}, - url: '{{ url_for("metadata_edit.update_case_attributes") }}', - /* contentType: "application/json", */ - success: function(data, status, xhr) { - location.reload(); - } - }); }); // Edit row on edit button click $(document).on("click", ".edit", function(){ -- cgit v1.2.3