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