xref: /webtrees/resources/views/modals/media-file-fields.phtml (revision 06a438b41c4b328354bcb5bd8d8d578a3a78f995)
1<?php
2
3use Fisharebest\Webtrees\GedcomTag;
4use Fisharebest\Webtrees\I18N;
5
6?>
7<?php ?>
8
9<div class="form-group row <?= $media_file ? 'd-none' : '' ?>">
10    <label class="col-form-label col-sm-2" for="file-location">
11        <?= I18N::translate('Media file') ?>
12    </label>
13    <div class="col-sm-10">
14        <select class="form-control" id="file-location" name="file_location">
15            <option value="upload">
16                <?= I18N::translate('A file on your computer') ?>
17            </option>
18            <?php if (!empty($unused_files)) : ?>
19            <option value="unused">
20                <?= I18N::translate('A file on the server') ?>
21            </option>
22            <?php endif ?>
23            <option value="url">
24                <?= /* I18N: URL = web address */ I18N::translate('A URL') ?>
25            </option>
26        </select>
27    </div>
28</div>
29
30<div class="form-group row file-location file-location-upload <?= $media_file ? 'd-none' : '' ?>">
31    <label class="col-form-label col-sm-2" for="file">
32        <?= I18N::translate('A file on your computer') ?>
33    </label>
34    <div class="col-sm-10">
35        <input class="form-control" id="file" name="file" type="file">
36        <small class="text-muted">
37            <?= I18N::translate('Maximum upload size: ') ?>
38            <?= $max_upload_size ?>
39        </small>
40    </div>
41</div>
42
43<div class="form-group row file-location file-location-upload <?= $media_file && $media_file->isExternal() ? 'd-none' : '' ?>">
44    <label class="col-form-label col-sm-2" for="folder">
45        <?= I18N::translate('Filename on server') ?>
46    </label>
47    <div class="col-sm-10">
48        <div class="row">
49            <div class="col-sm-6">
50                <div class="form-check">
51                    <label class="form-check-label">
52                        <input class="form-check-input" type="radio" name="auto" value="0" checked>
53                        <input class="form-control" id="folder" name="folder" placeholder="<?= I18N::translate('Folder') ?>" type="text" value="<?= e(dirname($media_file ? $media_file->filename() : '') === '.' ? '' : dirname($media_file ? $media_file->filename() : '')) ?>" data-autocomplete-url="<?= e(route('autocomplete-folder', ['tree' => $tree->name(), 'query' => 'QUERY'])) ?>" autocomplete="off">
54                        <div class="input-group">
55                            <div class="input-group-append">
56                                <span class="input-group-text">/</span>
57                            </div>
58                        </div>
59                    </label>
60                </div>
61            </div>
62            <div class="col-sm-6">
63                <input class="form-control" name="new_file" type="text" placeholder="<?= I18N::translate('Same as uploaded file') ?>" value="<?= e(basename($media_file ? $media_file->filename() : '')) ?>">
64            </div>
65        </div>
66        <p class="small text-muted">
67            <?= I18N::translate('If you have a large number of media files, you can organize them into folders and subfolders.') ?>
68        </p>
69        <div class="form-check">
70            <label class="form-check-label">
71                <input class="form-check-input" type="radio" name="auto" value="1">
72                <?= I18N::translate('Create a unique filename') ?>
73            </label>
74        </div>
75    </div>
76</div>
77
78<div class="form-group row file-location file-location-unused d-none">
79    <label class="col-form-label col-sm-2" for="unused">
80        <?= I18N::translate('A file on the server') ?>
81    </label>
82    <div class="col-sm-10">
83        <?= view('components/select', ['name' => 'unused', 'selected' => '', 'options' => $unused_files]) ?>
84        <small class="text-muted">
85        </small>
86    </div>
87</div>
88
89<div class="form-group row file-location file-location-url <?= $media_file && $media_file->isExternal() ? '' : 'd-none' ?>">
90    <label class="col-form-label col-sm-2" for="remote">
91        <?= I18N::translate('URL') ?>
92    </label>
93    <div class="col-sm-10">
94        <input class="form-control" type="url" id="remote" name="remote" placeholder="https://www.example.com/photo.jpeg" value="<?= e($media_file && $media_file->isExternal() ? $media_file->filename() : '') ?>">
95        <small class="text-muted">
96            <?= view('icons/warning') ?>
97            <span class="sr-only"><?= I18N::translate('Caution!') ?></span>
98
99            <?= I18N::translate('The GEDCOM standard does not allow URLs in media objects.') ?>
100            <?= I18N::translate('Other genealogy applications might not recognize this data.') ?>
101        </small>
102    </div>
103</div>
104
105<div class="form-group row">
106    <label class="col-form-label col-sm-2" for="title">
107        <?= I18N::translate('Title') ?>
108    </label>
109    <div class="col-sm-10">
110        <input class="form-control" id="title" name="title" type="text" value="<?= e($media_file ? $media_file->title() : '') ?>">
111    </div>
112</div>
113
114<div class="form-group row">
115    <label class="col-form-label col-sm-2" for="type">
116        <?= I18N::translate('Media type') ?>
117    </label>
118    <div class="col-sm-10">
119        <?= view('components/select', ['name' => 'type', 'selected' => $media_file ? $media_file->type() : '', 'options' => ['' => ''] + GedcomTag::getFileFormTypes()]) ?>
120    </div>
121</div>
122
123<script>
124    webtrees.autocomplete('#folder');
125    document.getElementById('file-location').addEventListener('change', function () {
126        document.querySelectorAll('.file-location').forEach(function (element) {
127            element.classList.add('d-none');
128        });
129        document.querySelector('.file-location-' + this.value).classList.remove('d-none');
130    });
131</script>
132