Skip to content

Commit

Permalink
Updated items with treelist
Browse files Browse the repository at this point in the history
  • Loading branch information
UpSage authored Nov 21, 2024
1 parent 4f47818 commit 0039685
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions view/adminhtml/templates/items.phtml
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,11 @@
let currentParentForNewItem = null;
let nextId = 123;

function toggleSelectAllButton() {
const hasItems = $('#admin__container-treelist').children().length > 0;
$('#select-all').toggle(hasItems);
}

function generateTreeJSON($container) {
const treeData = [];
$container.children('.admin__item-treelist').each(function () {
Expand All @@ -126,6 +131,7 @@
return treeData;
}


function updateJsonOutput() {
const treeJSON = generateTreeJSON($('#admin__container-treelist'));
$('#json-output').val(JSON.stringify(treeJSON, null, 2));
Expand Down Expand Up @@ -174,6 +180,7 @@ function updateJsonOutput() {

$container.append($item);
});
toggleSelectAllButton();
}

function initializeSortableAndDroppable() {
Expand Down Expand Up @@ -303,6 +310,7 @@ function updateJsonOutput() {

initializeSortableAndDroppable();
updateJsonOutput();
toggleSelectAllButton();

$('.popup-overlay, #add-popup').hide();
currentParentForNewItem = null;
Expand All @@ -319,6 +327,7 @@ function updateJsonOutput() {
$(this).closest('.admin__item-treelist').remove();
updateJsonOutput();
updateDeleteButtonVisibility();
toggleSelectAllButton();
});

$('#delete-selected').click(function () {
Expand All @@ -327,11 +336,13 @@ function updateJsonOutput() {
});
updateJsonOutput();
updateDeleteButtonVisibility();
toggleSelectAllButton();
});

renderTreeList(treeData, $('#admin__container-treelist'));
setTimeout(initializeSortableAndDroppable, 0);
updateJsonOutput();
toggleSelectAllButton();
});


Expand Down

0 comments on commit 0039685

Please sign in to comment.