From 0c2b0175ddaf241a5cb77895cbde86bf39b31dbc Mon Sep 17 00:00:00 2001 From: Linty Date: Mon, 19 Feb 2024 16:53:41 +0100 Subject: [PATCH] fixes #2119 issue #2120 uses nodes to update album UI As we're using selectize.js to display the albums, we need to use the methods provided by selectize.js to update the data returned by the Piwigo API. Bug correction: when moving an album, the "sub-albums" label disappeared. --- admin/themes/default/js/albums.js | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/admin/themes/default/js/albums.js b/admin/themes/default/js/albums.js index 942be4c2a..c0628d078 100644 --- a/admin/themes/default/js/albums.js +++ b/admin/themes/default/js/albums.js @@ -152,8 +152,15 @@ $(document).ready(() => { }, success: function (raw_data) { data = jQuery.parseJSON(raw_data); - $("#cat-"+catToEdit).find(".move-cat-title-container p.move-cat-title").html($(".RenameAlbumLabelUsername input").val()); - $("#cat-"+catToEdit).find(".move-cat-title-container p.move-cat-title").attr('title', $(".RenameAlbumLabelUsername input").val()); + const node_id = $("#cat-"+catToEdit).find('.move-cat-toogler').attr('data-id'); + const node = $('.tree').tree('getNodeById', node_id); + node.name = $(".RenameAlbumLabelUsername input").val(); + $('.tree').tree('updateNode', node, $(".RenameAlbumLabelUsername input").val()); + + $(".move-cat-title-container").on("click", function () { + openRenameAlbumPopIn($(this).find(".move-cat-title").attr("title")); + $(".RenameAlbumSubmit").data("cat_id", $(this).attr('data-id')); + }); closeRenameAlbumPopIn(); }, error: function(message) { @@ -583,6 +590,7 @@ function getAllSubAlbumsFromNode(node, nb_sub_cats) { function setSubcatsBadge(node) { if (node.children.length != 0) { $("#cat-"+node.id).find(".nb-subcats").text(node.children.length).show(100); + $("#cat-"+node.id).find(".badge-dropdown").find(".nb-subcats").text(x_nb_subcats.replace('%d', node.children.length)); } else { $("#cat-"+node.id).find(".nb-subcats").hide(100) } @@ -758,6 +766,15 @@ function changeParent(node, parent, rank) { data = jQuery.parseJSON(raw_data); if (data.stat === "ok") { changeRank(node, rank) + const updated_cats = data.result.updated_cats; + if (updated_cats) + { + updated_cats.forEach((cat) => { + const node = $('.tree').tree('getNodeById', cat.cat_id); + node.nb_sub_photos = cat.nb_sub_photos; + $('.tree').tree('updateNode', node, node.name); + }); + } res(); } else { rej(raw_data);