xref: /webtrees/resources/views/modals/media-file-fields.phtml (revision 63763244e313b0e5dc598319721f6a7aa399e128)
1d70512abSGreg Roach<?php
2d70512abSGreg Roach
3d70512abSGreg Roachuse Fisharebest\Webtrees\GedcomTag;
4*63763244SGreg Roachuse Fisharebest\Webtrees\Http\RequestHandlers\AutoCompleteFolder;
52cf1b3d7SGreg Roachuse Fisharebest\Webtrees\I18N;
6d70512abSGreg Roach
7d70512abSGreg Roach?>
82cf1b3d7SGreg Roach<?php ?>
9dd6b2bfcSGreg Roach
10dd6b2bfcSGreg Roach<div class="form-group row <?= $media_file ? 'd-none' : '' ?>">
11dd6b2bfcSGreg Roach    <label class="col-form-label col-sm-2" for="file-location">
12dd6b2bfcSGreg Roach        <?= I18N::translate('Media file') ?>
13dd6b2bfcSGreg Roach    </label>
14dd6b2bfcSGreg Roach    <div class="col-sm-10">
15dd6b2bfcSGreg Roach        <select class="form-control" id="file-location" name="file_location">
16dd6b2bfcSGreg Roach            <option value="upload">
17dd6b2bfcSGreg Roach                <?= I18N::translate('A file on your computer') ?>
18dd6b2bfcSGreg Roach            </option>
19dd6b2bfcSGreg Roach            <?php if (!empty($unused_files)) : ?>
20dd6b2bfcSGreg Roach            <option value="unused">
21dd6b2bfcSGreg Roach                <?= I18N::translate('A file on the server') ?>
22dd6b2bfcSGreg Roach            </option>
23dd6b2bfcSGreg Roach            <?php endif ?>
24dd6b2bfcSGreg Roach            <option value="url">
25dd6b2bfcSGreg Roach                <?= /* I18N: URL = web address */ I18N::translate('A URL') ?>
26dd6b2bfcSGreg Roach            </option>
27dd6b2bfcSGreg Roach        </select>
28dd6b2bfcSGreg Roach    </div>
29dd6b2bfcSGreg Roach</div>
30dd6b2bfcSGreg Roach
31dd6b2bfcSGreg Roach<div class="form-group row file-location file-location-upload <?= $media_file ? 'd-none' : '' ?>">
32dd6b2bfcSGreg Roach    <label class="col-form-label col-sm-2" for="file">
33dd6b2bfcSGreg Roach        <?= I18N::translate('A file on your computer') ?>
34dd6b2bfcSGreg Roach    </label>
35dd6b2bfcSGreg Roach    <div class="col-sm-10">
36dd6b2bfcSGreg Roach        <input class="form-control" id="file" name="file" type="file">
37dd6b2bfcSGreg Roach        <small class="text-muted">
38dd6b2bfcSGreg Roach            <?= I18N::translate('Maximum upload size: ') ?>
39dd6b2bfcSGreg Roach            <?= $max_upload_size ?>
40dd6b2bfcSGreg Roach        </small>
41dd6b2bfcSGreg Roach    </div>
42dd6b2bfcSGreg Roach</div>
43dd6b2bfcSGreg Roach
44dd6b2bfcSGreg Roach<div class="form-group row file-location file-location-upload <?= $media_file && $media_file->isExternal() ? 'd-none' : '' ?>">
45dd6b2bfcSGreg Roach    <label class="col-form-label col-sm-2" for="folder">
46dd6b2bfcSGreg Roach        <?= I18N::translate('Filename on server') ?>
47dd6b2bfcSGreg Roach    </label>
48dd6b2bfcSGreg Roach    <div class="col-sm-10">
49dd6b2bfcSGreg Roach        <div class="row">
50dd6b2bfcSGreg Roach            <div class="col-sm-6">
51dd6b2bfcSGreg Roach                <div class="form-check">
52dd6b2bfcSGreg Roach                    <label class="form-check-label">
53dd6b2bfcSGreg Roach                        <input class="form-check-input" type="radio" name="auto" value="0" checked>
54*63763244SGreg Roach                        <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(AutoCompleteFolder::class, ['tree' => $tree->name()])) ?>" autocomplete="off">
55dd6b2bfcSGreg Roach                        <div class="input-group">
56dd6b2bfcSGreg Roach                            <div class="input-group-append">
57dd6b2bfcSGreg Roach                                <span class="input-group-text">/</span>
58dd6b2bfcSGreg Roach                            </div>
59dd6b2bfcSGreg Roach                        </div>
60dd6b2bfcSGreg Roach                    </label>
61dd6b2bfcSGreg Roach                </div>
62dd6b2bfcSGreg Roach            </div>
63dd6b2bfcSGreg Roach            <div class="col-sm-6">
6442f5d4a5SGreg Roach                <input class="form-control" name="new_file" type="text" placeholder="<?= I18N::translate('Same as uploaded file') ?>" value="<?= e(basename($media_file ? $media_file->filename() : '')) ?>">
65dd6b2bfcSGreg Roach            </div>
66dd6b2bfcSGreg Roach        </div>
67dd6b2bfcSGreg Roach        <p class="small text-muted">
68dd6b2bfcSGreg Roach            <?= I18N::translate('If you have a large number of media files, you can organize them into folders and subfolders.') ?>
69dd6b2bfcSGreg Roach        </p>
70dd6b2bfcSGreg Roach        <div class="form-check">
71dd6b2bfcSGreg Roach            <label class="form-check-label">
72dd6b2bfcSGreg Roach                <input class="form-check-input" type="radio" name="auto" value="1">
73dd6b2bfcSGreg Roach                <?= I18N::translate('Create a unique filename') ?>
74dd6b2bfcSGreg Roach            </label>
75dd6b2bfcSGreg Roach        </div>
76dd6b2bfcSGreg Roach    </div>
77dd6b2bfcSGreg Roach</div>
78dd6b2bfcSGreg Roach
79dd6b2bfcSGreg Roach<div class="form-group row file-location file-location-unused d-none">
80dd6b2bfcSGreg Roach    <label class="col-form-label col-sm-2" for="unused">
81dd6b2bfcSGreg Roach        <?= I18N::translate('A file on the server') ?>
82dd6b2bfcSGreg Roach    </label>
83dd6b2bfcSGreg Roach    <div class="col-sm-10">
84c9e11c2aSGreg Roach        <?= view('components/select', ['name' => 'unused', 'selected' => '', 'options' => $unused_files]) ?>
85dd6b2bfcSGreg Roach        <small class="text-muted">
86dd6b2bfcSGreg Roach        </small>
87dd6b2bfcSGreg Roach    </div>
88dd6b2bfcSGreg Roach</div>
89dd6b2bfcSGreg Roach
90dd6b2bfcSGreg Roach<div class="form-group row file-location file-location-url <?= $media_file && $media_file->isExternal() ? '' : 'd-none' ?>">
91dd6b2bfcSGreg Roach    <label class="col-form-label col-sm-2" for="remote">
92dd6b2bfcSGreg Roach        <?= I18N::translate('URL') ?>
93dd6b2bfcSGreg Roach    </label>
94dd6b2bfcSGreg Roach    <div class="col-sm-10">
95dd6b2bfcSGreg 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() : '') ?>">
96dd6b2bfcSGreg Roach    </div>
97dd6b2bfcSGreg Roach</div>
98dd6b2bfcSGreg Roach
99dd6b2bfcSGreg Roach<div class="form-group row">
100dd6b2bfcSGreg Roach    <label class="col-form-label col-sm-2" for="title">
101dd6b2bfcSGreg Roach        <?= I18N::translate('Title') ?>
102dd6b2bfcSGreg Roach    </label>
103dd6b2bfcSGreg Roach    <div class="col-sm-10">
104dd6b2bfcSGreg Roach        <input class="form-control" id="title" name="title" type="text" value="<?= e($media_file ? $media_file->title() : '') ?>">
105dd6b2bfcSGreg Roach    </div>
106dd6b2bfcSGreg Roach</div>
107dd6b2bfcSGreg Roach
108dd6b2bfcSGreg Roach<div class="form-group row">
109dd6b2bfcSGreg Roach    <label class="col-form-label col-sm-2" for="type">
110dd6b2bfcSGreg Roach        <?= I18N::translate('Media type') ?>
111dd6b2bfcSGreg Roach    </label>
112dd6b2bfcSGreg Roach    <div class="col-sm-10">
113c9e11c2aSGreg Roach        <?= view('components/select', ['name' => 'type', 'selected' => $media_file ? $media_file->type() : '', 'options' => ['' => ''] + GedcomTag::getFileFormTypes()]) ?>
114dd6b2bfcSGreg Roach    </div>
115dd6b2bfcSGreg Roach</div>
116dd6b2bfcSGreg Roach
117dd6b2bfcSGreg Roach<script>
1182cf1b3d7SGreg Roach    webtrees.autocomplete('#folder');
119dd6b2bfcSGreg Roach    document.getElementById('file-location').addEventListener('change', function () {
1202cf1b3d7SGreg Roach        document.querySelectorAll('.file-location').forEach(function (element) {
1212cf1b3d7SGreg Roach            element.classList.add('d-none');
1222cf1b3d7SGreg Roach        });
1232cf1b3d7SGreg Roach        document.querySelector('.file-location-' + this.value).classList.remove('d-none');
124dd6b2bfcSGreg Roach    });
125dd6b2bfcSGreg Roach</script>
126