xref: /webtrees/resources/views/admin/components.phtml (revision 352bd396f944a449a229e394abc071136bb37e8e)
1<?php
2
3use Fisharebest\Webtrees\Auth;
4use Fisharebest\Webtrees\Http\RequestHandlers\ControlPanel;
5use Fisharebest\Webtrees\Http\RequestHandlers\ModulesAllPage;
6use Fisharebest\Webtrees\I18N;
7use Fisharebest\Webtrees\Module\ModuleConfigInterface;
8use Fisharebest\Webtrees\Module\ModuleCustomInterface;
9use Fisharebest\Webtrees\Module\ModuleExternalUrlInterface;
10use Fisharebest\Webtrees\Module\ModuleInterface;
11use Fisharebest\Webtrees\Tree;
12use Fisharebest\Webtrees\View;
13use Illuminate\Support\Collection;
14
15/**
16 * @var array<string,array<string,string>> $access_summary
17 * @var string                             $description
18 * @var string                             $interface
19 * @var Collection<int,ModuleInterface>    $modules
20 * @var string                             $title
21 * @var Collection<int,Tree>               $trees
22 * @var bool                               $uses_access
23 * @var bool                               $uses_sorting
24 */
25
26?>
27
28<?= view('components/breadcrumbs', ['links' => [route(ControlPanel::class) => I18N::translate('Control panel'), route(ModulesAllPage::class) => I18N::translate('All modules'), $title]]) ?>
29
30<h1><?= $title ?></h1>
31
32<p><?= $description ?></p>
33
34<form method="post">
35    <table class="table table-bordered wt-table-components">
36        <thead>
37            <tr>
38                <th><?= I18N::translate('Module') ?></th>
39                <th class="text-center"><?= I18N::translate('Enabled') ?></th>
40                <?php if ($uses_access) : ?>
41                    <th colspan="2" class="text-center"><?= I18N::translate('Access level') ?></th>
42                <?php endif ?>
43                <?php if ($uses_sorting) : ?>
44                    <th class="text-center"><?= I18N::translate('Move up') ?></th>
45                    <th class="text-center"><?= I18N::translate('Move down') ?></th>
46                <?php endif ?>
47            </tr>
48        </thead>
49
50        <tbody>
51            <?php foreach ($modules as $module_name => $module) : ?>
52                <tr>
53                    <th scope="col">
54                        <input type="hidden" name="order[]" value="<?= e($module->name()) ?>">
55                        <span title="<?= e(strip_tags($module->description())) ?>">
56                            <?= $module instanceof ModuleCustomInterface ? $module->customTranslations(I18N::languageTag())[$module->title()] ?? $module->title() : $module->title() ?>
57                        </span>
58                        <?php if ($module instanceof ModuleConfigInterface) : ?>
59                            <?php if ($module->isEnabled()) : ?>
60                                <a href="<?= e($module->getConfigLink()) ?>" title="<?= I18N::translate('Preferences') ?>">
61                                    <?= view('icons/preferences') ?>
62                                    <span class="visually-hidden">
63                                        <?= I18N::translate('Preferences') ?>
64                                    </span>
65                                </a>
66                            <?php else : ?>
67                                <span class="text-muted">
68                                    <?= view('icons/preferences') ?>
69                                </span>
70                            <?php endif ?>
71                        <?php endif ?>
72                        <?php if ($module instanceof ModuleCustomInterface) : ?>
73                            <?= view('admin/custom-module-info', ['module' => $module]) ?>
74                        <?php endif ?>
75                        <?php if ($module instanceof ModuleExternalUrlInterface) : ?>
76                            <?= view('admin/external-module-info', ['module' => $module]) ?>
77                        <?php endif ?>
78                    </th>
79
80                    <td class="text-center">
81                        <label class="d-block">
82                            <input type="checkbox" name="status-<?= e($module->name()) ?>"
83                                   id="status-<?= e($module->name()) ?>" <?= $module->isEnabled() ? 'checked' : '' ?>>
84                            <span class="visually-hidden">
85                                <?= I18N::translate('Enabled') ?>
86                            </span>
87                        </label>
88                    </td>
89
90                    <?php if ($uses_access) : ?>
91                        <td>
92                            <ul class="list-unstyled">
93                                <?php foreach ($access_summary[$module->name()] as $level) : ?>
94                                    <li><?= $level ?></li>
95                                <?php endforeach ?>
96                            </ul>
97
98                            <div class="modal fade" id="access-level-<?= $module->name() ?>" tabindex="-1"
99                                 role="dialog">
100                                <div class="modal-dialog" role="document">
101                                    <div class="modal-content">
102                                        <div class="modal-header">
103                                            <h2 class="modal-title">
104                                                <?= e($module->title()) ?><?= I18N::translate('Access level') ?>
105                                            </h2>
106                                            <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="<?= I18N::translate('close') ?>">
107                                            </button>
108                                        </div>
109                                        <div class="modal-body">
110                                            <table class="table table-sm">
111                                                <tbody>
112                                                    <?php foreach ($trees as $tree) : ?>
113                                                        <tr>
114                                                            <td>
115                                                                <?= e($tree->title()) ?>
116                                                            </td>
117                                                            <td>
118                                                                <?= view('components/select', ['name' => 'access-' . $module->name() . '-' . $tree->id(), 'selected' => $module->accessLevel($tree, $interface), 'options' => Auth::accessLevelNames()]) ?>
119                                                        </tr>
120                                                    <?php endforeach ?>
121                                                </tbody>
122                                            </table>
123                                        </div>
124                                        <div class="modal-footer">
125                                            <button type="button" class="btn btn-primary" data-bs-dismiss="modal">
126                                                <?= view('icons/cancel') ?>
127                                                <?= I18N::translate('close') ?>
128                                            </button>
129                                        </div>
130                                    </div>
131                                </div>
132                            </div>
133                        </td>
134
135                        <td>
136                            <button type="button" class="btn btn-link" data-bs-toggle="modal" data-bs-backdrop="static"
137                                    data-bs-target="#access-level-<?= $module->name() ?>">
138                                <?= view('icons/edit') ?>
139                                <span class="visually-hidden"><?= I18N::translate('edit') ?></span>
140                            </button>
141                        </td>
142                    <?php endif ?>
143
144                    <?php if ($uses_sorting) : ?>
145                        <td class="move up text-center">
146                            <a href="#" title="<?= I18N::translate('Move up') ?>">
147                                <?= view('icons/arrow-up') ?>
148                            </a>
149                        </td>
150
151                        <td class="move down text-center">
152                            <a href="#" title="<?= I18N::translate('Move down') ?>">
153                                <?= view('icons/arrow-down') ?>
154                            </a>
155                        </td>
156                    <?php endif ?>
157                </tr>
158            <?php endforeach ?>
159        </tbody>
160    </table>
161
162    <button class="btn btn-primary" type="submit">
163        <?= view('icons/save') ?>
164        <?= I18N::translate('save') ?>
165    </button>
166
167    <a class="btn btn-secondary" href="<?= e(route(ControlPanel::class)) ?>">
168        <?= view('icons/cancel') ?>
169        <?= I18N::translate('cancel') ?>
170    </a>
171
172    <?= csrf_field() ?>
173</form>
174
175<?php View::push('javascript') ?>
176<script>
177  $('.wt-table-components td.move').click(function () {
178    let row = $(this).closest('tr');
179
180    if ($(this).hasClass('up')) {
181      row.prev().before(row);
182    } else {
183      row.next().after(row);
184    }
185
186    return false;
187  });
188</script>
189<?php View::endpush() ?>
190
191