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