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