xref: /webtrees/resources/views/individual-page.phtml (revision 06a438b41c4b328354bcb5bd8d8d578a3a78f995)
1<?php
2
3use Fisharebest\Webtrees\Auth;
4use Fisharebest\Webtrees\Http\RequestHandlers\AddNewFact;
5use Fisharebest\Webtrees\Http\RequestHandlers\PendingChangesAcceptRecord;
6use Fisharebest\Webtrees\Http\RequestHandlers\PendingChangesRejectRecord;
7use Fisharebest\Webtrees\I18N;
8use Fisharebest\Webtrees\Individual;
9use Fisharebest\Webtrees\Tree;
10use Fisharebest\Webtrees\View;
11use Illuminate\Support\Collection;
12
13/**
14 * @var string     $age
15 * @var Individual $individual
16 * @var string     $user_link
17 * @var Collection $sidebars
18 * @var Collection $individual_media
19 * @var Collection $name_records
20 * @var Collection $sex_records
21 * @var Collection $tabs
22 * @var Tree       $tree
23 */
24?>
25
26<?php if ($individual->isPendingDeletion()) : ?>
27    <?php if (Auth::isModerator($individual->tree())) : ?>
28        <?= view('components/alert-warning-dismissible', [
29            'alert' => /* I18N: %1$s is “accept”, %2$s is “reject”. These are links. */
30                I18N::translate('This individual has been deleted. You should review the deletion and then %1$s or %2$s it.', '<a href="#" class="alert-link" data-post-url="' . e(route(PendingChangesAcceptRecord::class, ['tree' => $individual->tree()->name(), 'xref' => $individual->xref()])) . '">' . I18N::translateContext('You should review the deletion and then accept or reject it.', 'accept') . '</a>', '<a href="#" class="alert-link" data-post-url="' . e(route(PendingChangesRejectRecord::class, ['tree' => $individual->tree()->name(), 'xref' => $individual->xref()])) . '">' . I18N::translateContext('You should review the deletion and then accept or reject it.', 'reject') . '</a>') . ' ' . view('help/link', ['topic' => 'pending_changes']),
31        ]) ?>
32    <?php elseif (Auth::isEditor($individual->tree())) : ?>
33        <?= view('components/alert-warning-dismissible', ['alert' => I18N::translate('This individual has been deleted. The deletion will need to be reviewed by a moderator.') . ' ' . view('help/link', ['topic' => 'pending_changes'])]) ?>
34    <?php endif ?>
35<?php elseif ($individual->isPendingAddition()) : ?>
36    <?php if (Auth::isModerator($individual->tree())) : ?>
37        <?= view('components/alert-warning-dismissible', [
38            'alert' => /* I18N: %1$s is “accept”, %2$s is “reject”. These are links. */
39                I18N::translate('This individual has been edited. You should review the changes and then %1$s or %2$s them.', '<a href="#" class="alert-link" data-post-url="' . e(route(PendingChangesAcceptRecord::class, ['tree' => $individual->tree()->name(), 'xref' => $individual->xref()])) . '">' . I18N::translateContext('You should review the changes and then accept or reject them.', 'accept') . '</a>', '<a href="#" class="alert-link" data-post-url="' . e(route(PendingChangesRejectRecord::class, ['tree' => $individual->tree()->name(), 'xref' => $individual->xref()])) . '">' . I18N::translateContext('You should review the changes and then accept or reject them.', 'reject') . '</a>') . ' ' . view('help/link', ['topic' => 'pending_changes']),
40        ]) ?>
41    <?php elseif (Auth::isEditor($individual->tree())) : ?>
42        <?= view('components/alert-warning-dismissible', ['alert' => I18N::translate('This individual has been edited. The changes need to be reviewed by a moderator.') . ' ' . view('help/link', ['topic' => 'pending_changes'])]) ?>
43    <?php endif ?>
44<?php endif ?>
45
46<div class="d-flex mb-4">
47    <h2 class="wt-page-title mx-auto">
48        <?= $individual->fullName() ?><?= $user_link ?>, <?= $individual->lifespan() ?> <?= $age ?>
49    </h2>
50    <?php if ($individual->canEdit()) : ?>
51        <?= view('individual-page-menu', ['individual' => $individual, 'tree' => $tree]) ?>
52    <?php endif ?>
53</div>
54
55<div class="row">
56    <div class="<?= $sidebars->isEmpty() ? 'col-sm-12' : 'col-sm-8' ?>">
57        <div class="row mb-4">
58            <!-- Individual images -->
59            <?php if ($individual_media->isNotEmpty() || $tree->getPreference('USE_SILHOUETTE') === '1') : ?>
60                <div class="col-sm-3">
61                    <?php if ($individual_media->isEmpty()) : ?>
62                        <div class="img-thumbnail">
63                            <i class="wt-individual-silhouette wt-individual-silhouette-<?= strtolower($individual->sex()) ?>"></i>
64                        </div>
65                    <?php elseif ($individual_media->count() === 1) : ?>
66                        <?= $individual_media->first()->displayImage(200, 260, 'crop', ['class' => 'img-thumbnail img-fluid w-100']) ?>
67                    <?php else : ?>
68                        <div id="individual-images" class="carousel slide" data-ride="carousel" data-interval="false">
69                            <div class="carousel-inner">
70                                <?php foreach ($individual_media as $n => $media_file) : ?>
71                                    <div class="carousel-item <?= $n === 0 ? 'active' : '' ?>">
72                                        <?= $media_file->displayImage(200, 260, 'crop', ['class' => 'img-thumbnail img-fluid w-100']) ?>
73                                    </div>
74                                <?php endforeach ?>
75                            </div>
76                            <a class="carousel-control-prev" href="#individual-images" role="button" data-slide="prev">
77                                <span class="carousel-control-prev-icon" aria-hidden="true"></span>
78                                <span class="sr-only"><?= I18N::translate('previous') ?></span>
79                            </a>
80                            <a class="carousel-control-next" href="#individual-images" role="button" data-slide="next">
81                                <span class="carousel-control-next-icon" aria-hidden="true"></span>
82                                <span class="sr-only"><?= I18N::translate('next') ?></span>
83                            </a>
84                        </div>
85                    <?php endif ?>
86
87                    <?php if (Auth::isEditor($individual->tree())) : ?>
88                        <div class="text-center">
89                            <a href="<?= e(route(AddNewFact::class, ['tree' => $individual->tree()->name(), 'xref' => $individual->xref(), 'fact' => 'OBJE'])) ?>">
90                                <?= I18N::translate('Add a media object') ?>
91                            </a>
92                        </div>
93                    <?php endif ?>
94                </div>
95            <?php endif ?>
96
97            <!-- Name accordion -->
98            <div class="col-sm accordion" id="individual-names">
99                <?php foreach ($name_records as $name_record) : ?>
100                    <?= $name_record ?>
101                <?php endforeach ?>
102
103                <?php foreach ($sex_records as $sex_record) : ?>
104                    <?= $sex_record ?>
105                <?php endforeach ?>
106            </div>
107        </div>
108
109        <div class="wt-tabs-individual" id="individual-tabs">
110            <ul class="nav nav-tabs flex-wrap" role="tablist">
111                <?php foreach ($tabs as $tab) : ?>
112                    <li class="nav-item" role="presentation">
113                        <a class="nav-link<?= $tab->isGrayedOut($individual) ? ' text-muted' : '' ?>" data-toggle="tab" role="tab" data-href="<?= e(route('module', ['module' => $tab->name(), 'action' => 'Tab', 'tree' => $individual->tree()->name(), 'xref' => $individual->xref()])) ?>" href="#<?= $tab->name() ?>">
114                            <?= $tab->tabTitle() ?>
115                        </a>
116                    </li>
117                <?php endforeach ?>
118            </ul>
119
120            <div class="tab-content">
121                <?php foreach ($tabs as $tab) : ?>
122                    <div id="<?= $tab->name() ?>" class="tab-pane fade wt-ajax-load" role="tabpanel"><?php if (!$tab->canLoadAjax()) :
123                        ?><?= $tab->getTabContent($individual) ?><?php
124                             endif ?></div>
125                <?php endforeach ?>
126            </div>
127        </div>
128    </div>
129    <?php if ($sidebars->isNotEmpty()) : ?>
130    <div class="col-sm-4 accordion" id="sidebar">
131        <?php foreach ($sidebars as $sidebar) : ?>
132            <div class="card">
133                <div class="card-header" role="tab" id="sidebar-header-<?= $sidebar->name() ?>">
134                    <div class="card-title mb-0">
135                        <a data-toggle="collapse" href="#sidebar-content-<?= $sidebar->name() ?>" aria-expanded="<?= $sidebar->name() === 'family_nav' ? 'true' : 'false' ?>" aria-controls="sidebar-content-<?= $sidebar->name() ?>">
136                            <?= view('icons/expand') ?>
137                            <?= view('icons/collapse') ?>
138                            <?= $sidebar->sidebarTitle() ?>
139                        </a>
140                    </div>
141                </div>
142
143                <div id="sidebar-content-<?= $sidebar->name() ?>" class="collapse<?= $sidebar->name() === 'family_nav' ? ' show' : '' ?>" data-parent="#sidebar" aria-labelledby="sidebar-header-<?= $sidebar->name() ?>">
144                    <div class="card-body">
145                        <?= $sidebar->getSidebarContent($individual) ?>
146                    </div>
147                </div>
148            </div>
149        <?php endforeach ?>
150    </div>
151    <?php endif ?>
152</div>
153
154<?php View::push('javascript') ?>
155<script>
156  "use strict";
157
158  // Bootstrap tabs - load content dynamically using AJAX
159  $('a[data-toggle="tab"][data-href]').on('show.bs.tab', function () {
160      let target = $(this.hash + ':empty');
161      if (target) {
162          // Start the download immediately...
163          let download = fetch(this.dataset.href);
164
165          // ...but don't insert it until the tab is ready.
166          $(this).one('shown.bs.tab', () => {
167              download
168                  .then(data => data.text())
169                  .then(data => target.html(data));
170          });
171      }
172  });
173
174  // If the URL contains a fragment, then activate the corresponding tab.
175  // Use a prefix on the fragment, to prevent scrolling to the element.
176  let target = window.location.hash.replace("tab-", "");
177  let tab = $("#individual-tabs .nav-link[href='" + target + "']");
178  // If not, then activate the first tab.
179  if (tab.length === 0) {
180    tab = $("#individual-tabs .nav-link:first");
181  }
182  tab.tab("show");
183
184  // If the user selects a tab, update the URL to reflect this
185  $('#individual-tabs a[data-toggle="tab"]').on('shown.bs.tab', function (e) {
186    window.location.hash = "tab-" + e.target.href.substring(e.target.href.indexOf('#') + 1);
187  });
188</script>
189<?php View::endpush() ?>
190
191<?= view('modals/ajax') ?>
192