xref: /webtrees/resources/views/edit/reorder-children.phtml (revision 504055284fcef1c6d50f172e3cb3fa077cc9c7a8)
15229eadeSGreg Roach<?php
25229eadeSGreg Roach
310e06497SGreg Roachdeclare(strict_types=1);
410e06497SGreg Roach
571cd890dSGreg Roachuse Fisharebest\Webtrees\Fact;
67c2c99faSGreg Roachuse Fisharebest\Webtrees\Family;
75229eadeSGreg Roachuse Fisharebest\Webtrees\Gedcom;
85229eadeSGreg Roachuse Fisharebest\Webtrees\Http\RequestHandlers\ReorderChildrenAction;
95229eadeSGreg Roachuse Fisharebest\Webtrees\I18N;
1071cd890dSGreg Roachuse Fisharebest\Webtrees\Individual;
115229eadeSGreg Roachuse Fisharebest\Webtrees\View;
125229eadeSGreg Roach
137c2c99faSGreg Roach/**
147c2c99faSGreg Roach * @var Family $family
157c2c99faSGreg Roach * @var string $title
16*50405528SGreg Roach * @var string $url
177c2c99faSGreg Roach */
187c2c99faSGreg Roach
195229eadeSGreg Roach?>
20dd6b2bfcSGreg Roach
21dd6b2bfcSGreg Roach<h2 class="wt-page-title"><?= $title ?></h2>
22dd6b2bfcSGreg Roach
237c2c99faSGreg Roach<form method="post" action="<?= e(route(ReorderChildrenAction::class, ['tree' => $family->tree()->name(), 'xref' => $family->xref()])) ?>" class="wt-page-content">
24*50405528SGreg Roach    <input type="hidden" name="url" value="<?= e($url) ?>">
25dd6b2bfcSGreg Roach    <div class="wt-sortable-list">
2671cd890dSGreg Roach        <?php foreach ($family->facts(['CHIL'])->filter(static fn (Fact $fact): bool => $fact->target() instanceof Individual) as $fact) : ?>
27d4786c66SGreg Roach            <div class="card my-2 wt-sortable-item" data-wt-sort-by-date="<?= $fact->target()->getBirthDate()->julianDay() ?>">
28905ab80aSGreg Roach                <input type="hidden" name="order[]" value="<?= $fact->id() ?>">
29aabcb63cSGreg Roach                <div class="card-header">
3092044e0dSGreg Roach                    <?= view('edit/reorder-card-header', ['title' => $fact->target()->fullName()]) ?>
31aabcb63cSGreg Roach                </div>
3292044e0dSGreg Roach
33dd6b2bfcSGreg Roach                <div class="card-body">
348d0ebef0SGreg Roach                    <?= $fact->target()->formatFirstMajorFact(Gedcom::BIRTH_EVENTS, 2) ?>
358d0ebef0SGreg Roach                    <?= $fact->target()->formatFirstMajorFact(Gedcom::DEATH_EVENTS, 2) ?>
36dd6b2bfcSGreg Roach                </div>
37dd6b2bfcSGreg Roach            </div>
38dd6b2bfcSGreg Roach        <?php endforeach ?>
39dd6b2bfcSGreg Roach    </div>
40dd6b2bfcSGreg Roach
41dd6b2bfcSGreg Roach    <p>
42dd6b2bfcSGreg Roach        <button class="btn btn-primary" type="submit">
43d993d560SGreg Roach            <?= view('icons/save') ?>
44dd6b2bfcSGreg Roach            <?= /* I18N: A button label. */ I18N::translate('save') ?>
45dd6b2bfcSGreg Roach        </button>
46dd6b2bfcSGreg Roach
47dd6b2bfcSGreg Roach        <button class="btn btn-secondary" id="btn-default-order" type="button">
48d993d560SGreg Roach            <?= view('icons/sort') ?>
49dd6b2bfcSGreg Roach            <?= /* I18N: A button label. */ I18N::translate('sort by date of birth') ?>
50dd6b2bfcSGreg Roach        </button>
51dd6b2bfcSGreg Roach
52*50405528SGreg Roach        <a class="btn btn-secondary" href="<?= e($url) ?>">
53d993d560SGreg Roach            <?= view('icons/cancel') ?>
54dd6b2bfcSGreg Roach            <?= /* I18N: A button label. */ I18N::translate('cancel') ?>
55dd6b2bfcSGreg Roach        </a>
56dd6b2bfcSGreg Roach    </p>
5781443e3cSGreg Roach
5881443e3cSGreg Roach    <?= csrf_field() ?>
59dd6b2bfcSGreg Roach</form>
60dd6b2bfcSGreg Roach
61dd6b2bfcSGreg Roach<?php View::push('javascript') ?>
62dd6b2bfcSGreg Roach<script>
63aabcb63cSGreg Roach    new Sortable(document.querySelector(".wt-sortable-list"), {
6492044e0dSGreg Roach        handle: ".card-header",
65aabcb63cSGreg Roach    });
66dd6b2bfcSGreg Roach
67dd6b2bfcSGreg Roach    $("#btn-default-order").on("click", function () {
68dd6b2bfcSGreg Roach        $(".wt-sortable-list .wt-sortable-item").sort(function (x, y) {
69d4786c66SGreg Roach            return Math.sign(x.dataset.wtSortByDate - y.dataset.wtSortByDate);
70dd6b2bfcSGreg Roach        }).appendTo(".wt-sortable-list");
71dd6b2bfcSGreg Roach    });
72dd6b2bfcSGreg Roach</script>
73dd6b2bfcSGreg Roach<?php View::endpush() ?>
74