xref: /webtrees/resources/views/edit/reorder-families.phtml (revision 3f0247b283a74c64ac885446380ea81de9cf779e)
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<int,Fact> $famc_facts
15 * @var Collection<int,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    <?php if ($fams_facts->count() < 2) : ?>
27        <?php foreach ($fams_facts as $fact) : ?>
28            <input type="hidden" name="order[]" value="<?= e($fact->id()) ?>">
29        <?php endforeach ?>
30    <?php else : ?>
31        <h3><?= I18N::translate('Spouses') ?></h3>
32
33        <p>
34            <?= I18N::translate('When an individual has more than one spouse, you should sort the families in date order.') ?>
35        </p>
36
37        <p>
38            <button class="btn btn-secondary" id="btn-default-order" type="button">
39                <?= view('icons/sort') ?>
40                <?= /* I18N: A button label. */ I18N::translate('sort by date of marriage') ?>
41            </button>
42        </p>
43
44        <div class="wt-sortable-list wt-sortable-list-fams">
45            <?php foreach ($fams_facts as $fact) : ?>
46                <div class="card mb-2 wt-sortable-item" data-wt-sort-by-date="<?= $fact->target()->getMarriageDate()->julianDay() ?>">
47                    <input type="hidden" name="order[]" value="<?= $fact->id() ?>">
48                    <div class="card-header">
49                        <?= view('edit/reorder-card-header', ['title' => $fact->target()->fullName()]) ?>
50                    </div>
51
52                    <div class="card-body">
53                        <?= $fact->target()->formatFirstMajorFact(Gedcom::MARRIAGE_EVENTS, 2) ?>
54                        <?= $fact->target()->formatFirstMajorFact(Gedcom::DIVORCE_EVENTS, 2) ?>
55                    </div>
56                </div>
57            <?php endforeach ?>
58        </div>
59    <?php endif ?>
60
61    <?php if ($famc_facts->count() < 2) : ?>
62            <?php foreach ($famc_facts as $fact) : ?>
63                <input type="hidden" name="order[]" value="<?= e($fact->id()) ?>">
64            <?php endforeach ?>
65    <?php else : ?>
66        <?php if ($fams_facts->count() >= 2) : ?>
67        <hr>
68        <?php endif ?>
69
70        <h3><?= I18N::translate('Parents') ?></h3>
71
72        <p>
73            <?= I18N::translate('An individual can have more than one set of parents.  For example, birth and adopted.') ?>
74            <br>
75            <?= I18N::translate('The first family in the list will be used in charts, lists, reports, etc.') ?>
76        </p>
77
78        <div class="wt-sortable-list wt-sortable-list-famc">
79            <?php foreach ($famc_facts as $fact) : ?>
80                <div class="card my-2 wt-sortable-item" data-sortbydate="<?= $fact->target()->getMarriageDate()->julianDay() ?>">
81                    <input type="hidden" name="order[]" value="<?= $fact->id() ?>">
82                    <div class="card-header">
83                        <?= view('edit/reorder-card-header', ['title' => $fact->target()->fullName() . ($fact->attribute('PEDI') === '' ? '' : ' — ' . Registry::elementFactory()->make('INDI:FAMC:PEDI')->value($fact->attribute('PEDI'), $tree))]) ?>
84                    </div>
85                    <div class="card-body">
86                        <?= $fact->target()->formatFirstMajorFact(Gedcom::MARRIAGE_EVENTS, 2) ?>
87                        <?= $fact->target()->formatFirstMajorFact(Gedcom::DIVORCE_EVENTS, 2) ?>
88                    </div>
89                </div>
90            <?php endforeach ?>
91        </div>
92    <?php endif ?>
93
94    <p>
95        <button class="btn btn-primary" type="submit">
96            <?= view('icons/save') ?>
97            <?= /* I18N: A button label. */ I18N::translate('save') ?>
98        </button>
99
100        <a class="btn btn-secondary" href="<?= e($individual->url()) ?>">
101            <?= view('icons/cancel') ?>
102            <?= /* I18N: A button label. */ I18N::translate('cancel') ?>
103        </a>
104    </p>
105
106    <?= csrf_field() ?>
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