xref: /webtrees/resources/views/modals/media-file-fields.phtml (revision d4786c66945cca20d5ce34ac3cf08cf5a5110ae2)
1d70512abSGreg Roach<?php
2d70512abSGreg Roach
363763244SGreg Roachuse Fisharebest\Webtrees\Http\RequestHandlers\AutoCompleteFolder;
42cf1b3d7SGreg Roachuse Fisharebest\Webtrees\I18N;
5696f5b06SGreg Roachuse Fisharebest\Webtrees\MediaFile;
6696f5b06SGreg Roachuse Fisharebest\Webtrees\Tree;
7696f5b06SGreg Roach
8696f5b06SGreg Roach/**
9696f5b06SGreg Roach * @var string                   $max_upload_size
10696f5b06SGreg Roach * @var MediaFile|null           $media_file
11455a30feSGreg Roach * @var array<int|string,string> $media_types
12696f5b06SGreg Roach * @var Tree                     $tree
13696f5b06SGreg Roach * @var array<string,string>     $unused_files
14696f5b06SGreg Roach */
15d70512abSGreg Roach
16d70512abSGreg Roach?>
17dd6b2bfcSGreg Roach
18315eb316SGreg Roach<div class="row form-group <?= $media_file instanceof MediaFile ? 'd-none' : '' ?>">
19dd6b2bfcSGreg Roach    <label class="col-form-label col-sm-2" for="file-location">
20dd6b2bfcSGreg Roach        <?= I18N::translate('Media file') ?>
21dd6b2bfcSGreg Roach    </label>
22dd6b2bfcSGreg Roach    <div class="col-sm-10">
23dd6b2bfcSGreg Roach        <select class="form-control" id="file-location" name="file_location">
24dd6b2bfcSGreg Roach            <option value="upload">
25dd6b2bfcSGreg Roach                <?= I18N::translate('A file on your computer') ?>
26dd6b2bfcSGreg Roach            </option>
27dd6b2bfcSGreg Roach            <?php if (!empty($unused_files)) : ?>
28dd6b2bfcSGreg Roach            <option value="unused">
29dd6b2bfcSGreg Roach                <?= I18N::translate('A file on the server') ?>
30dd6b2bfcSGreg Roach            </option>
31dd6b2bfcSGreg Roach            <?php endif ?>
32dd6b2bfcSGreg Roach            <option value="url">
33dd6b2bfcSGreg Roach                <?= /* I18N: URL = web address */ I18N::translate('A URL') ?>
34dd6b2bfcSGreg Roach            </option>
35dd6b2bfcSGreg Roach        </select>
36dd6b2bfcSGreg Roach    </div>
37dd6b2bfcSGreg Roach</div>
38dd6b2bfcSGreg Roach
39315eb316SGreg Roach<div class="row form-group file-location file-location-upload <?= $media_file instanceof MediaFile ? 'd-none' : '' ?>">
40dd6b2bfcSGreg Roach    <label class="col-form-label col-sm-2" for="file">
41dd6b2bfcSGreg Roach        <?= I18N::translate('A file on your computer') ?>
42dd6b2bfcSGreg Roach    </label>
43dd6b2bfcSGreg Roach    <div class="col-sm-10">
448303bc50SGreg Roach        <input class="form-control-file" id="file" name="file" type="file">
45dd6b2bfcSGreg Roach        <small class="text-muted">
46dd6b2bfcSGreg Roach            <?= I18N::translate('Maximum upload size: ') ?>
47dd6b2bfcSGreg Roach            <?= $max_upload_size ?>
48dd6b2bfcSGreg Roach        </small>
49dd6b2bfcSGreg Roach    </div>
50dd6b2bfcSGreg Roach</div>
51dd6b2bfcSGreg Roach
52315eb316SGreg Roach<div class="row form-group file-location file-location-upload <?= $media_file instanceof MediaFile && $media_file->isExternal() ? 'd-none' : '' ?>">
53dd6b2bfcSGreg Roach    <label class="col-form-label col-sm-2" for="folder">
54dd6b2bfcSGreg Roach        <?= I18N::translate('Filename on server') ?>
55dd6b2bfcSGreg Roach    </label>
56dd6b2bfcSGreg Roach    <div class="col-sm-10">
57dd6b2bfcSGreg Roach        <div class="row">
58dd6b2bfcSGreg Roach            <div class="col-sm-6">
59dd6b2bfcSGreg Roach                <div class="form-check">
60dd6b2bfcSGreg Roach                    <label class="form-check-label">
61696f5b06SGreg Roach                        <span class="input-group">
62dd6b2bfcSGreg Roach                            <input class="form-check-input" type="radio" name="auto" value="0" checked>
63*d4786c66SGreg 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">
64dd6b2bfcSGreg Roach                            <span class="input-group-text">/</span>
65696f5b06SGreg Roach                        </span>
66dd6b2bfcSGreg Roach                    </label>
67dd6b2bfcSGreg Roach                </div>
68dd6b2bfcSGreg Roach            </div>
69dd6b2bfcSGreg Roach            <div class="col-sm-6">
70696f5b06SGreg 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() : '')) ?>">
71dd6b2bfcSGreg Roach            </div>
72dd6b2bfcSGreg Roach        </div>
73315eb316SGreg Roach        <div class="form-text">
74dd6b2bfcSGreg Roach            <?= I18N::translate('If you have a large number of media files, you can organize them into folders and subfolders.') ?>
75315eb316SGreg Roach        </div>
76dd6b2bfcSGreg Roach        <div class="form-check">
77dd6b2bfcSGreg Roach            <label class="form-check-label">
78dd6b2bfcSGreg Roach                <input class="form-check-input" type="radio" name="auto" value="1">
79dd6b2bfcSGreg Roach                <?= I18N::translate('Create a unique filename') ?>
80dd6b2bfcSGreg Roach            </label>
81dd6b2bfcSGreg Roach        </div>
82dd6b2bfcSGreg Roach    </div>
83dd6b2bfcSGreg Roach</div>
84dd6b2bfcSGreg Roach
85315eb316SGreg Roach<div class="row form-group file-location file-location-unused d-none">
86dd6b2bfcSGreg Roach    <label class="col-form-label col-sm-2" for="unused">
87dd6b2bfcSGreg Roach        <?= I18N::translate('A file on the server') ?>
88dd6b2bfcSGreg Roach    </label>
89dd6b2bfcSGreg Roach    <div class="col-sm-10">
90c9e11c2aSGreg Roach        <?= view('components/select', ['name' => 'unused', 'selected' => '', 'options' => $unused_files]) ?>
91dd6b2bfcSGreg Roach        <small class="text-muted">
92dd6b2bfcSGreg Roach        </small>
93dd6b2bfcSGreg Roach    </div>
94dd6b2bfcSGreg Roach</div>
95dd6b2bfcSGreg Roach
96315eb316SGreg Roach<div class="row form-group file-location file-location-url <?= $media_file && $media_file->isExternal() ? '' : 'd-none' ?>">
97dd6b2bfcSGreg Roach    <label class="col-form-label col-sm-2" for="remote">
98dd6b2bfcSGreg Roach        <?= I18N::translate('URL') ?>
99dd6b2bfcSGreg Roach    </label>
100dd6b2bfcSGreg Roach    <div class="col-sm-10">
101dd6b2bfcSGreg 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() : '') ?>">
102dd6b2bfcSGreg Roach    </div>
103dd6b2bfcSGreg Roach</div>
104dd6b2bfcSGreg Roach
105315eb316SGreg Roach<div class="row form-group">
106dd6b2bfcSGreg Roach    <label class="col-form-label col-sm-2" for="title">
107dd6b2bfcSGreg Roach        <?= I18N::translate('Title') ?>
108dd6b2bfcSGreg Roach    </label>
109dd6b2bfcSGreg Roach    <div class="col-sm-10">
110dd6b2bfcSGreg Roach        <input class="form-control" id="title" name="title" type="text" value="<?= e($media_file ? $media_file->title() : '') ?>">
111dd6b2bfcSGreg Roach    </div>
112dd6b2bfcSGreg Roach</div>
113dd6b2bfcSGreg Roach
114315eb316SGreg Roach<div class="row form-group">
115dd6b2bfcSGreg Roach    <label class="col-form-label col-sm-2" for="type">
116dd6b2bfcSGreg Roach        <?= I18N::translate('Media type') ?>
117dd6b2bfcSGreg Roach    </label>
118dd6b2bfcSGreg Roach    <div class="col-sm-10">
119455a30feSGreg Roach        <?= view('components/select', ['name' => 'type', 'selected' => $media_file ? $media_file->type() : '', 'options' => $media_types]) ?>
120dd6b2bfcSGreg Roach    </div>
121dd6b2bfcSGreg Roach</div>
122dd6b2bfcSGreg Roach
123dd6b2bfcSGreg Roach<script>
1242cf1b3d7SGreg Roach    webtrees.autocomplete('#folder');
125dd6b2bfcSGreg Roach    document.getElementById('file-location').addEventListener('change', function () {
12620ccd96cSGreg Roach        document.querySelectorAll('.file-location').forEach((e) => e.classList.add('d-none'));
12720ccd96cSGreg Roach        document.querySelectorAll('.file-location-' + this.value).forEach((e) => e.classList.remove('d-none'));
128dd6b2bfcSGreg Roach    });
129dd6b2bfcSGreg Roach</script>
130