From 6518bd0136fc5f78906dfb98787aad595e73de30 Mon Sep 17 00:00:00 2001 From: Matthieu Leproux Date: Mon, 28 Mar 2022 16:57:47 +0200 Subject: [PATCH] related to #1609 added create album and album deletion Album creation bug, it places the ne album at the root Album deletion bug, when deleting an album, the other click event are removed I don't know why yet --- admin/albums.php | 2 + admin/themes/clear/theme.css | 2 +- admin/themes/default/js/albums.js | 189 +++++++++++++++- admin/themes/default/template/albums.tpl | 267 +++++++++++++++++++++++ admin/themes/default/theme.css | 18 +- admin/themes/roma/theme.css | 2 +- include/ws_functions/pwg.categories.php | 6 + ws.php | 1 + 8 files changed, 476 insertions(+), 11 deletions(-) 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'}
@@ -101,6 +109,86 @@ var delay_autoOpen = {$delay_before_autoOpen} {'Apply an automatic order to root albums'|@translate}
+
+
+ + +
+ +
+
+ {'Créer un nouvel album à la racine'|translate} +
+ +
+ +
+ +
+
+ + +
+
+ +
+
+ {'Add'|@translate} +
+ +
+ {'Cancel'|@translate} +
+
+
+
+ +
+
+
+ {'Supprimer l\'album : tatatatattata'|translate} +
+ +
+
    +
  • +
  • +
  • +
+
+ + +
+
+ +
+
+ {'Confirm deletion'|translate} +
+ +
+ {'Cancel'|translate} +
+
+
+
+
\ No newline at end of file diff --git a/admin/themes/default/theme.css b/admin/themes/default/theme.css index f44d613ac..544eb3223 100644 --- a/admin/themes/default/theme.css +++ b/admin/themes/default/theme.css @@ -5313,7 +5313,7 @@ input:checked + .slider:before, input:checked + .slider::after { position: relative; } -.AddUserErrors, .update-user-fail { +.AddUserErrors, .update-user-fail, .AddAlbumErrors { background-color: #ffcfcf; color: #ff5252; border-left:solid 3px red; @@ -6255,19 +6255,27 @@ color:#FF7B00; color: black; } -.AddUserPopInContainer { +.AddUserPopInContainer, +.AddAlbumPopInContainer, +.DeleteAlbumPopInContainer { background-color: white; } -.AddUserPopInContainer .AddIconTitle { +.AddUserPopInContainer .AddIconTitle, +.AddAlbumPopInContainer .AddIconTitle, +.DeleteAlbumPopInContainer .DeleteIconTitle { color: #000000; } -.AddUserPopInContainer .AddUserLabel { +.AddUserPopInContainer .AddUserLabel, +.AddAlbumPopInContainer .AddAlbumLabel, +.DeleteAlbumPopInContainer .DeleteAlbumLabel { color: #3E3E3E; } -.AddUserPopInContainer .AddUserInput { +.AddUserPopInContainer .AddUserInput, +.AddAlbumPopInContainer .AddAlbumInput, +.DeleteAlbumPopInContainer .DeleteAlbumInput { background-color:white; border: solid 2px #D4D4D4; } diff --git a/admin/themes/roma/theme.css b/admin/themes/roma/theme.css index cc97d023e..58781142d 100644 --- a/admin/themes/roma/theme.css +++ b/admin/themes/roma/theme.css @@ -708,7 +708,7 @@ input:focus + .slider { /*UserList Pop in*/ -.CloseUserList{ +.CloseUserList, .CloseAddAlbum, #CloseDeleteAlbum{ color:white; } diff --git a/include/ws_functions/pwg.categories.php b/include/ws_functions/pwg.categories.php index 3c3ab82a7..40b54a2bc 100644 --- a/include/ws_functions/pwg.categories.php +++ b/include/ws_functions/pwg.categories.php @@ -572,6 +572,12 @@ function ws_categories_add($params, &$service) { include_once(PHPWG_ROOT_PATH.'admin/include/functions.php'); + global $conf; + + if ($params["position"] != "") { + $conf['newcat_default_position'] = $params["position"]; + } + $options = array(); if (!empty($params['status']) and in_array($params['status'], array('private','public'))) { diff --git a/ws.php b/ws.php index b416b6f6d..92c3812a6 100644 --- a/ws.php +++ b/ws.php @@ -582,6 +582,7 @@ function ws_addDefaultMethods( $arr ) 'info'=>'public, private'), 'commentable' => array('default'=>true, 'type'=>WS_TYPE_BOOL), + 'position' => array('default'=>null), ), 'Adds an album.', $ws_functions_root . 'pwg.categories.php',