xref: /webtrees/resources/views/edit/reorder-families.phtml (revision a87526dfb486ce67715abefc5214a71160b2ab4a)
11afbbc50SGreg Roach<?php
21afbbc50SGreg Roach
3*10e06497SGreg Roachdeclare(strict_types=1);
4*10e06497SGreg Roach
5c2ed51d1SGreg Roachuse Fisharebest\Webtrees\Fact;
61afbbc50SGreg Roachuse Fisharebest\Webtrees\Gedcom;
71afbbc50SGreg Roachuse Fisharebest\Webtrees\Http\RequestHandlers\ReorderFamiliesAction;
81afbbc50SGreg Roachuse Fisharebest\Webtrees\I18N;
9c2ed51d1SGreg Roachuse Fisharebest\Webtrees\Individual;
10c2ed51d1SGreg Roachuse Fisharebest\Webtrees\Registry;
11c2ed51d1SGreg Roachuse Fisharebest\Webtrees\Tree;
121afbbc50SGreg Roachuse Fisharebest\Webtrees\View;
13c2ed51d1SGreg Roachuse Illuminate\Support\Collection;
14c2ed51d1SGreg Roach
15c2ed51d1SGreg Roach/**
1636779af1SGreg Roach * @var Collection<int,Fact> $famc_facts
1736779af1SGreg Roach * @var Collection<int,Fact> $fams_facts
18c2ed51d1SGreg Roach * @var Individual           $individual
19c2ed51d1SGreg Roach * @var string               $title
20c2ed51d1SGreg Roach * @var Tree                 $tree
21c2ed51d1SGreg Roach */
221afbbc50SGreg Roach
231afbbc50SGreg Roach?>
241afbbc50SGreg Roach
251afbbc50SGreg Roach<h2 class="wt-page-title"><?= $title ?></h2>
261afbbc50SGreg Roach
271afbbc50SGreg Roach<form method="post" action="<?= e(route(ReorderFamiliesAction::class, ['tree' => $tree->name(), 'xref' => $individual->xref()])) ?>" class="wt-page-content">
281afbbc50SGreg Roach    <?php if ($fams_facts->count() < 2) : ?>
291afbbc50SGreg Roach        <?php foreach ($fams_facts as $fact) : ?>
301afbbc50SGreg Roach            <input type="hidden" name="order[]" value="<?= e($fact->id()) ?>">
311afbbc50SGreg Roach        <?php endforeach ?>
321afbbc50SGreg Roach    <?php else : ?>
331afbbc50SGreg Roach        <h3><?= I18N::translate('Spouses') ?></h3>
341afbbc50SGreg Roach
351afbbc50SGreg Roach        <p>
361afbbc50SGreg Roach            <?= I18N::translate('When an individual has more than one spouse, you should sort the families in date order.') ?>
371afbbc50SGreg Roach        </p>
381afbbc50SGreg Roach
391afbbc50SGreg Roach        <p>
401afbbc50SGreg Roach            <button class="btn btn-secondary" id="btn-default-order" type="button">
411afbbc50SGreg Roach                <?= view('icons/sort') ?>
421afbbc50SGreg Roach                <?= /* I18N: A button label. */ I18N::translate('sort by date of marriage') ?>
431afbbc50SGreg Roach            </button>
441afbbc50SGreg Roach        </p>
451afbbc50SGreg Roach
46cfb92551SGreg Roach        <div class="wt-sortable-list wt-sortable-list-fams">
471afbbc50SGreg Roach            <?php foreach ($fams_facts as $fact) : ?>
48d4786c66SGreg Roach                <div class="card mb-2 wt-sortable-item" data-wt-sort-by-date="<?= $fact->target()->getMarriageDate()->julianDay() ?>">
491afbbc50SGreg Roach                    <input type="hidden" name="order[]" value="<?= $fact->id() ?>">
501afbbc50SGreg Roach                    <div class="card-header">
5192044e0dSGreg Roach                        <?= view('edit/reorder-card-header', ['title' => $fact->target()->fullName()]) ?>
521afbbc50SGreg Roach                    </div>
5392044e0dSGreg Roach
541afbbc50SGreg Roach                    <div class="card-body">
551afbbc50SGreg Roach                        <?= $fact->target()->formatFirstMajorFact(Gedcom::MARRIAGE_EVENTS, 2) ?>
561afbbc50SGreg Roach                        <?= $fact->target()->formatFirstMajorFact(Gedcom::DIVORCE_EVENTS, 2) ?>
571afbbc50SGreg Roach                    </div>
581afbbc50SGreg Roach                </div>
591afbbc50SGreg Roach            <?php endforeach ?>
601afbbc50SGreg Roach        </div>
611afbbc50SGreg Roach    <?php endif ?>
621afbbc50SGreg Roach
631afbbc50SGreg Roach    <?php if ($famc_facts->count() < 2) : ?>
641afbbc50SGreg Roach            <?php foreach ($famc_facts as $fact) : ?>
651afbbc50SGreg Roach                <input type="hidden" name="order[]" value="<?= e($fact->id()) ?>">
661afbbc50SGreg Roach            <?php endforeach ?>
671afbbc50SGreg Roach    <?php else : ?>
681afbbc50SGreg Roach        <?php if ($fams_facts->count() >= 2) : ?>
691afbbc50SGreg Roach        <hr>
701afbbc50SGreg Roach        <?php endif ?>
711afbbc50SGreg Roach
721afbbc50SGreg Roach        <h3><?= I18N::translate('Parents') ?></h3>
731afbbc50SGreg Roach
741afbbc50SGreg Roach        <p>
751afbbc50SGreg Roach            <?= I18N::translate('An individual can have more than one set of parents. For example, birth and adopted.') ?>
761afbbc50SGreg Roach            <br>
771afbbc50SGreg Roach            <?= I18N::translate('The first family in the list will be used in charts, lists, reports, etc.') ?>
781afbbc50SGreg Roach        </p>
791afbbc50SGreg Roach
80cfb92551SGreg Roach        <div class="wt-sortable-list wt-sortable-list-famc">
811afbbc50SGreg Roach            <?php foreach ($famc_facts as $fact) : ?>
8292044e0dSGreg Roach                <div class="card my-2 wt-sortable-item" data-sortbydate="<?= $fact->target()->getMarriageDate()->julianDay() ?>">
831afbbc50SGreg Roach                    <input type="hidden" name="order[]" value="<?= $fact->id() ?>">
841afbbc50SGreg Roach                    <div class="card-header">
85c2ed51d1SGreg Roach                        <?= view('edit/reorder-card-header', ['title' => $fact->target()->fullName() . ($fact->attribute('PEDI') === '' ? '' : ' — ' . Registry::elementFactory()->make('INDI:FAMC:PEDI')->value($fact->attribute('PEDI'), $tree))]) ?>
861afbbc50SGreg Roach                    </div>
871afbbc50SGreg Roach                    <div class="card-body">
881afbbc50SGreg Roach                        <?= $fact->target()->formatFirstMajorFact(Gedcom::MARRIAGE_EVENTS, 2) ?>
891afbbc50SGreg Roach                        <?= $fact->target()->formatFirstMajorFact(Gedcom::DIVORCE_EVENTS, 2) ?>
901afbbc50SGreg Roach                    </div>
911afbbc50SGreg Roach                </div>
921afbbc50SGreg Roach            <?php endforeach ?>
931afbbc50SGreg Roach        </div>
941afbbc50SGreg Roach    <?php endif ?>
951afbbc50SGreg Roach
961afbbc50SGreg Roach    <p>
971afbbc50SGreg Roach        <button class="btn btn-primary" type="submit">
981afbbc50SGreg Roach            <?= view('icons/save') ?>
991afbbc50SGreg Roach            <?= /* I18N: A button label. */ I18N::translate('save') ?>
1001afbbc50SGreg Roach        </button>
1011afbbc50SGreg Roach
1021afbbc50SGreg Roach        <a class="btn btn-secondary" href="<?= e($individual->url()) ?>">
1031afbbc50SGreg Roach            <?= view('icons/cancel') ?>
1041afbbc50SGreg Roach            <?= /* I18N: A button label. */ I18N::translate('cancel') ?>
1051afbbc50SGreg Roach        </a>
1061afbbc50SGreg Roach    </p>
10781443e3cSGreg Roach
10881443e3cSGreg Roach    <?= csrf_field() ?>
1091afbbc50SGreg Roach</form>
1101afbbc50SGreg Roach
1111afbbc50SGreg Roach<?php View::push('javascript') ?>
1121afbbc50SGreg Roach<script>
1136f100147SGreg Roach    const famc_list = document.querySelector(".wt-sortable-list-famc");
1146f100147SGreg Roach    const fams_list = document.querySelector(".wt-sortable-list-fams");
1156f100147SGreg Roach
1166f100147SGreg Roach    if (famc_list !== null) {
1176f100147SGreg Roach        new Sortable(famc_list, {
11892044e0dSGreg Roach            handle: ".card-header",
1191afbbc50SGreg Roach        });
1206f100147SGreg Roach    }
1211afbbc50SGreg Roach
1226f100147SGreg Roach    if (fams_list !== null) {
1236f100147SGreg Roach        new Sortable(fams_list, {
12492044e0dSGreg Roach            handle: ".card-header",
1251afbbc50SGreg Roach        });
1261afbbc50SGreg Roach
1271afbbc50SGreg Roach        $("#btn-default-order").on("click", function () {
1281afbbc50SGreg Roach            $(".wt-sortable-list-fams .wt-sortable-item").sort(function (x, y) {
129d4786c66SGreg Roach                return Math.sign(x.dataset.wtSortByDate - y.dataset.wtSortByDate);
1301afbbc50SGreg Roach            }).appendTo(".wt-sortable-list-fams");
1311afbbc50SGreg Roach        });
1326f100147SGreg Roach    }
1331afbbc50SGreg Roach</script>
1341afbbc50SGreg Roach<?php View::endpush() ?>
135