diff --git a/admin/albums.php b/admin/albums.php
index 6de2f0828..bd9fc8707 100644
--- a/admin/albums.php
+++ b/admin/albums.php
@@ -169,6 +169,8 @@ function assocToOrderedTree($assocT)
{
$orderedTree = array();
+
+ // echo '
'; print_r($assocT); echo '
';
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);
diff --git a/admin/themes/default/js/albums.js b/admin/themes/default/js/albums.js
index 347bdf06e..39ab6d33d 100644
--- a/admin/themes/default/js/albums.js
+++ b/admin/themes/default/js/albums.js
@@ -71,11 +71,17 @@ $(document).ready(() => {
cont.find(".move-cat-title").after(
""
- +" aaaa "
- +" aaaa "
- +" aaaa "
+ +""
+ +""+ node.nb_images +""
+ +""+ node.last_updates +""
+"
"
)
+
+ 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") {