xref: /webtrees/resources/views/edit/reorder-children.phtml (revision 83615acfc72bfb50678c6481f2a00bab04041a87)
18d0ebef0SGreg Roach<?php use Fisharebest\Webtrees\Gedcom; ?>
2dd6b2bfcSGreg Roach<?php use Fisharebest\Webtrees\I18N; ?>
3dd6b2bfcSGreg Roach<?php use Fisharebest\Webtrees\View; ?>
4dd6b2bfcSGreg Roach
5dd6b2bfcSGreg Roach<h2 class="wt-page-title"><?= $title ?></h2>
6dd6b2bfcSGreg Roach
7*83615acfSGreg Roach<form method="post" action="<?= e(route('reorder-children-action')) ?>" class="wt-page-content">
8dd6b2bfcSGreg Roach    <?= csrf_field() ?>
9*83615acfSGreg Roach    <input type="hidden" name="ged" value="<?= e($family->tree()->name()) ?>">
10*83615acfSGreg Roach    <input type="hidden" name="xref" value="<?= e($family->xref()) ?>">
11*83615acfSGreg Roach
12dd6b2bfcSGreg Roach    <div class="wt-sortable-list">
138d0ebef0SGreg Roach        <?php foreach ($family->facts(['CHIL']) as $fact) : ?>
14dc124885SGreg Roach            <div class="card mb-2 wt-sortable-item" data-sortbydate="<?= $fact->target()->getBirthDate()->julianDay() ?>">
15905ab80aSGreg Roach                <input type="hidden" name="order[]" value="<?= $fact->id() ?>">
16dd6b2bfcSGreg Roach                <h3 class="card-header">
176a83cfe8SGreg Roach                    <?= view('icons/drag-handle') ?>
1839ca88baSGreg Roach                    <?= $fact->target()->fullName() ?>
19dd6b2bfcSGreg Roach                </h3>
20dd6b2bfcSGreg Roach                <div class="card-body">
218d0ebef0SGreg Roach                    <?= $fact->target()->formatFirstMajorFact(Gedcom::BIRTH_EVENTS, 2) ?>
228d0ebef0SGreg Roach                    <?= $fact->target()->formatFirstMajorFact(Gedcom::DEATH_EVENTS, 2) ?>
23dd6b2bfcSGreg Roach                </div>
24dd6b2bfcSGreg Roach            </div>
25dd6b2bfcSGreg Roach        <?php endforeach ?>
26dd6b2bfcSGreg Roach    </div>
27dd6b2bfcSGreg Roach
28dd6b2bfcSGreg Roach    <p>
29dd6b2bfcSGreg Roach        <button class="btn btn-primary" type="submit">
30d993d560SGreg Roach            <?= view('icons/save') ?>
31dd6b2bfcSGreg Roach            <?= /* I18N: A button label. */ I18N::translate('save') ?>
32dd6b2bfcSGreg Roach        </button>
33dd6b2bfcSGreg Roach
34dd6b2bfcSGreg Roach        <button class="btn btn-secondary" id="btn-default-order" type="button">
35d993d560SGreg Roach            <?= view('icons/sort') ?>
36dd6b2bfcSGreg Roach            <?= /* I18N: A button label. */ I18N::translate('sort by date of birth') ?>
37dd6b2bfcSGreg Roach        </button>
38dd6b2bfcSGreg Roach
39dd6b2bfcSGreg Roach        <a class="btn btn-secondary" href="<?= e($family->url()) ?>">
40d993d560SGreg Roach            <?= view('icons/cancel') ?>
41dd6b2bfcSGreg Roach            <?= /* I18N: A button label. */ I18N::translate('cancel') ?>
42dd6b2bfcSGreg Roach        </a>
43dd6b2bfcSGreg Roach    </p>
44dd6b2bfcSGreg Roach</form>
45dd6b2bfcSGreg Roach
46dd6b2bfcSGreg Roach<?php View::push('javascript') ?>
47dd6b2bfcSGreg Roach<script>
48dd6b2bfcSGreg Roach  new Sortable(document.querySelector(".wt-sortable-list"), {});
49dd6b2bfcSGreg Roach
50dd6b2bfcSGreg Roach  $("#btn-default-order").on("click", function() {
51dd6b2bfcSGreg Roach    $(".wt-sortable-list .wt-sortable-item").sort(function(x, y) {
52dd6b2bfcSGreg Roach      return Math.sign(x.dataset.sortbydate - y.dataset.sortbydate);
53dd6b2bfcSGreg Roach    }).appendTo(".wt-sortable-list");
54dd6b2bfcSGreg Roach  });
55dd6b2bfcSGreg Roach</script>
56dd6b2bfcSGreg Roach<?php View::endpush() ?>
57