xref: /webtrees/resources/views/search-trees.phtml (revision 928e8f1ab8bf8a4eae9e8ec7a464d6b65ee174d5)
1<?php
2
3declare(strict_types=1);
4
5use Fisharebest\Webtrees\I18N;
6use Fisharebest\Webtrees\Tree;
7use Illuminate\Support\Collection;
8
9/**
10 * @var Collection<int,Tree> $all_trees
11 * @var Collection<int,Tree> $search_trees
12 */
13
14?>
15
16<?php if ($all_trees->count() > 1) : ?>
17    <fieldset class="row">
18        <div class="col-sm-3 col-form-label wt-page-options-label">
19            <?= I18N::translate('Family trees') ?>
20        </div>
21        <div class="col-sm-9 wt-page-options-value pt-2">
22            <div id="search-trees">
23                <?php if ($all_trees->count() > 3) : ?>
24                    <div class="d-flex">
25                        <?php if ($all_trees->count() > $search_trees->count()) : ?>
26                            <div class="me-2">
27                                <button type="button" data-bs-toggle="collapse" class="btn btn-secondary btn-sm" data-bs-target="#more-trees,#select-all" aria-expanded="false" aria-controls="more-trees">
28                                    <?= view('icons/expand') ?>
29                                    <?= view('icons/collapse') ?>
30                                </button>
31                            </div>
32                        <?php endif ?>
33                        <div>
34                            <?php foreach ($search_trees as $n => $tree) : ?>
35                                <?= view('components/checkbox', ['name' => 'search_trees[]', 'id' => 'chkbx-' . $n, 'checked' => $search_trees->containsStrict($tree), 'value' => e($tree->name()), 'label' => e($tree->title())]) ?>
36                            <?php endforeach ?>
37                            <div id="more-trees" class="<?= $all_trees->count() > $search_trees->count() ? 'collapse' : '' ?>">
38                                <?php foreach ($all_trees as $n => $tree) : ?>
39                                    <?php if (!$search_trees->containsStrict($tree)) : ?>
40                                        <?= view('components/checkbox', ['name' => 'search_trees[]', 'id' => 'chkbx-' . $n, 'checked' => $search_trees->containsStrict($tree), 'value' => e($tree->name()), 'label' => e($tree->title())]) ?>
41                                    <?php endif ?>
42                                <?php endforeach ?>
43                            </div>
44                        </div>
45                        <div class="ms-auto <?= $all_trees->count() > $search_trees->count() ? 'collapse' : '' ?>" id="select-all">
46                            <button type="button" class="btn btn-sm btn-secondary mx-1" onclick="document.querySelectorAll('#search-trees [type=checkbox]').forEach((element) => {element.checked=true;});">
47                                <?= /* I18N: select all (of a list of options) */ I18N::translate('select all') ?>
48                            </button>
49                            <button type="button" class="btn btn-sm btn-secondary mx-1" onclick="document.querySelectorAll('#search-trees [type=checkbox]').forEach((element) => {element.checked=false;});">
50                                <?= /* I18N: select none (of a list of options) */  I18N::translate('select none') ?>
51                            </button>
52                            <?php if ($all_trees->count() > 10) : ?>
53                                <button type="button"  class="btn btn-sm btn-secondary mx-1" onclick="document.querySelectorAll('#search-trees [type=checkbox]').forEach((element) => {element.checked=!element.checked;});">
54                                    <?= /* I18N: reverse the selection (of a list of options) */ I18N::translate('invert selection') ?>
55                                </button>
56                            <?php endif ?>
57                        </div>
58                </div>
59                <?php else : ?>
60                    <?php foreach ($all_trees as $n => $tree) : ?>
61                        <?= view('components/checkbox-inline', ['name' => 'search_trees[]', 'id' => 'chkbx-' . $n, 'checked' => $search_trees->containsStrict($tree), 'value' => e($tree->name()), 'label' => e($tree->title())]) ?>
62                    <?php endforeach ?>
63                <?php endif ?>
64            </div>
65        </div>
66    </fieldset>
67<?php endif ?>
68