related to #1609 subcats badge works and updates when moving albums

This commit is contained in:
Matthieu Leproux
2022-04-04 12:57:00 +02:00
parent 2d6ef34962
commit 423297d4a7
2 changed files with 35 additions and 7 deletions
+6
View File
@@ -169,6 +169,8 @@ function assocToOrderedTree($assocT)
{
$orderedTree = array();
// echo '<pre>'; print_r($assocT); echo '</pre>';
foreach($assocT as $cat)
{
$orderedCat = array();
@@ -176,8 +178,12 @@ function assocToOrderedTree($assocT)
$orderedCat['name'] = $cat['cat']['name'];
$orderedCat['status'] = $cat['cat']['status'];
$orderedCat['id'] = $cat['cat']['id'];
$orderedCat['nb_images'] = 'test2';
$orderedCat['last_updates'] = 'test3';
if (isset($cat['children']))
{
//Does not update when moving a node
$orderedCat['nb_subcats'] = count($cat['children']);
$orderedCat['children'] = assocToOrderedTree($cat['children']);
}
array_push($orderedTree, $orderedCat);
+29 -7
View File
@@ -71,11 +71,17 @@ $(document).ready(() => {
cont.find(".move-cat-title").after(
"<div class='badge-container'>"
+"<i class='icon-blue icon-sitemap'> aaaa </i>"
+"<i class='icon-purple icon-picture'> aaaa </i>"
+"<i class='icon-red icon-back-in-time'> aaaa </i>"
+"<i class='icon-blue icon-sitemap nb-subcats'></i>"
+"<i class='icon-purple icon-picture nb-images'>"+ node.nb_images +"</i>"
+"<i class='icon-red icon-back-in-time last-update'>"+ node.last_updates +"</i>"
+"</div>"
)
if (node.nb_subcats) {
cont.find(".nb-subcats").text(node.nb_subcats);
} else {
cont.find(".nb-subcats").hide();
}
}
var url_split = window.location.href.split("#");
@@ -385,8 +391,7 @@ function openDeleteAlbumPopIn(cat_to_delete) {
$(".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)));
$(".DeleteIconTitle span").html(delete_album_with_subs.replace("%s", node.name).replace("%d", getAllSubAlbumsFromNode(node, nb_sub_cats)));
}
// Actually delete
@@ -410,6 +415,7 @@ function openDeleteAlbumPopIn(cat_to_delete) {
triggerDeleteAlbum($(this).data("id"));
});
// setSubcatsBadge($('.tree').tree('getNodeById', node.parent));
closeDeleteAlbumPopIn();
},
error: function(message) {
@@ -423,12 +429,12 @@ function closeDeleteAlbumPopIn() {
$("#DeleteAlbum").fadeOut();
}
function getSubAlbumsFromNode(node, nb_sub_cats) {
function getAllSubAlbumsFromNode(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);
tmp = getAllSubAlbumsFromNode(child, nb_sub_cats);
nb_sub_cats += tmp;
});
} else {
@@ -437,6 +443,16 @@ function getSubAlbumsFromNode(node, nb_sub_cats) {
return nb_sub_cats;
}
function setSubcatsBadge(node) {
console.log($("#cat-"+node.id).find(".nb-subcats"));
console.log("the node "+node.id+" has " +node.children.length+"children" );
if (node.children.length != 0) {
$("#cat-"+node.id).find(".nb-subcats").text(node.children.length).show();
} else {
$("#cat-"+node.id).find(".nb-subcats").hide()
}
}
function goToNode(node, firstNode) {
// console.log(firstNode.id, node.id);
if (node.parent) {
@@ -531,6 +547,8 @@ function applyMove(event) {
event.move_info.do_move();
clearTimeout(waitingTimeout);
$('.waiting-message').removeClass('visible');
setSubcatsBadge(previous_parent);
setSubcatsBadge($('.tree').tree('getNodeById', moveParent));
})
.catch((message) => console.log('An error has occured : ' + message ));
}
@@ -546,6 +564,7 @@ function moveNode(node, rank, parent) {
}
function changeParent(node, parent, rank) {
oldParent = node.parent
return new Promise((res, rej) => {
jQuery.ajax({
url: "ws.php?format=json&method=pwg.categories.move",
@@ -555,6 +574,9 @@ function changeParent(node, parent, rank) {
parent : parent,
pwg_token : pwg_token
},
before: function () {
oldParent = node.parent
},
success: function (raw_data) {
data = jQuery.parseJSON(raw_data);
if (data.stat === "ok") {