xref: /webtrees/resources/views/edit/reorder-families.phtml (revision b7e8616f5f3bd6f035d5d40dd804283727b5c140)
1<?php
2
3use Fisharebest\Webtrees\Fact;
4use Fisharebest\Webtrees\Gedcom;
5use Fisharebest\Webtrees\Http\RequestHandlers\ReorderFamiliesAction;
6use Fisharebest\Webtrees\I18N;
7use Fisharebest\Webtrees\Individual;
8use Fisharebest\Webtrees\Registry;
9use Fisharebest\Webtrees\Tree;
10use Fisharebest\Webtrees\View;
11use Illuminate\Support\Collection;
12
13/**
14 * @var Collection<Fact> $famc_facts
15 * @var Collection<Fact> $fams_facts
16 * @var Individual       $individual
17 * @var string           $title
18 * @var Tree             $tree
19 */
20
21?>
22
23<h2 class="wt-page-title"><?= $title ?></h2>
24
25<form method="post" action="<?= e(route(ReorderFamiliesAction::class, ['tree' => $tree->name(), 'xref' => $individual->xref()])) ?>" class="wt-page-content">
26    <?= csrf_field() ?>
27
28    <?php if ($fams_facts->count() < 2) : ?>
29        <?php foreach ($fams_facts as $fact) : ?>
30            <input type="hidden" name="order[]" value="<?= e($fact->id()) ?>">
31        <?php endforeach ?>
32    <?php else : ?>
33        <h3><?= I18N::translate('Spouses') ?></h3>
34
35        <p>
36            <?= I18N::translate('When an individual has more than one spouse, you should sort the families in date order.') ?>
37        </p>
38
39        <p>
40            <button class="btn btn-secondary" id="btn-default-order" type="button">
41                <?= view('icons/sort') ?>
42                <?= /* I18N: A button label. */ I18N::translate('sort by date of marriage') ?>
43            </button>
44        </p>
45
46        <div class="wt-sortable-list wt-sortable-list-fams">
47            <?php foreach ($fams_facts as $fact) : ?>
48                <div class="card mb-2 wt-sortable-item" data-wt-sort-by-date="<?= $fact->target()->getMarriageDate()->julianDay() ?>">
49                    <input type="hidden" name="order[]" value="<?= $fact->id() ?>">
50                    <div class="card-header">
51                        <?= view('edit/reorder-card-header', ['title' => $fact->target()->fullName()]) ?>
52                    </div>
53
54                    <div class="card-body">
55                        <?= $fact->target()->formatFirstMajorFact(Gedcom::MARRIAGE_EVENTS, 2) ?>
56                        <?= $fact->target()->formatFirstMajorFact(Gedcom::DIVORCE_EVENTS, 2) ?>
57                    </div>
58                </div>
59            <?php endforeach ?>
60        </div>
61    <?php endif ?>
62
63    <?php if ($famc_facts->count() < 2) : ?>
64            <?php foreach ($famc_facts as $fact) : ?>
65                <input type="hidden" name="order[]" value="<?= e($fact->id()) ?>">
66            <?php endforeach ?>
67    <?php else : ?>
68        <?php if ($fams_facts->count() >= 2) : ?>
69        <hr>
70        <?php endif ?>
71
72        <h3><?= I18N::translate('Parents') ?></h3>
73
74        <p>
75            <?= I18N::translate('An individual can have more than one set of parents.  For example, birth and adopted.') ?>
76            <br>
77            <?= I18N::translate('The first family in the list will be used in charts, lists, reports, etc.') ?>
78        </p>
79
80        <div class="wt-sortable-list wt-sortable-list-famc">
81            <?php foreach ($famc_facts as $fact) : ?>
82                <div class="card my-2 wt-sortable-item" data-sortbydate="<?= $fact->target()->getMarriageDate()->julianDay() ?>">
83                    <input type="hidden" name="order[]" value="<?= $fact->id() ?>">
84                    <div class="card-header">
85                        <?= view('edit/reorder-card-header', ['title' => $fact->target()->fullName() . ($fact->attribute('PEDI') === '' ? '' : ' — ' . Registry::elementFactory()->make('INDI:FAMC:PEDI')->value($fact->attribute('PEDI'), $tree))]) ?>
86                    </div>
87                    <div class="card-body">
88                        <?= $fact->target()->formatFirstMajorFact(Gedcom::MARRIAGE_EVENTS, 2) ?>
89                        <?= $fact->target()->formatFirstMajorFact(Gedcom::DIVORCE_EVENTS, 2) ?>
90                    </div>
91                </div>
92            <?php endforeach ?>
93        </div>
94    <?php endif ?>
95
96    <p>
97        <button class="btn btn-primary" type="submit">
98            <?= view('icons/save') ?>
99            <?= /* I18N: A button label. */ I18N::translate('save') ?>
100        </button>
101
102        <a class="btn btn-secondary" href="<?= e($individual->url()) ?>">
103            <?= view('icons/cancel') ?>
104            <?= /* I18N: A button label. */ I18N::translate('cancel') ?>
105        </a>
106    </p>
107</form>
108
109<?php View::push('javascript') ?>
110<script>
111    const famc_list = document.querySelector(".wt-sortable-list-famc");
112    const fams_list = document.querySelector(".wt-sortable-list-fams");
113
114    if (famc_list !== null) {
115        new Sortable(famc_list, {
116            handle: ".card-header",
117        });
118    }
119
120    if (fams_list !== null) {
121        new Sortable(fams_list, {
122            handle: ".card-header",
123        });
124
125        $("#btn-default-order").on("click", function () {
126            $(".wt-sortable-list-fams .wt-sortable-item").sort(function (x, y) {
127                return Math.sign(x.dataset.wtSortByDate - y.dataset.wtSortByDate);
128            }).appendTo(".wt-sortable-list-fams");
129        });
130    }
131</script>
132<?php View::endpush() ?>
133