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