diff --git a/admin/cat_search.php b/admin/cat_search.php deleted file mode 100644 index 3a0e211c6..000000000 --- a/admin/cat_search.php +++ /dev/null @@ -1,99 +0,0 @@ - 25) - { - $name = mb_substr($name, 0, 25).'...'; - } - - $placeholder = $name; - break; -} - -if (empty($placeholder)) -{ - $placeholder = l10n('Portraits'); -} - -$template->set_filename('cat_search', 'cat_search.tpl'); - -$template->assign( - array( - 'data_cat' => $categories, - 'ADMIN_PAGE_TITLE' => l10n('Albums'), - 'placeholder' => $placeholder, - ) -); - -// +-----------------------------------------------------------------------+ -// | sending html code | -// +-----------------------------------------------------------------------+ -$template->assign_var_from_handle('ADMIN_CONTENT', 'cat_search'); -?> diff --git a/admin/include/add_core_tabs.inc.php b/admin/include/add_core_tabs.inc.php index 37be24774..1f3e9b63f 100644 --- a/admin/include/add_core_tabs.inc.php +++ b/admin/include/add_core_tabs.inc.php @@ -35,7 +35,6 @@ function add_core_tabs($sheets, $tab_id) global $my_base_url; $sheets['list'] = array('caption' => ''.l10n('List'), 'url' => $my_base_url.'albums'); $sheets['permalinks'] = array('caption' => ''.l10n('Permalinks'), 'url' => $my_base_url.'permalinks'); - $sheets['search'] = array('caption' => ''.l10n('Search'), 'url' => $my_base_url.'cat_search'); break; case 'users': diff --git a/admin/themes/default/js/albums.js b/admin/themes/default/js/albums.js index 370ddbc09..addf1aba9 100644 --- a/admin/themes/default/js/albums.js +++ b/admin/themes/default/js/albums.js @@ -389,6 +389,7 @@ function createAlbumNode(node, li) { } cont.append($(icon.replace(/%icon%/g, 'icon-grip-vertical-solid'))); + cont.find('.icon-grip-vertical-solid').attr('title', str_albs_drag_drop); if (node.haveChildren || node.children.length != 0) { cont.append($(icon.replace(/%icon%/g, 'icon-sitemap'))); diff --git a/admin/themes/default/js/cat_search.js b/admin/themes/default/js/cat_search.js new file mode 100644 index 000000000..281b0d155 --- /dev/null +++ b/admin/themes/default/js/cat_search.js @@ -0,0 +1,118 @@ +const RESULT_LIMIT = 100; +const editLink = "admin.php?page=album-"; +const colors = ["icon-red", "icon-blue", "icon-yellow", "icon-purple", "icon-green"]; + +$(function() { + $(".limit-album-reached").hide(); + + $('#cat_search_input').on('input', () => { + updateSearch(); + }); +}) + +// Update the page according to the search field +function updateSearch () { + let string = $('.search-input').val(); + $('.search-album-result').html(""); + $('.search-album-noresult').hide(); + $(".limit-album-reached").hide(); + if (string == '') { + // help button unnecessary so do not show + // $('.search-album-help').show(); + $('.search-album-ghost').show(); + $('.search-album-num-result').hide(); + hideSearchContainer(); + } else { + $('.search-album-ghost').hide(); + $('.search-album-help').hide(); + $('.search-album-num-result').show(); + showSearchContainer(); + + let nbResult = 0; + + nbResult = searchAlbumByName(data, string, nbResult); + + if (nbResult != 1) { + if (nbResult >= RESULT_LIMIT) { + $('.search-album-num-result').html(str_result_limit.replace('%d', nbResult)); + } else { + $('.search-album-num-result').html(str_albums_found.replace('%d', nbResult)); + } + } else { + $('.search-album-num-result').html(str_album_found); + } + + if (nbResult != 0) { + resultAppear($('.search-album-result .search-album-elem').first()); + } else { + $('.search-album-noresult').show(); + } + } +} + +function searchAlbumByName(categories, search, nbResult, children, name='') { + for (const c of categories) { + if (nbResult >= RESULT_LIMIT) { + return nbResult; + } + + let currentName = name + `${c.name}` + ' / '; + + if (c.name.toString().toLowerCase().includes(search.toLowerCase())) { + const haveChild = c.children && c.children.length ? true : false; + nbResult++; + addAlbumResult(c, nbResult, haveChild, currentName); + } + + if (c.children && c.children.length) { + nbResult = searchAlbumByName(c.children, search, nbResult, true, currentName); + } + + } + return nbResult; +} + +// Add an album as a result in the page +function addAlbumResult (cat, nbResult, haveChildren, name) { + const id = +cat.id; + const template = $('.search-album-elem-template').html(); + const newCatNode = $(template); + + if (haveChildren) { + newCatNode.find('.search-album-icon').addClass('icon-sitemap'); + } else { + newCatNode.find('.search-album-icon').addClass('icon-folder-open'); + } + + const colorId = id%5; + newCatNode.find('.search-album-icon').addClass(colors[colorId]); + newCatNode.find('.search-album-name').html(name.slice(0, -2)); + + const href = "admin.php?page=album-" + id; + newCatNode.find('.search-album-edit').attr('href', href); + + $('.search-album-result').append(newCatNode); + + if(nbResult >= RESULT_LIMIT) { + $(".limit-album-reached").show(1000); + $('.limit-album-reached').html(str_result_limit.replace('%d', nbResult)); + } +} + +// Make the results appear one after one [and limit results to 100] +function resultAppear(result) { + result.fadeIn(); + if (result.next().length != 0) { + setTimeout(() => {resultAppear(result.next().first())}, 50); + } +} + +function showSearchContainer() { + $('.tree').hide(); + $('.album-search-result-container').show(); +} + +function hideSearchContainer() { + $('.album-search-result-container').hide(); + $('.tree').fadeIn(); +} diff --git a/admin/themes/default/template/albums.tpl b/admin/themes/default/template/albums.tpl index 6476c194d..4686b3cae 100644 --- a/admin/themes/default/template/albums.tpl +++ b/admin/themes/default/template/albums.tpl @@ -19,7 +19,14 @@ var x_nb_subcats = "{'%d sub-albums'|@translate}"; var x_nb_images = "{'%d photos'|@translate}"; var x_nb_sub_photos = "{'%d pictures in sub-albums'|@translate}"; +var str_albums_found = '{"%d albums found"|translate}'; +var str_album_found = '{"1 album found"|translate}'; +var str_result_limit = '{"%d+ albums found, try to refine the search"|translate|escape:javascript}'; +const str_albs_drag_drop = '{"Drag and drop to reorder albums"|translate}'; + var delay_autoOpen = {$delay_before_autoOpen} + +const categoriesforSearch = Object.values(data); {/footer_script} {combine_script id='jquery.confirm' load='footer' require='jquery' path='themes/default/js/plugins/jquery-confirm.min.js'} @@ -54,6 +61,7 @@ const tiptip_locked_album = "{'Locked album'|translate|escape:javascript}"; {combine_script id='jquery.tipTip' load='footer' path='themes/default/js/plugins/jquery.tipTip.minified.js'} +{combine_script id='cat_search' load='footer' path='admin/themes/default/js/cat_search.js'} {combine_script id='albums' load='footer' path='admin/themes/default/js/albums.js'}
@@ -129,7 +137,19 @@ const tiptip_locked_album = "{'Locked album'|translate|escape:javascript}";

