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 18696f5b06SGreg Roach<div class="form-group row <?= $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 39696f5b06SGreg Roach<div class="form-group row 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"> 44*8303bc50SGreg 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 52696f5b06SGreg Roach<div class="form-group row 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> 63696f5b06SGreg 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-autocomplete-url="<?= e(route(AutoCompleteFolder::class, ['tree' => $tree->name()])) ?>" autocomplete="off"> 64696f5b06SGreg Roach <span class="input-group-append"> 65dd6b2bfcSGreg Roach <span class="input-group-text">/</span> 66696f5b06SGreg Roach </span> 67696f5b06SGreg Roach </span> 68dd6b2bfcSGreg Roach </label> 69dd6b2bfcSGreg Roach </div> 70dd6b2bfcSGreg Roach </div> 71dd6b2bfcSGreg Roach <div class="col-sm-6"> 72696f5b06SGreg 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() : '')) ?>"> 73dd6b2bfcSGreg Roach </div> 74dd6b2bfcSGreg Roach </div> 75dd6b2bfcSGreg Roach <p class="small text-muted"> 76dd6b2bfcSGreg Roach <?= I18N::translate('If you have a large number of media files, you can organize them into folders and subfolders.') ?> 77dd6b2bfcSGreg Roach </p> 78dd6b2bfcSGreg Roach <div class="form-check"> 79dd6b2bfcSGreg Roach <label class="form-check-label"> 80dd6b2bfcSGreg Roach <input class="form-check-input" type="radio" name="auto" value="1"> 81dd6b2bfcSGreg Roach <?= I18N::translate('Create a unique filename') ?> 82dd6b2bfcSGreg Roach </label> 83dd6b2bfcSGreg Roach </div> 84dd6b2bfcSGreg Roach </div> 85dd6b2bfcSGreg Roach</div> 86dd6b2bfcSGreg Roach 87dd6b2bfcSGreg Roach<div class="form-group row file-location file-location-unused d-none"> 88dd6b2bfcSGreg Roach <label class="col-form-label col-sm-2" for="unused"> 89dd6b2bfcSGreg Roach <?= I18N::translate('A file on the server') ?> 90dd6b2bfcSGreg Roach </label> 91dd6b2bfcSGreg Roach <div class="col-sm-10"> 92c9e11c2aSGreg Roach <?= view('components/select', ['name' => 'unused', 'selected' => '', 'options' => $unused_files]) ?> 93dd6b2bfcSGreg Roach <small class="text-muted"> 94dd6b2bfcSGreg Roach </small> 95dd6b2bfcSGreg Roach </div> 96dd6b2bfcSGreg Roach</div> 97dd6b2bfcSGreg Roach 98dd6b2bfcSGreg Roach<div class="form-group row file-location file-location-url <?= $media_file && $media_file->isExternal() ? '' : 'd-none' ?>"> 99dd6b2bfcSGreg Roach <label class="col-form-label col-sm-2" for="remote"> 100dd6b2bfcSGreg Roach <?= I18N::translate('URL') ?> 101dd6b2bfcSGreg Roach </label> 102dd6b2bfcSGreg Roach <div class="col-sm-10"> 103dd6b2bfcSGreg 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() : '') ?>"> 104dd6b2bfcSGreg Roach </div> 105dd6b2bfcSGreg Roach</div> 106dd6b2bfcSGreg Roach 107dd6b2bfcSGreg Roach<div class="form-group row"> 108dd6b2bfcSGreg Roach <label class="col-form-label col-sm-2" for="title"> 109dd6b2bfcSGreg Roach <?= I18N::translate('Title') ?> 110dd6b2bfcSGreg Roach </label> 111dd6b2bfcSGreg Roach <div class="col-sm-10"> 112dd6b2bfcSGreg Roach <input class="form-control" id="title" name="title" type="text" value="<?= e($media_file ? $media_file->title() : '') ?>"> 113dd6b2bfcSGreg Roach </div> 114dd6b2bfcSGreg Roach</div> 115dd6b2bfcSGreg Roach 116dd6b2bfcSGreg Roach<div class="form-group row"> 117dd6b2bfcSGreg Roach <label class="col-form-label col-sm-2" for="type"> 118dd6b2bfcSGreg Roach <?= I18N::translate('Media type') ?> 119dd6b2bfcSGreg Roach </label> 120dd6b2bfcSGreg Roach <div class="col-sm-10"> 121455a30feSGreg Roach <?= view('components/select', ['name' => 'type', 'selected' => $media_file ? $media_file->type() : '', 'options' => $media_types]) ?> 122dd6b2bfcSGreg Roach </div> 123dd6b2bfcSGreg Roach</div> 124dd6b2bfcSGreg Roach 125dd6b2bfcSGreg Roach<script> 1262cf1b3d7SGreg Roach webtrees.autocomplete('#folder'); 127dd6b2bfcSGreg Roach document.getElementById('file-location').addEventListener('change', function () { 1282cf1b3d7SGreg Roach document.querySelectorAll('.file-location').forEach(function (element) { 1292cf1b3d7SGreg Roach element.classList.add('d-none'); 1302cf1b3d7SGreg Roach }); 1312cf1b3d7SGreg Roach document.querySelector('.file-location-' + this.value).classList.remove('d-none'); 132dd6b2bfcSGreg Roach }); 133dd6b2bfcSGreg Roach</script> 134