xref: /webtrees/resources/views/edit/reorder-families.phtml (revision 64d12f7b9a9462c8fcd06eb53b52f5b2d2a444f3)
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                    <span class="drag-handle">
40                        <?= view('icons/drag-handle') ?>
41                    </span>
42                        <?= $fact->target()->fullName() ?>
43                    </div>
44                    <div class="card-body">
45                        <?= $fact->target()->formatFirstMajorFact(Gedcom::MARRIAGE_EVENTS, 2) ?>
46                        <?= $fact->target()->formatFirstMajorFact(Gedcom::DIVORCE_EVENTS, 2) ?>
47                    </div>
48                </div>
49            <?php endforeach ?>
50        </div>
51    <?php endif ?>
52
53    <?php if ($famc_facts->count() < 2) : ?>
54            <?php foreach ($famc_facts as $fact) : ?>
55                <input type="hidden" name="order[]" value="<?= e($fact->id()) ?>">
56            <?php endforeach ?>
57    <?php else : ?>
58        <?php if ($fams_facts->count() >= 2) : ?>
59        <hr>
60        <?php endif ?>
61
62        <h3><?= I18N::translate('Parents') ?></h3>
63
64        <p>
65            <?= I18N::translate('An individual can have more than one set of parents.  For example, birth and adopted.') ?>
66            <br>
67            <?= I18N::translate('The first family in the list will be used in charts, lists, reports, etc.') ?>
68        </p>
69
70        <div class="wt-sortable-list-famc">
71            <?php foreach ($famc_facts as $fact) : ?>
72                <div class="card mb-2 wt-sortable-item" data-sortbydate="<?= $fact->target()->getMarriageDate()->julianDay() ?>">
73                    <input type="hidden" name="order[]" value="<?= $fact->id() ?>">
74                    <div class="card-header">
75                    <span class="drag-handle">
76                        <?= view('icons/drag-handle') ?>
77                    </span>
78                        <?= $fact->target()->fullName() ?>
79                        <?php if ($fact->attribute('PEDI') !== '') : ?>
80<?= GedcomCodePedi::getValue($fact->attribute('PEDI'), $individual) ?>
81                        <?php endif ?>
82                    </div>
83                    <div class="card-body">
84                        <?= $fact->target()->formatFirstMajorFact(Gedcom::MARRIAGE_EVENTS, 2) ?>
85                        <?= $fact->target()->formatFirstMajorFact(Gedcom::DIVORCE_EVENTS, 2) ?>
86                    </div>
87                </div>
88            <?php endforeach ?>
89        </div>
90    <?php endif ?>
91
92    <p>
93        <button class="btn btn-primary" type="submit">
94            <?= view('icons/save') ?>
95            <?= /* I18N: A button label. */ I18N::translate('save') ?>
96        </button>
97
98        <a class="btn btn-secondary" href="<?= e($individual->url()) ?>">
99            <?= view('icons/cancel') ?>
100            <?= /* I18N: A button label. */ I18N::translate('cancel') ?>
101        </a>
102    </p>
103</form>
104
105<?php View::push('javascript') ?>
106<script>
107    const famc_list = document.querySelector(".wt-sortable-list-famc");
108    const fams_list = document.querySelector(".wt-sortable-list-fams");
109
110    if (famc_list !== null) {
111      new Sortable(famc_list, {
112        handle: ".drag-handle",
113      });
114    }
115
116    if (fams_list !== null) {
117      new Sortable(fams_list, {
118        handle: ".drag-handle",
119      });
120
121      $("#btn-default-order").on("click", function() {
122        $(".wt-sortable-list-fams .wt-sortable-item").sort(function(x, y) {
123          return Math.sign(x.dataset.sortbydate - y.dataset.sortbydate);
124        }).appendTo(".wt-sortable-list-fams");
125      });
126    }
127</script>
128<?php View::endpush() ?>
129