{'Automatic sort order'|@translate}

-
{'Drag and drop to reorder albums'|@translate}
+ {*
{'Drag and drop to reorder albums'|@translate}
*} +
+
+ {*
{'Search albums'|@translate}
*} + +
+ + + +
+ +
+
@@ -246,6 +266,26 @@ const tiptip_locked_album = "{'Locked album'|translate|escape:javascript}";
+ + + - diff --git a/admin/themes/default/theme.css b/admin/themes/default/theme.css index 9e41c1909..56d32eb0d 100644 --- a/admin/themes/default/theme.css +++ b/admin/themes/default/theme.css @@ -6628,8 +6628,6 @@ li.plupload_delete a:hover {background: url("images/cancelhover.svg")!important; display: flex; justify-content: center; align-items: center; - margin: 10px; - margin-bottom: 25px } .search-album-cont { @@ -6645,7 +6643,7 @@ li.plupload_delete a:hover {background: url("images/cancelhover.svg")!important; } .search-album-num-result { - margin-left: 10px; + margin-right: 10px; } .search-album-input-container { @@ -6663,7 +6661,7 @@ li.plupload_delete a:hover {background: url("images/cancelhover.svg")!important; font-size: 20px; } -.search-album-help, .search-album-num-result { +.search-album-help { position: absolute; right: 0; transform: translateX(calc(100% + 10px)); @@ -6674,6 +6672,10 @@ li.plupload_delete a:hover {background: url("images/cancelhover.svg")!important; flex-direction: column; } +.search-album-result { + margin-top: 30px; +} + .search-album-elem, .search-album-ghost div { height: 64px; border-radius: 5px; @@ -6775,6 +6777,10 @@ li.plupload_delete a:hover {background: url("images/cancelhover.svg")!important; display: none; } +.limit-album-reached { + justify-content: center; +} + .doubleSelect { width: 100%; } diff --git a/install/obsolete.list b/install/obsolete.list index 03fd279ba..21521f440 100644 --- a/install/obsolete.list +++ b/install/obsolete.list @@ -141,4 +141,6 @@ themes/default/vendor/fontello/font/fontello.svg themes/default/vendor/fontello/font/fontello.ttf themes/default/vendor/fontello/font/fontello.woff themes/default/vendor/fontello/font/fontello.woff2 +admin/cat_search.php +admin/themes/default/template/cat_search.tpl obsolete.list