xref: /webtrees/resources/views/individual-page.phtml (revision dc270d8cc5085ed29f3f419c99734ddd0960c624)
12c3dad18SGreg Roach<?php
2852ede8cSGreg Roach
32c3dad18SGreg Roachuse Fisharebest\Webtrees\Auth;
4*dc270d8cSGreg Roachuse Fisharebest\Webtrees\Fact;
52917771cSGreg Roachuse Fisharebest\Webtrees\Http\RequestHandlers\AddNewFact;
622e73debSGreg Roachuse Fisharebest\Webtrees\Http\RequestHandlers\PendingChangesAcceptRecord;
722e73debSGreg Roachuse Fisharebest\Webtrees\Http\RequestHandlers\PendingChangesRejectRecord;
82c3dad18SGreg Roachuse Fisharebest\Webtrees\I18N;
92c3dad18SGreg Roachuse Fisharebest\Webtrees\Individual;
10*dc270d8cSGreg Roachuse Fisharebest\Webtrees\Media;
11*dc270d8cSGreg Roachuse Fisharebest\Webtrees\Module\ModuleSidebarInterface;
12*dc270d8cSGreg Roachuse Fisharebest\Webtrees\Module\ModuleTabInterface;
13054771e9SGreg Roachuse Fisharebest\Webtrees\Tree;
142c3dad18SGreg Roachuse Fisharebest\Webtrees\View;
152c3dad18SGreg Roachuse Illuminate\Support\Collection;
162c3dad18SGreg Roach
172c3dad18SGreg Roach/**
18054771e9SGreg Roach * @var string                             $age
192c3dad18SGreg Roach * @var Individual                         $individual
202c3dad18SGreg Roach * @var string                             $user_link
21*dc270d8cSGreg Roach * @var Collection<ModuleSidebarInterface> $sidebars
22*dc270d8cSGreg Roach * @var Collection<Media>                  $individual_media
23*dc270d8cSGreg Roach * @var Collection<Fact>                   $name_records
24*dc270d8cSGreg Roach * @var Collection<Fact>                   $sex_records
25*dc270d8cSGreg Roach * @var Collection<ModuleTabInterface      $tabs
26054771e9SGreg Roach * @var Tree                               $tree
272c3dad18SGreg Roach */
282c3dad18SGreg Roach?>
29dd6b2bfcSGreg Roach
30dd6b2bfcSGreg Roach<?php if ($individual->isPendingDeletion()) : ?>
31f4afa648SGreg Roach    <?php if (Auth::isModerator($individual->tree())) : ?>
32dd6b2bfcSGreg Roach        <?= view('components/alert-warning-dismissible', [
33dd6b2bfcSGreg Roach            'alert' => /* I18N: %1$s is “accept”, %2$s is “reject”. These are links. */
340973b4d2SGreg Roach                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']),
35dd6b2bfcSGreg Roach        ]) ?>
36f4afa648SGreg Roach    <?php elseif (Auth::isEditor($individual->tree())) : ?>
370973b4d2SGreg Roach        <?= 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'])]) ?>
38dd6b2bfcSGreg Roach    <?php endif ?>
39dd6b2bfcSGreg Roach<?php elseif ($individual->isPendingAddition()) : ?>
40f4afa648SGreg Roach    <?php if (Auth::isModerator($individual->tree())) : ?>
41dd6b2bfcSGreg Roach        <?= view('components/alert-warning-dismissible', [
42dd6b2bfcSGreg Roach            'alert' => /* I18N: %1$s is “accept”, %2$s is “reject”. These are links. */
430973b4d2SGreg Roach                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']),
44dd6b2bfcSGreg Roach        ]) ?>
45f4afa648SGreg Roach    <?php elseif (Auth::isEditor($individual->tree())) : ?>
460973b4d2SGreg Roach        <?= 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'])]) ?>
47dd6b2bfcSGreg Roach    <?php endif ?>
48dd6b2bfcSGreg Roach<?php endif ?>
49dd6b2bfcSGreg Roach
50dd6b2bfcSGreg Roach<div class="d-flex mb-4">
51dd6b2bfcSGreg Roach    <h2 class="wt-page-title mx-auto">
525e6816beSGreg Roach        <?= $individual->fullName() ?><?= $user_link ?>, <?= $individual->lifespan() ?> <?= $age ?>
53dd6b2bfcSGreg Roach    </h2>
541450f098SGreg Roach    <?php if ($individual->canEdit()) : ?>
55203146cfSGreg Roach        <?= view('individual-page-menu', ['record' => $individual]) ?>
56dd6b2bfcSGreg Roach    <?php endif ?>
57dd6b2bfcSGreg Roach</div>
58dd6b2bfcSGreg Roach
59dd6b2bfcSGreg Roach<div class="row">
608d38dd5aSGreg Roach    <div class="<?= $sidebars->isEmpty() ? 'col-sm-12' : 'col-sm-8' ?>">
61dd6b2bfcSGreg Roach        <div class="row mb-4">
62dd6b2bfcSGreg Roach            <!-- Individual images -->
638e64ca84SGreg Roach            <?php if ($individual_media->isNotEmpty() || $tree->getPreference('USE_SILHOUETTE') === '1') : ?>
64dd6b2bfcSGreg Roach                <div class="col-sm-3">
658e64ca84SGreg Roach                    <?php if ($individual_media->isEmpty()) : ?>
668e64ca84SGreg Roach                        <div class="img-thumbnail">
6739ca88baSGreg Roach                            <i class="wt-individual-silhouette wt-individual-silhouette-<?= strtolower($individual->sex()) ?>"></i>
688e64ca84SGreg Roach                        </div>
698e64ca84SGreg Roach                    <?php elseif ($individual_media->count() === 1) : ?>
708e64ca84SGreg Roach                        <?= $individual_media->first()->displayImage(200, 260, 'crop', ['class' => 'img-thumbnail img-fluid w-100']) ?>
71dd6b2bfcSGreg Roach                    <?php else : ?>
72dd6b2bfcSGreg Roach                        <div id="individual-images" class="carousel slide" data-ride="carousel" data-interval="false">
73dd6b2bfcSGreg Roach                            <div class="carousel-inner">
74dd6b2bfcSGreg Roach                                <?php foreach ($individual_media as $n => $media_file) : ?>
75dd6b2bfcSGreg Roach                                    <div class="carousel-item <?= $n === 0 ? 'active' : '' ?>">
76dd6b2bfcSGreg Roach                                        <?= $media_file->displayImage(200, 260, 'crop', ['class' => 'img-thumbnail img-fluid w-100']) ?>
77dd6b2bfcSGreg Roach                                    </div>
78dd6b2bfcSGreg Roach                                <?php endforeach ?>
79dd6b2bfcSGreg Roach                            </div>
80dd6b2bfcSGreg Roach                            <a class="carousel-control-prev" href="#individual-images" role="button" data-slide="prev">
81dd6b2bfcSGreg Roach                                <span class="carousel-control-prev-icon" aria-hidden="true"></span>
82dd6b2bfcSGreg Roach                                <span class="sr-only"><?= I18N::translate('previous') ?></span>
83dd6b2bfcSGreg Roach                            </a>
84dd6b2bfcSGreg Roach                            <a class="carousel-control-next" href="#individual-images" role="button" data-slide="next">
85dd6b2bfcSGreg Roach                                <span class="carousel-control-next-icon" aria-hidden="true"></span>
86dd6b2bfcSGreg Roach                                <span class="sr-only"><?= I18N::translate('next') ?></span>
87dd6b2bfcSGreg Roach                            </a>
88dd6b2bfcSGreg Roach                        </div>
89dd6b2bfcSGreg Roach                    <?php endif ?>
90dd6b2bfcSGreg Roach
91f4afa648SGreg Roach                    <?php if (Auth::isEditor($individual->tree())) : ?>
928e64ca84SGreg Roach                        <div class="text-center">
932917771cSGreg Roach                            <a href="<?= e(route(AddNewFact::class, ['tree' => $individual->tree()->name(), 'xref' => $individual->xref(), 'fact' => 'OBJE'])) ?>">
94dd6b2bfcSGreg Roach                                <?= I18N::translate('Add a media object') ?>
95dd6b2bfcSGreg Roach                            </a>
96dd6b2bfcSGreg Roach                        </div>
97dd6b2bfcSGreg Roach                    <?php endif ?>
98dd6b2bfcSGreg Roach                </div>
998e64ca84SGreg Roach            <?php endif ?>
100dd6b2bfcSGreg Roach
101dd6b2bfcSGreg Roach            <!-- Name accordion -->
102c15fb5e7SGreg Roach            <div class="col-sm accordion" id="individual-names">
103dd6b2bfcSGreg Roach                <?php foreach ($name_records as $name_record) : ?>
104dd6b2bfcSGreg Roach                    <?= $name_record ?>
105dd6b2bfcSGreg Roach                <?php endforeach ?>
106dd6b2bfcSGreg Roach
107dd6b2bfcSGreg Roach                <?php foreach ($sex_records as $sex_record) : ?>
108dd6b2bfcSGreg Roach                    <?= $sex_record ?>
109dd6b2bfcSGreg Roach                <?php endforeach ?>
110dd6b2bfcSGreg Roach            </div>
111dd6b2bfcSGreg Roach        </div>
112dd6b2bfcSGreg Roach
1134a2590a5SGreg Roach        <div class="wt-tabs-individual" id="individual-tabs">
1146a4003b9SGreg Roach            <ul class="nav nav-tabs flex-wrap" role="tablist">
115dd6b2bfcSGreg Roach                <?php foreach ($tabs as $tab) : ?>
1166a4003b9SGreg Roach                    <li class="nav-item" role="presentation">
117852ede8cSGreg Roach                        <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() ?>">
118defb8071SRichard Cissée                            <?= $tab->tabTitle() ?>
119dd6b2bfcSGreg Roach                        </a>
120dd6b2bfcSGreg Roach                    </li>
121dd6b2bfcSGreg Roach                <?php endforeach ?>
122dd6b2bfcSGreg Roach            </ul>
1236a4003b9SGreg Roach
124dd6b2bfcSGreg Roach            <div class="tab-content">
125dd6b2bfcSGreg Roach                <?php foreach ($tabs as $tab) : ?>
126677aaceaSGreg Roach                    <div id="<?= $tab->name() ?>" class="tab-pane fade wt-ajax-load" role="tabpanel"><?php if (!$tab->canLoadAjax()) :
127d70512abSGreg Roach                        ?><?= $tab->getTabContent($individual) ?><?php
128d70512abSGreg Roach                             endif ?></div>
129dd6b2bfcSGreg Roach                <?php endforeach ?>
130dd6b2bfcSGreg Roach            </div>
131dd6b2bfcSGreg Roach        </div>
132dd6b2bfcSGreg Roach    </div>
133c72fc94cSGreg Roach    <?php if ($sidebars->isNotEmpty()) : ?>
134336be01cSGreg Roach    <div class="col-sm-4 accordion" id="sidebar">
135dd6b2bfcSGreg Roach        <?php foreach ($sidebars as $sidebar) : ?>
136dd6b2bfcSGreg Roach            <div class="card">
137677aaceaSGreg Roach                <div class="card-header" role="tab" id="sidebar-header-<?= $sidebar->name() ?>">
138dd6b2bfcSGreg Roach                    <div class="card-title mb-0">
139336be01cSGreg Roach                        <a data-toggle="collapse" href="#sidebar-content-<?= $sidebar->name() ?>" aria-expanded="<?= $sidebar->name() === 'family_nav' ? 'true' : 'false' ?>" aria-controls="sidebar-content-<?= $sidebar->name() ?>">
140c15fb5e7SGreg Roach                            <?= view('icons/expand') ?>
141c15fb5e7SGreg Roach                            <?= view('icons/collapse') ?>
142defb8071SRichard Cissée                            <?= $sidebar->sidebarTitle() ?>
143dd6b2bfcSGreg Roach                        </a>
144dd6b2bfcSGreg Roach                    </div>
145dd6b2bfcSGreg Roach                </div>
1466a4003b9SGreg Roach
147336be01cSGreg Roach                <div id="sidebar-content-<?= $sidebar->name() ?>" class="collapse<?= $sidebar->name() === 'family_nav' ? ' show' : '' ?>" data-parent="#sidebar" aria-labelledby="sidebar-header-<?= $sidebar->name() ?>">
148dd6b2bfcSGreg Roach                    <div class="card-body">
1497d70e4a7SGreg Roach                        <?= $sidebar->getSidebarContent($individual) ?>
1507d70e4a7SGreg Roach                    </div>
151dd6b2bfcSGreg Roach                </div>
152dd6b2bfcSGreg Roach            </div>
153dd6b2bfcSGreg Roach        <?php endforeach ?>
154dd6b2bfcSGreg Roach    </div>
155c72fc94cSGreg Roach    <?php endif ?>
156dd6b2bfcSGreg Roach</div>
157dd6b2bfcSGreg Roach
158dd6b2bfcSGreg Roach<?php View::push('javascript') ?>
159dd6b2bfcSGreg Roach<script>
160dd6b2bfcSGreg Roach  "use strict";
161dd6b2bfcSGreg Roach
162dd6b2bfcSGreg Roach  // Bootstrap tabs - load content dynamically using AJAX
163dd6b2bfcSGreg Roach  $('a[data-toggle="tab"][data-href]').on('show.bs.tab', function () {
1645675e46eSmiqrogroove      let target = $(this.hash + ':empty');
16506b58f1dSGreg Roach      if (target.length > 0) {
1665675e46eSmiqrogroove          // Start the download immediately...
1675675e46eSmiqrogroove          let download = fetch(this.dataset.href);
1685675e46eSmiqrogroove
1695675e46eSmiqrogroove          // ...but don't insert it until the tab is ready.
1705675e46eSmiqrogroove          $(this).one('shown.bs.tab', () => {
1715675e46eSmiqrogroove              download
1725675e46eSmiqrogroove                  .then(data => data.text())
1735675e46eSmiqrogroove                  .then(data => target.html(data));
1745675e46eSmiqrogroove          });
1755675e46eSmiqrogroove      }
176dd6b2bfcSGreg Roach  });
177dd6b2bfcSGreg Roach
178dd6b2bfcSGreg Roach  // If the URL contains a fragment, then activate the corresponding tab.
179dd6b2bfcSGreg Roach  // Use a prefix on the fragment, to prevent scrolling to the element.
180054771e9SGreg Roach  let target = window.location.hash.replace("tab-", "");
181054771e9SGreg Roach  let tab = $("#individual-tabs .nav-link[href='" + target + "']");
182dd6b2bfcSGreg Roach  // If not, then activate the first tab.
183dd6b2bfcSGreg Roach  if (tab.length === 0) {
184dd6b2bfcSGreg Roach    tab = $("#individual-tabs .nav-link:first");
185dd6b2bfcSGreg Roach  }
186dd6b2bfcSGreg Roach  tab.tab("show");
187dd6b2bfcSGreg Roach
188dd6b2bfcSGreg Roach  // If the user selects a tab, update the URL to reflect this
189dd6b2bfcSGreg Roach  $('#individual-tabs a[data-toggle="tab"]').on('shown.bs.tab', function (e) {
190dd6b2bfcSGreg Roach    window.location.hash = "tab-" + e.target.href.substring(e.target.href.indexOf('#') + 1);
191dd6b2bfcSGreg Roach  });
192dd6b2bfcSGreg Roach</script>
193dd6b2bfcSGreg Roach<?php View::endpush() ?>
194dd6b2bfcSGreg Roach
195dd6b2bfcSGreg Roach<?= view('modals/ajax') ?>
196