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