summaryrefslogtreecommitdiff
path: root/resources/views/admin/components.phtml
blob: 7144722530d196a1ef7dfac1426b125bb6092b73 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
<?php

declare(strict_types=1);

use Fisharebest\Webtrees\Auth;
use Fisharebest\Webtrees\Http\RequestHandlers\ControlPanel;
use Fisharebest\Webtrees\Http\RequestHandlers\ModulesAllPage;
use Fisharebest\Webtrees\I18N;
use Fisharebest\Webtrees\Module\ModuleConfigInterface;
use Fisharebest\Webtrees\Module\ModuleCustomInterface;
use Fisharebest\Webtrees\Module\ModuleExternalUrlInterface;
use Fisharebest\Webtrees\Module\ModuleInterface;
use Fisharebest\Webtrees\Tree;
use Fisharebest\Webtrees\View;
use Illuminate\Support\Collection;

/**
 * @var array<string,array<string,string>> $access_summary
 * @var string                             $description
 * @var class-string<ModuleInterface>      $interface
 * @var Collection<int,ModuleInterface>    $modules
 * @var string                             $title
 * @var Collection<int,Tree>               $trees
 * @var bool                               $uses_access
 * @var bool                               $uses_sorting
 */

?>

<?= view('components/breadcrumbs', ['links' => [route(ControlPanel::class) => I18N::translate('Control panel'), route(ModulesAllPage::class) => I18N::translate('All modules'), $title]]) ?>

<h1><?= $title ?></h1>

<p><?= $description ?></p>

<form method="post">
    <table class="table table-bordered wt-table-components">
        <thead>
            <tr>
                <th><?= I18N::translate('Module') ?></th>
                <th class="text-center"><?= I18N::translate('Enabled') ?></th>
                <?php if ($uses_access) : ?>
                    <th colspan="2" class="text-center"><?= I18N::translate('Access level') ?></th>
                <?php endif ?>
                <?php if ($uses_sorting) : ?>
                    <th class="text-center"><?= I18N::translate('Move up') ?></th>
                    <th class="text-center"><?= I18N::translate('Move down') ?></th>
                <?php endif ?>
            </tr>
        </thead>

        <tbody>
            <?php foreach ($modules as $module_name => $module) : ?>
                <tr>
                    <th scope="col">
                        <input type="hidden" name="order[]" value="<?= e($module->name()) ?>">
                        <span title="<?= e(strip_tags($module->description())) ?>">
                            <?= $module instanceof ModuleCustomInterface ? $module->customTranslations(I18N::languageTag())[$module->title()] ?? $module->title() : $module->title() ?>
                        </span>
                        <?php if ($module instanceof ModuleConfigInterface) : ?>
                            <?php if ($module->isEnabled()) : ?>
                                <a href="<?= e($module->getConfigLink()) ?>" title="<?= I18N::translate('Preferences') ?>">
                                    <?= view('icons/preferences') ?>
                                    <span class="visually-hidden">
                                        <?= I18N::translate('Preferences') ?>
                                    </span>
                                </a>
                            <?php else : ?>
                                <span class="text-muted">
                                    <?= view('icons/preferences') ?>
                                </span>
                            <?php endif ?>
                        <?php endif ?>
                        <?php if ($module instanceof ModuleCustomInterface) : ?>
                            <?= view('admin/custom-module-info', ['module' => $module]) ?>
                        <?php endif ?>
                        <?php if ($module instanceof ModuleExternalUrlInterface) : ?>
                            <?= view('admin/external-module-info', ['module' => $module]) ?>
                        <?php endif ?>
                    </th>

                    <td class="text-center">
                        <label class="d-block">
                            <input type="checkbox" name="status-<?= e($module->name()) ?>"
                                   id="status-<?= e($module->name()) ?>" <?= $module->isEnabled() ? 'checked' : '' ?>>
                            <span class="visually-hidden">
                                <?= I18N::translate('Enabled') ?>
                            </span>
                        </label>
                    </td>

                    <?php if ($uses_access) : ?>
                        <td>
                            <ul class="list-unstyled">
                                <?php foreach ($access_summary[$module->name()] as $level) : ?>
                                    <li><?= $level ?></li>
                                <?php endforeach ?>
                            </ul>

                            <div class="modal fade" id="access-level-<?= $module->name() ?>" tabindex="-1"
                                 role="dialog">
                                <div class="modal-dialog" role="document">
                                    <div class="modal-content">
                                        <div class="modal-header">
                                            <h2 class="modal-title">
                                                <?= e($module->title()) ?> – <?= I18N::translate('Access level') ?>
                                            </h2>
                                            <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="<?= I18N::translate('close') ?>">
                                            </button>
                                        </div>
                                        <div class="modal-body">
                                            <table class="table table-sm">
                                                <tbody>
                                                    <?php foreach ($trees as $tree) : ?>
                                                        <tr>
                                                            <td>
                                                                <?= e($tree->title()) ?>
                                                            </td>
                                                            <td>
                                                                <?= view('components/select', ['name' => 'access-' . $module->name() . '-' . $tree->id(), 'selected' => $module->accessLevel($tree, $interface), 'options' => Auth::accessLevelNames()]) ?>
                                                        </tr>
                                                    <?php endforeach ?>
                                                </tbody>
                                            </table>
                                        </div>
                                        <div class="modal-footer">
                                            <button type="button" class="btn btn-primary" data-bs-dismiss="modal">
                                                <?= view('icons/cancel') ?>
                                                <?= I18N::translate('close') ?>
                                            </button>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </td>

                        <td>
                            <button type="button" class="btn btn-link" data-bs-toggle="modal" data-bs-backdrop="static"
                                    data-bs-target="#access-level-<?= $module->name() ?>">
                                <?= view('icons/edit') ?>
                                <span class="visually-hidden"><?= I18N::translate('edit') ?></span>
                            </button>
                        </td>
                    <?php endif ?>

                    <?php if ($uses_sorting) : ?>
                        <td class="move up text-center">
                            <a href="#" title="<?= I18N::translate('Move up') ?>">
                                <?= view('icons/arrow-up') ?>
                            </a>
                        </td>

                        <td class="move down text-center">
                            <a href="#" title="<?= I18N::translate('Move down') ?>">
                                <?= view('icons/arrow-down') ?>
                            </a>
                        </td>
                    <?php endif ?>
                </tr>
            <?php endforeach ?>
        </tbody>
    </table>

    <button class="btn btn-primary" type="submit">
        <?= view('icons/save') ?>
        <?= I18N::translate('save') ?>
    </button>

    <a class="btn btn-secondary" href="<?= e(route(ControlPanel::class)) ?>">
        <?= view('icons/cancel') ?>
        <?= I18N::translate('cancel') ?>
    </a>

    <?= csrf_field() ?>
</form>

<?php View::push('javascript') ?>
<script>
  $('.wt-table-components td.move').click(function () {
    let row = $(this).closest('tr');

    if ($(this).hasClass('up')) {
      row.prev().before(row);
    } else {
      row.next().after(row);
    }

    return false;
  });
</script>
<?php View::endpush() ?>