xref: /webtrees/resources/views/admin/components.phtml (revision 3f0247b283a74c64ac885446380ea81de9cf779e)
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">Close
126                                            </button>
127                                        </div>
128                                    </div>
129                                </div>
130                            </div>
131                        </td>
132
133                        <td>
134                            <button type="button" class="btn btn-link" data-bs-toggle="modal" data-bs-backdrop="static"
135                                    data-bs-target="#access-level-<?= $module->name() ?>">
136                                <?= view('icons/edit') ?>
137                                <span class="visually-hidden"><?= I18N::translate('edit') ?></span>
138                            </button>
139                        </td>
140                    <?php endif ?>
141
142                    <?php if ($uses_sorting) : ?>
143                        <td class="move up text-center">
144                            <a href="#" title="<?= I18N::translate('Move up') ?>">
145                                <?= view('icons/arrow-up') ?>
146                            </a>
147                        </td>
148
149                        <td class="move down text-center">
150                            <a href="#" title="<?= I18N::translate('Move down') ?>">
151                                <?= view('icons/arrow-down') ?>
152                            </a>
153                        </td>
154                    <?php endif ?>
155                </tr>
156            <?php endforeach ?>
157        </tbody>
158    </table>
159
160    <button class="btn btn-primary" type="submit">
161        <?= view('icons/save') ?>
162        <?= I18N::translate('save') ?>
163    </button>
164
165    <a class="btn btn-secondary" href="<?= e(route(ControlPanel::class)) ?>">
166        <?= view('icons/cancel') ?>
167        <?= I18N::translate('cancel') ?>
168    </a>
169
170    <?= csrf_field() ?>
171</form>
172
173<?php View::push('javascript') ?>
174<script>
175  $('.wt-table-components td.move').click(function () {
176    let row = $(this).closest('tr');
177
178    if ($(this).hasClass('up')) {
179      row.prev().before(row);
180    } else {
181      row.next().after(row);
182    }
183
184    return false;
185  });
186</script>
187<?php View::endpush() ?>
188
189