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( + "
" + + "" + cat.fullname +"" + + "
" + ); + + if (related_categories_ids.includes(cat.id)) { + $(".search-result-item #"+ cat.id +".item-add").addClass("notClickable").attr("title", str_already_in_related_cats).on("click", function (event) { + event.preventDefault(); + }); + } else { + $(".search-result-item #"+ cat.id +".item-add").on("click", function () { + add_related_category(cat.id, cat.full_name_with_admin_links); + }); + } + }); +} + +function remove_related_category(cat_id) { + $(".invisible-related-categories-select option[value="+ cat_id +"]").remove(); + $("#" + cat_id).parent().remove(); + related_categories_ids.pop(cat_id); + + check_related_categories(); +} + +function add_related_category(cat_id, cat_link_path) { + if (!related_categories_ids.includes(cat_id)) { + $(".related-categories-container").append( + "" + ); + + $(".search-result-item #" + cat_id).addClass("notClickable"); + related_categories_ids.push(cat_id); + $(".invisible-related-categories-select").append(""); + + $("#"+ cat_id).on("click", function () { + remove_related_category($(this).attr("id")) + }) + + linked_albums_close(); + } + + check_related_categories(); +} + +function check_related_categories() { + + $(".linked-albums-badge").html(related_categories_ids.length); + + if (related_categories_ids.length == 0) { + $(".linked-albums-badge").addClass("badge-red"); + $(".add-item").addClass("highlight"); + $(".orphan-photo").html(str_orphan).show(); + } else { + $(".linked-albums-badge.badge-red").removeClass("badge-red"); + $(".add-item.highlight").removeClass("highlight"); + $(".orphan-photo").hide(); + } +} \ No newline at end of file diff --git a/admin/themes/default/template/picture_modify.tpl b/admin/themes/default/template/picture_modify.tpl index fad561161..a2d6dd7c3 100644 --- a/admin/themes/default/template/picture_modify.tpl +++ b/admin/themes/default/template/picture_modify.tpl @@ -49,6 +49,14 @@ str_are_you_sure = '{'Are you sure?'|translate}'; str_yes = '{'Yes, delete'|translate}'; str_no = '{'No, I have changed my mind'|translate|@escape:'javascript'}'; url_delete = '{$U_DELETE}'; +str_albums_found = '{"%d albums found"|translate}'; +str_album_found = '{"1 album found"|translate}'; +str_result_limit = '{"%d+ albums found, try to refine the search"|translate|escape:javascript}'; +str_orphan = '{'This photo is an orphan'|@translate}'; +str_no_search_in_progress = '{'No search in progress'|@translate}'; + +related_categories_ids = {$related_categories_ids|@json_encode}; +str_already_in_related_cats = '{'This albums is already in related categories list'|translate}'; {literal} $('#action-delete-picture').on('click', function() { @@ -84,6 +92,9 @@ $('#action-delete-picture').on('click', function() { }()); {/footer_script} +{combine_script id='picture_modify' load='footer' path='admin/themes/default/js/picture_modify.js'} +{combine_css path="admin/themes/default/fontello/css/animation.css" order=10} {* order 10 is required, see issue 1080 *} +
@@ -154,11 +165,24 @@ $('#action-delete-picture').on('click', function() {

- {'Linked albums'|@translate} + {'Linked albums'|@translate} {$related_categories|@count} + {if $related_categories|@count < 1} + {'This photo is an orphan'|@translate} + {else} + + {/if}
- + +

+

@@ -200,6 +224,31 @@ $('#action-delete-picture').on('click', function() {

+
+
+ + +
+ +
+
+ {'Associate to album'|@translate} +
+ +
+ + + +
+
+
+
+ +
+
+
+
+