xref: /webtrees/resources/views/edit/reorder-children.phtml (revision 92044e0d3ee7691ad1433867c218bd41de68960e)
15229eadeSGreg Roach<?php
25229eadeSGreg Roach
35229eadeSGreg Roachuse Fisharebest\Webtrees\Gedcom;
45229eadeSGreg Roachuse Fisharebest\Webtrees\Http\RequestHandlers\ReorderChildrenAction;
55229eadeSGreg Roachuse Fisharebest\Webtrees\I18N;
65229eadeSGreg Roachuse Fisharebest\Webtrees\View;
75229eadeSGreg Roach
85229eadeSGreg Roach?>
9dd6b2bfcSGreg Roach
10dd6b2bfcSGreg Roach<h2 class="wt-page-title"><?= $title ?></h2>
11dd6b2bfcSGreg Roach
125229eadeSGreg Roach<form method="post" action="<?= e(route(ReorderChildrenAction::class, ['tree' => $tree->name(), 'xref' => $family->xref()])) ?>" class="wt-page-content">
13dd6b2bfcSGreg Roach    <?= csrf_field() ?>
1483615acfSGreg Roach
15dd6b2bfcSGreg Roach    <div class="wt-sortable-list">
168d0ebef0SGreg Roach        <?php foreach ($family->facts(['CHIL']) as $fact) : ?>
17*92044e0dSGreg Roach            <div class="card my-2 wt-sortable-item" data-sortbydate="<?= $fact->target()->getBirthDate()->julianDay() ?>">
18905ab80aSGreg Roach                <input type="hidden" name="order[]" value="<?= $fact->id() ?>">
19aabcb63cSGreg Roach                <div class="card-header">
20*92044e0dSGreg Roach                    <?= view('edit/reorder-card-header', ['title' => $fact->target()->fullName()]) ?>
21aabcb63cSGreg Roach                </div>
22*92044e0dSGreg Roach
23dd6b2bfcSGreg Roach                <div class="card-body">
248d0ebef0SGreg Roach                    <?= $fact->target()->formatFirstMajorFact(Gedcom::BIRTH_EVENTS, 2) ?>
258d0ebef0SGreg Roach                    <?= $fact->target()->formatFirstMajorFact(Gedcom::DEATH_EVENTS, 2) ?>
26dd6b2bfcSGreg Roach                </div>
27dd6b2bfcSGreg Roach            </div>
28dd6b2bfcSGreg Roach        <?php endforeach ?>
29dd6b2bfcSGreg Roach    </div>
30dd6b2bfcSGreg Roach
31dd6b2bfcSGreg Roach    <p>
32dd6b2bfcSGreg Roach        <button class="btn btn-primary" type="submit">
33d993d560SGreg Roach            <?= view('icons/save') ?>
34dd6b2bfcSGreg Roach            <?= /* I18N: A button label. */ I18N::translate('save') ?>
35dd6b2bfcSGreg Roach        </button>
36dd6b2bfcSGreg Roach
37dd6b2bfcSGreg Roach        <button class="btn btn-secondary" id="btn-default-order" type="button">
38d993d560SGreg Roach            <?= view('icons/sort') ?>
39dd6b2bfcSGreg Roach            <?= /* I18N: A button label. */ I18N::translate('sort by date of birth') ?>
40dd6b2bfcSGreg Roach        </button>
41dd6b2bfcSGreg Roach
42dd6b2bfcSGreg Roach        <a class="btn btn-secondary" href="<?= e($family->url()) ?>">
43d993d560SGreg Roach            <?= view('icons/cancel') ?>
44dd6b2bfcSGreg Roach            <?= /* I18N: A button label. */ I18N::translate('cancel') ?>
45dd6b2bfcSGreg Roach        </a>
46dd6b2bfcSGreg Roach    </p>
47dd6b2bfcSGreg Roach</form>
48dd6b2bfcSGreg Roach
49dd6b2bfcSGreg Roach<?php View::push('javascript') ?>
50dd6b2bfcSGreg Roach<script>
51aabcb63cSGreg Roach    new Sortable(document.querySelector(".wt-sortable-list"), {
52*92044e0dSGreg Roach        handle: ".card-header",
53aabcb63cSGreg Roach    });
54dd6b2bfcSGreg Roach
55dd6b2bfcSGreg Roach    $("#btn-default-order").on("click", function () {
56dd6b2bfcSGreg Roach        $(".wt-sortable-list .wt-sortable-item").sort(function (x, y) {
57dd6b2bfcSGreg Roach            return Math.sign(x.dataset.sortbydate - y.dataset.sortbydate);
58dd6b2bfcSGreg Roach        }).appendTo(".wt-sortable-list");
59dd6b2bfcSGreg Roach    });
60dd6b2bfcSGreg Roach</script>
61dd6b2bfcSGreg Roach<?php View::endpush() ?>
62