diff --git a/admin/albums.php b/admin/albums.php index d2a1319f9..42fb4fc5c 100644 --- a/admin/albums.php +++ b/admin/albums.php @@ -125,6 +125,8 @@ $template->assign( $template->assign('delay_before_autoOpen', $conf['album_move_delay_before_auto_opening']); +$template->assign("POS_PREF", $conf['newcat_default_position']); + // +-----------------------------------------------------------------------+ // | Album display | // +-----------------------------------------------------------------------+ diff --git a/admin/themes/clear/theme.css b/admin/themes/clear/theme.css index 002c468a5..6ba07d952 100644 --- a/admin/themes/clear/theme.css +++ b/admin/themes/clear/theme.css @@ -563,7 +563,7 @@ input:focus + .slider { /*UserList Pop in*/ -.CloseUserList{ +.CloseUserList, .CloseAddAlbum, .CloseDeleteAlbum{ color:white; } diff --git a/admin/themes/default/js/albums.js b/admin/themes/default/js/albums.js index 4b0dcaa4f..af7590ca5 100644 --- a/admin/themes/default/js/albums.js +++ b/admin/themes/default/js/albums.js @@ -21,14 +21,14 @@ $(document).ready(() => { actions = '
'; - action_order = ""; + action_order = ""; cont = li.find('.jqtree-element'); cont.addClass('move-cat-container'); @@ -48,7 +48,7 @@ $(document).ready(() => { .replace(/%content%/g, toggler) .replace(/%id%/g, node.id))); - cont.find('.move-cat-action').append(action_order); + cont.find('.move-cat-action .move-cat-see').after(action_order); } cont.append($(icon.replace(/%icon%/g, 'icon-grip-vertical-solid'))); @@ -209,8 +209,189 @@ $(document).ready(() => { } }) + + // AddAlbumPopIn + $(".AddAlbumErrors").hide(); + $(".DeleteAlbumErrors").hide(); + $(".move-cat-add").on("click", function () { + openAddAlbumPopIn(); + }) + $(".CloseAddAlbum").on("click", function () { + closeAddAlbumPopIn(); + }); + $(".AddAlbumCancel").on("click", function () { + closeAddAlbumPopIn(); + }); + $(".DeleteAlbumCancel").on("click", function () { + closeDeleteAlbumPopIn(); + }); + + $(".AddAlbumSubmit").on("click", function () { + newAlbumName = $(".AddAlbumLabelUsername input").val(); + newAlbumParent = $(".AddAlbumSubmit").data("a-parent"); + newAlbumPosition = $("input[name=position]:checked").val(); + + jQuery.ajax({ + url: "ws.php?format=json&method=pwg.categories.add", + type: "POST", + data: { + name : newAlbumName, + parent : newAlbumParent, + position : newAlbumPosition + }, + success: function (raw_data) { + data = jQuery.parseJSON(raw_data); + var parent_node = $('.tree').tree('getNodeById', newAlbumParent); + $('.tree').tree( + 'appendNode', + { + id: data.result.id, + isEmptyFolder: true, + name: newAlbumName + }, + parent_node + ); + + $("#cat-"+data.result.id+" .move-cat-add").on("click", function () { + openAddAlbumPopIn(); + }) + }, + error: function(message) { + + } + }); + + }) + + // Delete Album + $(".move-cat-delete").on("click", function () { + cat_id = $(this).data("id"); + console.log(cat_id); + + $.ajax({ + url: "ws.php?format=json&method=pwg.categories.calculateOrphans", + type: "GET", + data: { + category_id: cat_id, + }, + success: function (raw_data) { + let data = JSON.parse(raw_data).result[0] + console.log(data); + if (data.nb_images_recursive == 0) { + $(".deleteAlbumOptions").hide(); + } else { + $(".deleteAlbumOptions").show(); + if (data.nb_images_associated_outside == 0) { + $("#IMAGES_ASSOCIATED_OUTSIDE").hide(); + } else { + $("#IMAGES_ASSOCIATED_OUTSIDE .innerText").html(""); + $("#IMAGES_ASSOCIATED_OUTSIDE .innerText").append(has_images_associated_outside.replace('%d', data.nb_images_recursive).replace('%d', data.nb_images_associated_outside)); + } + if (data.nb_images_becoming_orphan == 0) { + $("#IMAGES_BECOMING_ORPHAN").hide(); + } else { + $("#IMAGES_BECOMING_ORPHAN .innerText").html(""); + $("#IMAGES_BECOMING_ORPHAN .innerText").append(has_images_becomming_orphans.replace('%d', data.nb_images_becoming_orphan)); + } + } + }, + error: function(message) { + console.log(message); + } + }).done(function () { + openDeleteAlbumPopIn(cat_id); + }); + }) + + /*---------------- + Checkboxes + ----------------*/ + + function checkbox_change() { + if ($(this).attr('data-selected') == '1') { + $(this).find("i").hide(); + } else { + $(this).find("i").show(); + } + } + + function checkbox_click() { + if ($(this).attr('data-selected') == '1') { + $(this).attr('data-selected', '0'); + $(this).find("i").hide(); + } else { + $(this).attr('data-selected', '1'); + $(this).find("i").show(); + } + } + + $('.user-list-checkbox').unbind("change").change(checkbox_change); + $('.user-list-checkbox').unbind("click").click(checkbox_click); + }); +function openAddAlbumPopIn() { + $("#AddAlbum").fadeIn(); + $(".AddAlbumSubmit").data("a-parent", $(this).data("aid")); + $(".AddAlbumLabelUsername .user-property-input").val(''); + $(".AddAlbumLabelUsername .user-property-input").focus(); +} + +function closeAddAlbumPopIn() { + $("#AddAlbum").fadeOut(); +} + +function openDeleteAlbumPopIn(cat_to_delete) { + $("#DeleteAlbum").fadeIn(); + node = $(".tree").tree('getNodeById', cat_to_delete); + if (node.children.length == 0) { + $(".DeleteIconTitle span").html(delete_album_with_name.replace("%s", node.name)); + } else { + nb_sub_cats = 0; + test = getSubAlbumsFromNode(node, nb_sub_cats); + $(".DeleteIconTitle span").html(delete_album_with_subs.replace("%s", node.name).replace("%d", getSubAlbumsFromNode(node, nb_sub_cats))); + } + + // Actually delete + + $(".DeleteAlbumSubmit").unbind("click").on("click", function () { + $.ajax({ + url: "ws.php?format=json&method=pwg.categories.delete", + type: "POST", + data: { + category_id: cat_to_delete, + photo_deletion_mode: $("input [name=photo_deletion_mode]:checked").val(), + pwg_token: pwg_token, + }, + success: function (raw_data) { + $('.tree').tree('removeNode', node); + closeDeleteAlbumPopIn(); + }, + error: function(message) { + console.log(message); + } + }); + }) + +} +function closeDeleteAlbumPopIn() { + $("#DeleteAlbum").fadeOut(); +} + +function getSubAlbumsFromNode(node, nb_sub_cats) { + nb_sub_cats = 0; + if (node.children != 0) { + node.children.forEach(child => { + nb_sub_cats++; + tmp = getSubAlbumsFromNode(child, nb_sub_cats); + nb_sub_cats += tmp; + }); + } else { + return 0; + } + return nb_sub_cats; +} + function goToNode(node, firstNode) { // console.log(firstNode.id, node.id); if (node.parent) { diff --git a/admin/themes/default/template/albums.tpl b/admin/themes/default/template/albums.tpl index 6addde8c0..e8f6fb8cb 100644 --- a/admin/themes/default/template/albums.tpl +++ b/admin/themes/default/template/albums.tpl @@ -23,6 +23,14 @@ var delay_autoOpen = {$delay_before_autoOpen} {combine_script id='jtree' load='footer' path='themes/default/js/plugins/tree.jquery.js'} {combine_css path="admin/themes/default/fontello/css/animation.css" order=10} {* order 10 is required, see issue 1080 *} +{footer_script} +const delete_album_with_name = '{'Delete album "%s".'|@translate|escape:javascript}'; +const delete_album_with_subs = '{'Delete album "%s" and its %d sub-albums.'|@translate|escape:javascript}' +const has_images_associated_outside = '{"delete album and all %d photos, even the %d associated to other albums"|@translate|escape:javascript}'; +const has_images_becomming_orphans = '{'delete album and the %d orphan photos'|@translate|escape:javascript}'; +const has_images_recursives = '{'delete only album, not photos'|@translate|escape:javascript}'; +{/footer_script} + {combine_script id='albums' load='footer' path='admin/themes/default/js/albums.js'}