xref: /webtrees/resources/views/modals/media-file-fields.phtml (revision 4b9213b33377fa752da3c34c8057f8662b73fd24)
1d70512abSGreg Roach<?php
2d70512abSGreg Roach
3acb90a38SGreg Roachuse Fisharebest\Webtrees\Elements\SourceMediaType;
463763244SGreg Roachuse Fisharebest\Webtrees\Http\RequestHandlers\AutoCompleteFolder;
52cf1b3d7SGreg Roachuse Fisharebest\Webtrees\I18N;
6696f5b06SGreg Roachuse Fisharebest\Webtrees\MediaFile;
7696f5b06SGreg Roachuse Fisharebest\Webtrees\Tree;
8696f5b06SGreg Roach
9696f5b06SGreg Roach/**
10696f5b06SGreg Roach * @var string                   $max_upload_size
11696f5b06SGreg Roach * @var MediaFile|null           $media_file
12455a30feSGreg Roach * @var array<int|string,string> $media_types
13696f5b06SGreg Roach * @var Tree                     $tree
14696f5b06SGreg Roach * @var array<string,string>     $unused_files
15696f5b06SGreg Roach */
16d70512abSGreg Roach
17d70512abSGreg Roach?>
18dd6b2bfcSGreg Roach
199e3c2cf9SGreg Roach<div class="row <?= $media_file instanceof MediaFile ? 'd-none' : '' ?>">
20dd6b2bfcSGreg Roach    <label class="col-form-label col-sm-2" for="file-location">
21dd6b2bfcSGreg Roach        <?= I18N::translate('Media file') ?>
22dd6b2bfcSGreg Roach    </label>
23dd6b2bfcSGreg Roach    <div class="col-sm-10">
24*4b9213b3SGreg Roach        <select class="form-select" id="file-location" name="file_location">
25dd6b2bfcSGreg Roach            <option value="upload">
26dd6b2bfcSGreg Roach                <?= I18N::translate('A file on your computer') ?>
27dd6b2bfcSGreg Roach            </option>
28dd6b2bfcSGreg Roach            <?php if (!empty($unused_files)) : ?>
29dd6b2bfcSGreg Roach            <option value="unused">
30dd6b2bfcSGreg Roach                <?= I18N::translate('A file on the server') ?>
31dd6b2bfcSGreg Roach            </option>
32dd6b2bfcSGreg Roach            <?php endif ?>
33dd6b2bfcSGreg Roach            <option value="url">
34dd6b2bfcSGreg Roach                <?= /* I18N: URL = web address */ I18N::translate('A URL') ?>
35dd6b2bfcSGreg Roach            </option>
36dd6b2bfcSGreg Roach        </select>
37dd6b2bfcSGreg Roach    </div>
38dd6b2bfcSGreg Roach</div>
39dd6b2bfcSGreg Roach
409e3c2cf9SGreg Roach<div class="row file-location file-location-upload <?= $media_file instanceof MediaFile ? 'd-none' : '' ?>">
41dd6b2bfcSGreg Roach    <label class="col-form-label col-sm-2" for="file">
42dd6b2bfcSGreg Roach        <?= I18N::translate('A file on your computer') ?>
43dd6b2bfcSGreg Roach    </label>
44dd6b2bfcSGreg Roach    <div class="col-sm-10">
459e3c2cf9SGreg Roach        <input class="form-control" id="file" name="file" type="file">
46dd6b2bfcSGreg Roach        <small class="text-muted">
47dd6b2bfcSGreg Roach            <?= I18N::translate('Maximum upload size: ') ?>
48dd6b2bfcSGreg Roach            <?= $max_upload_size ?>
49dd6b2bfcSGreg Roach        </small>
50dd6b2bfcSGreg Roach    </div>
51dd6b2bfcSGreg Roach</div>
52dd6b2bfcSGreg Roach
539e3c2cf9SGreg Roach<div class="row file-location file-location-upload <?= $media_file instanceof MediaFile && $media_file->isExternal() ? 'd-none' : '' ?>">
54dd6b2bfcSGreg Roach    <label class="col-form-label col-sm-2" for="folder">
55dd6b2bfcSGreg Roach        <?= I18N::translate('Filename on server') ?>
56dd6b2bfcSGreg Roach    </label>
57dd6b2bfcSGreg Roach    <div class="col-sm-10">
58dd6b2bfcSGreg Roach        <div class="row">
59dd6b2bfcSGreg Roach            <div class="col-sm-6">
60dd6b2bfcSGreg Roach                <div class="form-check">
61dd6b2bfcSGreg Roach                    <label class="form-check-label">
62696f5b06SGreg Roach                        <span class="input-group">
63dd6b2bfcSGreg Roach                            <input class="form-check-input" type="radio" name="auto" value="0" checked>
64d4786c66SGreg 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">
65dd6b2bfcSGreg Roach                            <span class="input-group-text">/</span>
66696f5b06SGreg Roach                        </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">
78dd6b2bfcSGreg Roach            <label class="form-check-label">
79dd6b2bfcSGreg Roach                <input class="form-check-input" type="radio" name="auto" value="1">
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