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