xref: /webtrees/resources/views/edit/reorder-children.phtml (revision 28d026ad36e53e5af3ffb5b483ee815e04b18ecf)
1<?php
2
3declare(strict_types=1);
4
5use Fisharebest\Webtrees\Fact;
6use Fisharebest\Webtrees\Family;
7use Fisharebest\Webtrees\Gedcom;
8use Fisharebest\Webtrees\Http\RequestHandlers\ReorderChildrenAction;
9use Fisharebest\Webtrees\I18N;
10use Fisharebest\Webtrees\Individual;
11use Fisharebest\Webtrees\View;
12
13/**
14 * @var Family $family
15 * @var string $title
16 * @var string $url
17 */
18
19?>
20
21<h2 class="wt-page-title"><?= $title ?></h2>
22
23<form method="post" action="<?= e(route(ReorderChildrenAction::class, ['tree' => $family->tree()->name(), 'xref' => $family->xref()])) ?>" class="wt-page-content">
24    <input type="hidden" name="url" value="<?= e($url) ?>">
25    <div class="wt-sortable-list">
26        <?php foreach ($family->facts(['CHIL'])->filter(static fn (Fact $fact): bool => $fact->target() instanceof Individual) as $fact) : ?>
27            <div class="card my-2 wt-sortable-item" data-wt-sort-by-date="<?= $fact->target()->getBirthDate()->julianDay() ?>">
28                <input type="hidden" name="order[]" value="<?= $fact->id() ?>">
29                <div class="card-header">
30                    <?= view('edit/reorder-card-header', ['title' => $fact->target()->fullName()]) ?>
31                </div>
32
33                <div class="card-body">
34                    <?= $fact->target()->formatFirstMajorFact(Gedcom::BIRTH_EVENTS, 2) ?>
35                    <?= $fact->target()->formatFirstMajorFact(Gedcom::DEATH_EVENTS, 2) ?>
36                </div>
37            </div>
38        <?php endforeach ?>
39    </div>
40
41    <p>
42        <button class="btn btn-primary" type="submit">
43            <?= view('icons/save') ?>
44            <?= /* I18N: A button label. */ I18N::translate('save') ?>
45        </button>
46
47        <button class="btn btn-secondary" id="btn-default-order" type="button">
48            <?= view('icons/sort') ?>
49            <?= /* I18N: A button label. */ I18N::translate('sort by date of birth') ?>
50        </button>
51
52        <a class="btn btn-secondary" href="<?= e($url) ?>">
53            <?= view('icons/cancel') ?>
54            <?= /* I18N: A button label. */ I18N::translate('cancel') ?>
55        </a>
56    </p>
57
58    <?= csrf_field() ?>
59</form>
60
61<?php View::push('javascript') ?>
62<script>
63    new Sortable(document.querySelector(".wt-sortable-list"), {
64        handle: ".card-header",
65    });
66
67    $("#btn-default-order").on("click", function () {
68        $(".wt-sortable-list .wt-sortable-item").sort(function (x, y) {
69            return Math.sign(x.dataset.wtSortByDate - y.dataset.wtSortByDate);
70        }).appendTo(".wt-sortable-list");
71    });
72</script>
73<?php View::endpush() ?>
74