xref: /webtrees/resources/views/edit-blocks-page.phtml (revision 1270d2767576ed4a83917769b0ee3613e3b010bf)
1efbc3a0cSGreg Roach<?php
2efbc3a0cSGreg Roach
310e06497SGreg Roachdeclare(strict_types=1);
410e06497SGreg Roach
5efbc3a0cSGreg Roachuse Fisharebest\Webtrees\I18N;
67c2c99faSGreg Roachuse Fisharebest\Webtrees\Module\ModuleBlockInterface;
7efbc3a0cSGreg Roachuse Fisharebest\Webtrees\View;
87c2c99faSGreg Roachuse Illuminate\Support\Collection;
97c2c99faSGreg Roach
107c2c99faSGreg Roach/**
117c2c99faSGreg Roach * @var Collection<string,ModuleBlockInterface> $all_blocks
127c2c99faSGreg Roach * @var bool                                    $can_reset
137c2c99faSGreg Roach * @var Collection<int,ModuleBlockInterface>    $main_blocks
147c2c99faSGreg Roach * @var Collection<int,ModuleBlockInterface>    $side_blocks
157c2c99faSGreg Roach * @var string                                  $title
167c2c99faSGreg Roach * @var string                                  $url_cancel
177c2c99faSGreg Roach * @var string                                  $url_save
187c2c99faSGreg Roach */
19efbc3a0cSGreg Roach
20efbc3a0cSGreg Roach?>
21dd6b2bfcSGreg Roach
2239b853a7SGreg Roach<h2><?= $title ?></h2>
2339b853a7SGreg Roach
24efbc3a0cSGreg Roach<p class="mt-4 mb-1">
25efbc3a0cSGreg Roach    <?= I18N::translate('Drag the blocks to change their position.') ?>
2639b853a7SGreg Roach</p>
2739b853a7SGreg Roach
2883615acfSGreg Roach<form method="post" action="<?= e($url_save) ?>" id="edit-blocks">
2961275c55SJonathan Jaubart    <div class="row row-cols-1 row-cols-sm-2 g-3" id="current-blocks">
3061275c55SJonathan Jaubart        <div class="col">
3161275c55SJonathan Jaubart            <div class="card h-100">
3295021a04SGreg Roach                <div class="card-body" id="main-blocks">
3339b853a7SGreg Roach                    <?php foreach ($main_blocks as $block_id => $block) : ?>
34efbc3a0cSGreg Roach                        <?= view('edit-blocks-block', ['block_id' => $block_id, 'block' => $block]) ?>
3539b853a7SGreg Roach                    <?php endforeach ?>
3639b853a7SGreg Roach                </div>
3797e0d077SGreg Roach            </div>
3861275c55SJonathan Jaubart        </div>
3961275c55SJonathan Jaubart        <div class="col">
4061275c55SJonathan Jaubart            <div class="card h-100">
4195021a04SGreg Roach                <div class="card-body" id="side-blocks">
42efbc3a0cSGreg Roach                    <?php foreach ($side_blocks as $block_id => $block) : ?>
43efbc3a0cSGreg Roach                        <?= view('edit-blocks-block', ['block_id' => $block_id, 'block' => $block]) ?>
44efbc3a0cSGreg Roach                    <?php endforeach ?>
45efbc3a0cSGreg Roach                </div>
46efbc3a0cSGreg Roach            </div>
4797e0d077SGreg Roach        </div>
4861275c55SJonathan Jaubart    </div>
49efbc3a0cSGreg Roach
50efbc3a0cSGreg Roach    <p class="mt-4 mb-1">
51efbc3a0cSGreg Roach        <?= I18N::translate('Add more blocks from the following list.') ?>
52efbc3a0cSGreg Roach    </p>
53efbc3a0cSGreg Roach
54efbc3a0cSGreg Roach    <div class="d-flex flex-wrap" id="available-blocks">
55efbc3a0cSGreg Roach        <?php foreach ($all_blocks as $block_id => $block) : ?>
56efbc3a0cSGreg Roach            <?= view('edit-blocks-block', ['block_id' => $block_id, 'block' => $block]) ?>
57efbc3a0cSGreg Roach        <?php endforeach ?>
58efbc3a0cSGreg Roach    </div>
59efbc3a0cSGreg Roach
60efbc3a0cSGreg Roach    <hr>
61efbc3a0cSGreg Roach
62efbc3a0cSGreg Roach    <div>
63efbc3a0cSGreg Roach        <button class="btn btn-primary" type="submit">
6439b853a7SGreg Roach            <?= view('icons/save') ?>
6539b853a7SGreg Roach            <?= I18N::translate('save') ?>
6639b853a7SGreg Roach        </button>
67efbc3a0cSGreg Roach
6839b853a7SGreg Roach        <a class="btn btn-secondary" href="<?= e($url_cancel) ?>">
6939b853a7SGreg Roach            <?= view('icons/cancel') ?>
7039b853a7SGreg Roach            <?= I18N::translate('cancel') ?>
7139b853a7SGreg Roach        </a>
72efbc3a0cSGreg Roach
73efbc3a0cSGreg Roach        <?php if ($can_reset) : ?>
74*1270d276SGreg Roach            <button class="btn btn-link" id="defaults" type="submit" name="defaults" value="on" data-wt-confirm="<?= I18N::translate('Restore the default block layout') ?>">
75efbc3a0cSGreg Roach                <?= I18N::translate('Restore the default block layout') ?>
76efbc3a0cSGreg Roach            </button>
77efbc3a0cSGreg Roach        <?php endif ?>
78efbc3a0cSGreg Roach    </div>
7981443e3cSGreg Roach
8081443e3cSGreg Roach    <?= csrf_field() ?>
8139b853a7SGreg Roach</form>
8239b853a7SGreg Roach
83efbc3a0cSGreg Roach<?php View::push('styles') ?>
84efbc3a0cSGreg Roach<style>
85efbc3a0cSGreg Roach    #available-blocks .wt-icon-delete {
86efbc3a0cSGreg Roach        display: none;
87efbc3a0cSGreg Roach    }
88efbc3a0cSGreg Roach
89efbc3a0cSGreg Roach    #current-blocks .wt-icon-help {
90efbc3a0cSGreg Roach        display: none;
91efbc3a0cSGreg Roach    }
92efbc3a0cSGreg Roach</style>
93efbc3a0cSGreg Roach<?php View::endpush() ?>
94efbc3a0cSGreg Roach
9539b853a7SGreg Roach<?php View::push('javascript') ?>
96dd6b2bfcSGreg Roach<script>
97efbc3a0cSGreg Roach    new Sortable(document.getElementById("main-blocks"), {
98efbc3a0cSGreg Roach        group:     "blocks",
99efbc3a0cSGreg Roach        handle:    ".wt-icon-drag-handle",
100efbc3a0cSGreg Roach        animation: 150,
101efbc3a0cSGreg Roach        pull:      "clone",
102efbc3a0cSGreg Roach    });
103dd6b2bfcSGreg Roach
104efbc3a0cSGreg Roach    new Sortable(document.getElementById("side-blocks"), {
105efbc3a0cSGreg Roach        group:     "blocks",
106efbc3a0cSGreg Roach        handle:    ".wt-icon-drag-handle",
107efbc3a0cSGreg Roach        animation: 150,
108efbc3a0cSGreg Roach        pull:      "clone",
109efbc3a0cSGreg Roach    });
110dd6b2bfcSGreg Roach
111efbc3a0cSGreg Roach    new Sortable(document.getElementById("available-blocks"), {
112efbc3a0cSGreg Roach        group:     {
113efbc3a0cSGreg Roach            name: "blocks",
114efbc3a0cSGreg Roach            pull: "clone",
115efbc3a0cSGreg Roach            put:  false,
116efbc3a0cSGreg Roach        },
117efbc3a0cSGreg Roach        handle:    ".wt-icon-drag-handle",
118efbc3a0cSGreg Roach        animation: 150,
119efbc3a0cSGreg Roach        sort:      false,
120efbc3a0cSGreg Roach    });
121dd6b2bfcSGreg Roach
12269e24ab6SGreg Roach    document.getElementById('current-blocks').addEventListener('click', function (event) {
1238b993e2fSGreg Roach      if (event.target.closest('.wt-icon-delete')) {
12469e24ab6SGreg Roach        const wtBlock = event.target.closest('.wt-block');
12569e24ab6SGreg Roach        wtBlock.parentNode.removeChild(wtBlock);
12669e24ab6SGreg Roach      }
127efbc3a0cSGreg Roach    });
128dd6b2bfcSGreg Roach
12969e24ab6SGreg Roach    document.getElementById('edit-blocks').addEventListener('submit', function (event) {
13069e24ab6SGreg Roach      document.querySelectorAll('#main-blocks input').forEach((element) => { element.setAttribute('name', 'main[]'); })
13169e24ab6SGreg Roach      document.querySelectorAll('#side-blocks input').forEach((element) => { element.setAttribute('name', 'side[]'); })
132efbc3a0cSGreg Roach    });
133dd6b2bfcSGreg Roach</script>
13439b853a7SGreg Roach<?php View::endpush() ?>
135