xref: /webtrees/resources/views/admin/components.phtml (revision f9b64f4645b5fb43a1aaed50100ddd750a0b68d8)
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="sr-only">
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="sr-only">
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="close" data-dismiss="modal" aria-label="Close">
108                                                <span aria-hidden="true">&times;</span>
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-dismiss="modal">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-toggle="modal" data-backdrop="static"
137                                    data-target="#access-level-<?= $module->name() ?>">
138                                <?= view('icons/edit') ?>
139                                <span class="sr-only"><?= 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</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