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