|
5 | 5 |
|
6 | 6 | @endphp |
7 | 7 |
|
8 | | -@include('filament-tree::tree.scripts', ['containerKey' => $containerKey, $maxDepth => $maxDepth]) |
9 | | - |
10 | | -<div wire:disabled="updateTree"> |
| 8 | +<div wire:disabled="updateTree" |
| 9 | + x-data="{ |
| 10 | + init: function () { |
| 11 | + let nestedTree = $('#{{ $containerKey }}').nestable({ |
| 12 | + group: {{ $containerKey }}, |
| 13 | + maxDepth: {{ $maxDepth }}, |
| 14 | + expandBtnHTML: '', |
| 15 | + collapseBtnHTML: '', |
| 16 | + }); |
| 17 | + |
| 18 | + // Custom expand/collapse buttons |
| 19 | + $('#{{ $containerKey }} .dd-item-btns [data-action=expand]').on('click', function (el) { |
| 20 | + let list = $(this).closest('li'); |
| 21 | + if (list.length) { |
| 22 | + $(this).addClass('hidden'); |
| 23 | + $(this).parent().children('.dd-item-btns [data-action=collapse]').removeClass('hidden'); |
| 24 | + list.find('> .dd-list').removeClass('hidden').show(); |
| 25 | + list.find('> .dd-list > .dd-item').removeClass('dd-collapsed hidden'); |
| 26 | + } |
| 27 | + }); |
| 28 | + $('#{{ $containerKey }} .dd-item-btns [data-action=collapse]').on('click', function (el) { |
| 29 | + let list = $(this).closest('li'); |
| 30 | + if (list.length) { |
| 31 | + $(this).addClass('hidden'); |
| 32 | + $(this).parent().children('.dd-item-btns [data-action=expand]').removeClass('hidden'); |
| 33 | + list.find('> .dd-list').addClass('hidden').hide(); |
| 34 | + list.find('> .dd-list > .dd-item').addClass('dd-collapsed hidden'); |
| 35 | + } |
| 36 | + }); |
| 37 | + |
| 38 | + $('#nestable-menu [data-action=expand-all]').on('click', function () { |
| 39 | + $('.dd').nestable('expandAll'); |
| 40 | + $('.dd').find('.dd-item-btns [data-action=expand]').addClass('hidden'); |
| 41 | + $('.dd').find('.dd-item-btns [data-action=collapse]').removeClass('hidden'); |
| 42 | + $('.dd > ol > li').find('li').removeClass('hidden'); |
| 43 | + }); |
| 44 | + $('#nestable-menu [data-action=collapse-all]').on('click', function () { |
| 45 | + $('.dd').nestable('collapseAll'); |
| 46 | + $('.dd').find('.dd-item-btns [data-action=expand]').removeClass('hidden'); |
| 47 | + $('.dd').find('.dd-item-btns [data-action=collapse]').addClass('hidden'); |
| 48 | + $('.dd > ol > li').find('li').addClass('hidden'); |
| 49 | + }); |
| 50 | + $('#nestable-menu [data-action=save]').on('click', async function (e) { |
| 51 | + let value = $('#{{ $containerKey }}').nestable('serialize'); |
| 52 | + let result = await @this.updateTree(value); |
| 53 | + if (result['reload'] === true) { |
| 54 | + window.location.reload(); |
| 55 | + } |
| 56 | + }); |
| 57 | + } |
| 58 | + }"> |
11 | 59 | <x-filament::section :heading="($this->displayTreeTitle() ?? false) ? $this->getTreeTitle() : null"> |
12 | 60 | <menu class="flex gap-2 mb-4" id="nestable-menu"> |
13 | 61 | <div class="btn-group"> |
|
0 commit comments