From 86dae4c2645bb1b2866dc9612471ee686842b5ce Mon Sep 17 00:00:00 2001 From: Masahiko AMANO Date: Sat, 4 Feb 2023 16:30:23 +0300 Subject: [PATCH] perf(web): do not close menu on submit --- web/public/js/tfm-management.js | 42 +++++++++++++++++---------------- 1 file changed, 22 insertions(+), 20 deletions(-) diff --git a/web/public/js/tfm-management.js b/web/public/js/tfm-management.js index 3ef3755..0dddc32 100644 --- a/web/public/js/tfm-management.js +++ b/web/public/js/tfm-management.js @@ -331,20 +331,21 @@ $(document).on("submit", "#menu-file-view form", function (e) { } resp.data.forEach(tanzaku => { let current = $(`.list-item[tid="${tanzaku.id}"]`); - if (current.hasClass("selected")) { - current.removeClass("selected"); - } else { - if (!tdb_query("$TFM", 9, '' + current_sasa.id + ' ' + tanzaku.id).status) { - console.log("ERROR: failed to remove kazari: " + current_sasa.id + '-' + tanzaku.id); - } + if (!current.hasClass("selected") && + !tdb_query("$TFM", 9, '' + current_sasa.id + ' ' + tanzaku.id).status) { + console.log("ERROR: failed to remove kazari: " + current_sasa.id + '-' + tanzaku.id); } }); - $(".tanzaku.selected").each(function (index, element) { - if (!tdb_query("$TFM", 10, '' + current_sasa.id + ' ' + $(element).attr("tid"))) { - console.log("ERROR: failed to add kazari: " + current_sasa.id + '-' + $(element).attr("tid")); + $(".list-item.tanzaku.selected").each(function (index, element) { + let tid = parseInt($(element).attr("tid")); + if (resp.data.find(t => t.id === tid) != null) { + return; + } + if (!tdb_query("$TFM", 10, '' + current_sasa.id + ' ' + tid)) { + console.log("ERROR: failed to add kazari: " + current_sasa.id + '-' + tid); } }); - menu_view_file_close(); + alert("Saved changes!"); }); $(document).on("submit", "#menu-tag-view form", function (e) { @@ -356,20 +357,21 @@ $(document).on("submit", "#menu-tag-view form", function (e) { } resp.data.forEach(sasa => { let current = $(`.list-item[sid="${sasa.id}"]`); - if (current.hasClass("selected")) { - current.removeClass("selected"); - } else { - if (!tdb_query("$TFM", 9, '' + sasa.id + ' ' + current_tanzaku.id).status) { - console.log("ERROR: failed to remove kazari: " + sasa.id + '-' + current_tanzaku.id); - } + if (!current.hasClass("selected") && + !tdb_query("$TFM", 9, '' + sasa.id + ' ' + current_tanzaku.id).status) { + console.log("ERROR: failed to remove kazari: " + sasa.id + '-' + current_tanzaku.id); } }); - $(".sasa.selected").each(function (index, element) { - if (!tdb_query("$TFM", 10, '' + $(element).attr("sid") + ' ' + current_tanzaku.id)) { - console.log("ERROR: failed to add kazari: " + $(element).attr("sid") + '-' + current_tanzaku.id); + $(".list-item.sasa.selected").each(function (index, element) { + let sid = parseInt($(element).attr("sid")); + if (resp.data.find(s => s.id === sid) != null) { + return; + } + if (!tdb_query("$TFM", 10, '' + sid + ' ' + current_tanzaku.id)) { + console.log("ERROR: failed to add kazari: " + sid + '-' + current_tanzaku.id); } }); - menu_view_tag_close(); + alert("Saved changes!"); }); $(document).on("click", "#btn-remove", function (e) {