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