xref: /webtrees/resources/views/admin/media.phtml (revision 663dd9d85326d3016550248671b2f0eba8949cb3)
1<?php
2
3use Fisharebest\Webtrees\Http\RequestHandlers\ControlPanel;
4use Fisharebest\Webtrees\Http\RequestHandlers\ManageMediaAction;
5use Fisharebest\Webtrees\Http\RequestHandlers\ManageMediaData;
6use Fisharebest\Webtrees\I18N;
7use Fisharebest\Webtrees\View;
8use Illuminate\Support\Collection;
9
10/**
11 * @var string                   $data_folder
12 * @var string                   $files
13 * @var string                   $media_folder
14 * @var Collection<string>       $media_folders
15 * @var array<int|string,string> $media_types
16 * @var string                   $subfolders
17 * @var string                   $title
18 */
19?>
20
21<?= view('components/breadcrumbs', ['links' => [route(ControlPanel::class) => I18N::translate('Control panel'), $title]]) ?>
22
23<h1><?= $title ?></h1>
24
25<form method="post" action="<?= e(route(ManageMediaAction::class)) ?>" id="admin-media-form">
26    <?= csrf_field() ?>
27
28    <table class="table table-bordered table-sm">
29        <thead>
30            <tr>
31                <th><?= I18N::translate('Media files') ?></th>
32                <th><?= I18N::translate('Media folders') ?></th>
33            </tr>
34        </thead>
35        <tbody>
36            <tr>
37                <td>
38                    <label>
39                        <input type="radio" name="files" value="local" <?= $files === 'local' ? 'checked' : '' ?>>
40                        <?= /* I18N: “Local files” are stored on this computer */ I18N::translate('Local files') ?>
41                    </label>
42                    <br>
43                    <label>
44                        <input type="radio" name="files" value="external" <?= $files === 'external' ? 'checked' : '' ?>>
45                        <?= /* I18N: “External files” are stored on other computers */ I18N::translate('External files') ?>
46                    </label>
47                    <br>
48                    <label>
49                        <input type="radio" name="files" value="unused" <?= $files === 'unused' ? 'checked' : '' ?>>
50                        <?= I18N::translate('Unused files') ?>
51                    </label>
52                </td>
53                <td>
54                    <?php if ($files === 'local' || $files === 'unused') : ?>
55                        <div class="input-group mb-2" dir="ltr">
56                            <div class="input-group-prepend">
57                                <div class="input-group-text"><?= e($data_folder) ?></div>
58                            </div>
59                                <?php if ($media_folders->count() > 1) : ?>
60                                    <?= view('components/select', ['name' => 'media_folder', 'selected' => $media_folder, 'options' => $media_folders]) ?>
61
62                                <?php else : ?>
63                                    <input aria-label="<?= I18N::translate('Media folder') ?>"
64                                           type="text" class="form-control" name="media_folder" value="<?= e($media_folder) ?>" readonly>
65                                <?php endif ?>
66                        </div>
67
68                        <label>
69                            <input type="radio" name="subfolders" value="include" <?= $subfolders === 'include' ? 'checked' : '' ?>>
70                            <?= I18N::translate('Include subfolders') ?>
71                        </label>
72                        <br>
73                        <label>
74                            <input type="radio" name="subfolders" value="exclude" <?= $subfolders === 'exclude' ? ' checked' : '' ?>>
75                            <?= I18N::translate('Exclude subfolders') ?>
76                        </label>
77
78                    <?php elseif ($files === 'external') : ?>
79                        <?= I18N::translate('External media files have a URL instead of a filename.') ?>
80                        <input type="hidden" name="media_folder" value="<?= e($media_folder) ?>">
81
82                    <?php endif ?>
83                </td>
84            </tr>
85        </tbody>
86    </table>
87</form>
88<br>
89<br>
90
91<table
92    class="table table-bordered table-sm datatables d-none"
93    <?= view('lists/datatables-attributes') ?>
94    data-ajax="<?= e(route(ManageMediaData::class, ['files' => $files, 'media_folder' => $media_folder, 'subfolders' => $subfolders])) ?>"
95    data-server-side="true"
96>
97    <thead>
98        <tr>
99            <th>
100                <?= I18N::translate('Media file') ?>
101            </th>
102
103            <th data-sortable="false">
104                <?= I18N::translate('Media') ?>
105            </th>
106
107            <th data-sortable="<?= $files === 'unused' ? 'false' : 'true' ?>">
108                <?= I18N::translate('Media object') ?>
109            </th>
110        </tr>
111    </thead>
112</table>
113<?= view('modals/create-media-from-file', ['media_types' => $media_types]) ?>
114
115<?php View::push('javascript') ?>
116<script>
117    $("#admin-media-form input, #admin-media-form select").change(function () {
118        $("#admin-media-form").submit();
119    });
120</script>
121<?php View::endpush() ?>
122