xref: /webtrees/resources/views/modals/media-file-fields.phtml (revision 10e0649788c8d7d4974d81c048ca2b225df8f22e)
1d70512abSGreg Roach<?php
2d70512abSGreg Roach
3*10e06497SGreg Roachdeclare(strict_types=1);
4*10e06497SGreg Roach
5acb90a38SGreg Roachuse Fisharebest\Webtrees\Elements\SourceMediaType;
663763244SGreg Roachuse Fisharebest\Webtrees\Http\RequestHandlers\AutoCompleteFolder;
72cf1b3d7SGreg Roachuse Fisharebest\Webtrees\I18N;
8696f5b06SGreg Roachuse Fisharebest\Webtrees\MediaFile;
9696f5b06SGreg Roachuse Fisharebest\Webtrees\Tree;
10696f5b06SGreg Roach
11696f5b06SGreg Roach/**
12696f5b06SGreg Roach * @var string                   $max_upload_size
13696f5b06SGreg Roach * @var MediaFile|null           $media_file
14455a30feSGreg Roach * @var array<int|string,string> $media_types
15696f5b06SGreg Roach * @var Tree                     $tree
16696f5b06SGreg Roach * @var array<string,string>     $unused_files
17696f5b06SGreg Roach */
18d70512abSGreg Roach
19d70512abSGreg Roach?>
20dd6b2bfcSGreg Roach
219e3c2cf9SGreg Roach<div class="row <?= $media_file instanceof MediaFile ? 'd-none' : '' ?>">
22dd6b2bfcSGreg Roach    <label class="col-form-label col-sm-2" for="file-location">
23dd6b2bfcSGreg Roach        <?= I18N::translate('Media file') ?>
24dd6b2bfcSGreg Roach    </label>
25dd6b2bfcSGreg Roach    <div class="col-sm-10">
264b9213b3SGreg Roach        <select class="form-select" id="file-location" name="file_location">
27dd6b2bfcSGreg Roach            <option value="upload">
28dd6b2bfcSGreg Roach                <?= I18N::translate('A file on your computer') ?>
29dd6b2bfcSGreg Roach            </option>
30dd6b2bfcSGreg Roach            <?php if (!empty($unused_files)) : ?>
31dd6b2bfcSGreg Roach            <option value="unused">
32dd6b2bfcSGreg Roach                <?= I18N::translate('A file on the server') ?>
33dd6b2bfcSGreg Roach            </option>
34dd6b2bfcSGreg Roach            <?php endif ?>
35dd6b2bfcSGreg Roach            <option value="url">
36dd6b2bfcSGreg Roach                <?= /* I18N: URL = web address */ I18N::translate('A URL') ?>
37dd6b2bfcSGreg Roach            </option>
38dd6b2bfcSGreg Roach        </select>
39dd6b2bfcSGreg Roach    </div>
40dd6b2bfcSGreg Roach</div>
41dd6b2bfcSGreg Roach
429e3c2cf9SGreg Roach<div class="row file-location file-location-upload <?= $media_file instanceof MediaFile ? 'd-none' : '' ?>">
43dd6b2bfcSGreg Roach    <label class="col-form-label col-sm-2" for="file">
44dd6b2bfcSGreg Roach        <?= I18N::translate('A file on your computer') ?>
45dd6b2bfcSGreg Roach    </label>
46dd6b2bfcSGreg Roach    <div class="col-sm-10">
479e3c2cf9SGreg Roach        <input class="form-control" id="file" name="file" type="file">
48dd6b2bfcSGreg Roach        <small class="text-muted">
49dd6b2bfcSGreg Roach            <?= I18N::translate('Maximum upload size: ') ?>
50dd6b2bfcSGreg Roach            <?= $max_upload_size ?>
51dd6b2bfcSGreg Roach        </small>
52dd6b2bfcSGreg Roach    </div>
53dd6b2bfcSGreg Roach</div>
54dd6b2bfcSGreg Roach
559e3c2cf9SGreg Roach<div class="row file-location file-location-upload <?= $media_file instanceof MediaFile && $media_file->isExternal() ? 'd-none' : '' ?>">
56dd6b2bfcSGreg Roach    <label class="col-form-label col-sm-2" for="folder">
57dd6b2bfcSGreg Roach        <?= I18N::translate('Filename on server') ?>
58dd6b2bfcSGreg Roach    </label>
59dd6b2bfcSGreg Roach    <div class="col-sm-10">
60dd6b2bfcSGreg Roach        <div class="row">
61dd6b2bfcSGreg Roach            <div class="col-sm-6">
62dd6b2bfcSGreg Roach                <div class="form-check">
632729bcd2SGreg Roach                    <input class="form-check-input" type="radio" name="auto" id="filename-manual" value="0" checked>
642729bcd2SGreg Roach                    <label class="form-check-label input-group" for="filename-manual">
65d4786c66SGreg Roach                        <input class="form-control" id="folder" name="folder" placeholder="<?= I18N::translate('Folder') ?>" type="text" value="<?= e(dirname($media_file instanceof MediaFile ? $media_file->filename() : '') === '.' ? '' : dirname($media_file instanceof MediaFile ? $media_file->filename() : '')) ?>" data-wt-autocomplete-url="<?= e(route(AutoCompleteFolder::class, ['tree' => $tree->name()])) ?>" autocomplete="off">
66dd6b2bfcSGreg Roach                        <span class="input-group-text">/</span>
67dd6b2bfcSGreg Roach                    </label>
68dd6b2bfcSGreg Roach                </div>
69dd6b2bfcSGreg Roach            </div>
70dd6b2bfcSGreg Roach            <div class="col-sm-6">
71696f5b06SGreg Roach                <input aria-label="<?= I18N::translate('Filename') ?>" class="form-control" name="new_file" type="text" placeholder="<?= I18N::translate('Same as uploaded file') ?>" value="<?= e(basename($media_file ? $media_file->filename() : '')) ?>">
72dd6b2bfcSGreg Roach            </div>
73dd6b2bfcSGreg Roach        </div>
74315eb316SGreg Roach        <div class="form-text">
75dd6b2bfcSGreg Roach            <?= I18N::translate('If you have a large number of media files, you can organize them into folders and subfolders.') ?>
76315eb316SGreg Roach        </div>
77dd6b2bfcSGreg Roach        <div class="form-check">
782729bcd2SGreg Roach            <input class="form-check-input" type="radio" name="auto" id="filename-auto" value="1">
792729bcd2SGreg Roach            <label class="form-check-label" for="filename-auto">
80dd6b2bfcSGreg Roach                <?= I18N::translate('Create a unique filename') ?>
81dd6b2bfcSGreg Roach            </label>
82dd6b2bfcSGreg Roach        </div>
83dd6b2bfcSGreg Roach    </div>
84dd6b2bfcSGreg Roach</div>
85dd6b2bfcSGreg Roach
869e3c2cf9SGreg Roach<div class="row file-location file-location-unused d-none">
87dd6b2bfcSGreg Roach    <label class="col-form-label col-sm-2" for="unused">
88dd6b2bfcSGreg Roach        <?= I18N::translate('A file on the server') ?>
89dd6b2bfcSGreg Roach    </label>
90dd6b2bfcSGreg Roach    <div class="col-sm-10">
91c9e11c2aSGreg Roach        <?= view('components/select', ['name' => 'unused', 'selected' => '', 'options' => $unused_files]) ?>
92dd6b2bfcSGreg Roach        <small class="text-muted">
93dd6b2bfcSGreg Roach        </small>
94dd6b2bfcSGreg Roach    </div>
95dd6b2bfcSGreg Roach</div>
96dd6b2bfcSGreg Roach
979e3c2cf9SGreg Roach<div class="row file-location file-location-url <?= $media_file && $media_file->isExternal() ? '' : 'd-none' ?>">
98dd6b2bfcSGreg Roach    <label class="col-form-label col-sm-2" for="remote">
99dd6b2bfcSGreg Roach        <?= I18N::translate('URL') ?>
100dd6b2bfcSGreg Roach    </label>
101dd6b2bfcSGreg Roach    <div class="col-sm-10">
102dd6b2bfcSGreg Roach        <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() : '') ?>">
103dd6b2bfcSGreg Roach    </div>
104dd6b2bfcSGreg Roach</div>
105dd6b2bfcSGreg Roach
1069e3c2cf9SGreg Roach<div class="row mb-3">
107dd6b2bfcSGreg Roach    <label class="col-form-label col-sm-2" for="title">
108dd6b2bfcSGreg Roach        <?= I18N::translate('Title') ?>
109dd6b2bfcSGreg Roach    </label>
110dd6b2bfcSGreg Roach    <div class="col-sm-10">
111dd6b2bfcSGreg Roach        <input class="form-control" id="title" name="title" type="text" value="<?= e($media_file ? $media_file->title() : '') ?>">
112dd6b2bfcSGreg Roach    </div>
113dd6b2bfcSGreg Roach</div>
114dd6b2bfcSGreg Roach
1159e3c2cf9SGreg Roach<div class="row mb-3">
116dd6b2bfcSGreg Roach    <label class="col-form-label col-sm-2" for="type">
117dd6b2bfcSGreg Roach        <?= I18N::translate('Media type') ?>
118dd6b2bfcSGreg Roach    </label>
119dd6b2bfcSGreg Roach    <div class="col-sm-10">
120acb90a38SGreg Roach        <?= (new SourceMediaType(''))->edit('type', 'type', $media_file ? $media_file->type() : '', $tree) ?>
121dd6b2bfcSGreg Roach    </div>
122dd6b2bfcSGreg Roach</div>
123dd6b2bfcSGreg Roach
124dd6b2bfcSGreg Roach<script>
1252cf1b3d7SGreg Roach    webtrees.autocomplete('#folder');
126dd6b2bfcSGreg Roach    document.getElementById('file-location').addEventListener('change', function () {
12720ccd96cSGreg Roach        document.querySelectorAll('.file-location').forEach((e) => e.classList.add('d-none'));
12820ccd96cSGreg Roach        document.querySelectorAll('.file-location-' + this.value).forEach((e) => e.classList.remove('d-none'));
129dd6b2bfcSGreg Roach    });
130dd6b2bfcSGreg Roach</script>
131