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