diff --git a/admin/picture_modify.php b/admin/picture_modify.php index bebcff2b6..bc86a5be8 100644 --- a/admin/picture_modify.php +++ b/admin/picture_modify.php @@ -357,6 +357,9 @@ SELECT category_id, uppercats ;'; $result = pwg_query($query); +$related_categories = array(); +$related_categories_ids = array(); + while ($row = pwg_db_fetch_assoc($result)) { $name = @@ -371,10 +374,14 @@ while ($row = pwg_db_fetch_assoc($result)) } else { - $template->append('related_categories', $name); + $related_categories[$row['category_id']] = $name; + $related_categories_ids[] = $row['category_id']; } } +$template->assign('related_categories', $related_categories); +$template->assign('related_categories_ids', $related_categories_ids); + // jump to link // // 1. find all linked categories that are reachable for the current user. diff --git a/admin/themes/default/js/picture_modify.js b/admin/themes/default/js/picture_modify.js new file mode 100644 index 000000000..2ccd479fd --- /dev/null +++ b/admin/themes/default/js/picture_modify.js @@ -0,0 +1,151 @@ +$(document).ready(function () { + + $(".linked-albums.add-item").on("click", function () { + linked_albums_open(); + set_up_popin(); + }); + + $(".limitReached").html(str_no_search_in_progress); + $(".search-cancel-linked-album").hide(); + $(".linkedAlbumPopInContainer .searching").hide(); + $("#linkedAlbumSearch .search-input").on('input', function () { + if ($(this).val() != 0) { + $("#linkedAlbumSearch .search-cancel-linked-album").show() + } else { + $("#linkedAlbumSearch .search-cancel-linked-album").hide(); + } + + if ($(this).val().length > 2) { + linked_albums_search($(this).val()); + } else { + $(".limitReached").html(str_no_search_in_progress); + $("#searchResult").empty(); + } + }) + + $(".search-cancel-linked-album").on("click", function () { + $("#linkedAlbumSearch .search-input").val(""); + $("#linkedAlbumSearch .search-input").trigger("input"); + }) + + $(".related-categories-container .breadcrumb-item .remove-item").on("click", function () { + remove_related_category($(this).attr("id")); + }) +}) + +function set_up_popin() { + $(".ClosePopIn").on('click', function () { + linked_albums_close(); + }); +} + +function linked_albums_close() { + $("#addLinkedAlbum").fadeOut(); +} +function linked_albums_open() { + $("#addLinkedAlbum").fadeIn(); + $(".search-input").val(""); + $(".search-input").focus(); + $("#searchResult").empty(); +} +function linked_albums_search(searchText) { + $(".linkedAlbumPopInContainer .searching").show(); + $.ajax({ + url: "ws.php?format=json&method=pwg.categories.getAdminList", + type: "POST", + dataType: "json", + data : { + search: searchText, + additional_output: "full_name_with_admin_links", + }, + before: function () { + + }, + success: function (raw_data) { + $(".linkedAlbumPopInContainer .searching").hide(); + + categories = raw_data.result.categories; + fill_results(categories); + + if (raw_data.result.limit_reached) { + $(".limitReached").html(str_result_limit.replace("%d", categories.length)); + } else { + if (categories.length == 1) { + $(".limitReached").html(str_album_found); + } else { + $(".limitReached").html(str_albums_found.replace("%d", categories.length)); + } + } + }, + error: function (e) { + $(".linkedAlbumPopInContainer .searching").hide(); + console.log(e.message); + } + }) +} + +function fill_results(cats) { + $("#searchResult").empty(); + cats.forEach(cat => { + $("#searchResult").append( + "