1dd6b2bfcSGreg Roach<?php use Fisharebest\Webtrees\I18N; ?> 2dd6b2bfcSGreg Roach 3dd6b2bfcSGreg Roach<form action="<?= e(route('create-repository')) ?>" id="wt-modal-form" method="POST"> 4dd6b2bfcSGreg Roach <?= csrf_field() ?> 5aa6f03bbSGreg Roach <input type="hidden" name="ged" value="<?= e($tree->name()) ?>"> 6dd6b2bfcSGreg Roach 7dd6b2bfcSGreg Roach <?= view('modals/header', ['title' => I18N::translate('Create a repository')]) ?> 8dd6b2bfcSGreg Roach 9dd6b2bfcSGreg Roach <div class="modal-body"> 10dd6b2bfcSGreg Roach <?= view('modals/repository-fields') ?> 11dd6b2bfcSGreg Roach </div> 12dd6b2bfcSGreg Roach 13dd6b2bfcSGreg Roach <?= view('modals/footer-save-cancel') ?> 14dd6b2bfcSGreg Roach</form> 15dd6b2bfcSGreg Roach 16dd6b2bfcSGreg Roach<script> 17dd6b2bfcSGreg Roach // Submit the modal form using AJAX 18*2a12145eSGreg Roach document.getElementById("wt-modal-form").addEventListener("submit", function (event) { 19dd6b2bfcSGreg Roach event.preventDefault(); 20dd6b2bfcSGreg Roach let form = event.target; 21*2a12145eSGreg Roach let modal_content = document.querySelector("#wt-ajax-modal .modal-content"); 22dd6b2bfcSGreg Roach let select = document.getElementById(modal_content.dataset.selectId); 23dd6b2bfcSGreg Roach 24dd6b2bfcSGreg Roach $.ajax({ 25dd6b2bfcSGreg Roach url: form.action, 26dd6b2bfcSGreg Roach type: form.method, 27dd6b2bfcSGreg Roach data: new FormData(form), 28dd6b2bfcSGreg Roach async: false, 29dd6b2bfcSGreg Roach cache: false, 30dd6b2bfcSGreg Roach contentType: false, 31dd6b2bfcSGreg Roach processData: false, 32dd6b2bfcSGreg Roach success: function (data) { 33dd6b2bfcSGreg Roach if (select) { 34dd6b2bfcSGreg Roach // If this modal was activated by the "new" button in a select2 35dd6b2bfcSGreg Roach // edit control, then insert the result and select it. 36*2a12145eSGreg Roach let option = new Option(data.text, data.id, true, true); 37*2a12145eSGreg Roach option.innerHTML = option.innerText; 38*2a12145eSGreg Roach 39dd6b2bfcSGreg Roach $(select) 40dd6b2bfcSGreg Roach .select2() 41dd6b2bfcSGreg Roach .empty() 42*2a12145eSGreg Roach .append(option) 43*2a12145eSGreg Roach .trigger("change"); 44dd6b2bfcSGreg Roach 45*2a12145eSGreg Roach $("#wt-ajax-modal").modal("hide"); 46dd6b2bfcSGreg Roach } else { 47dd6b2bfcSGreg Roach modal_content.innerHTML = data.html; 48dd6b2bfcSGreg Roach } 49dd6b2bfcSGreg Roach }, 50dd6b2bfcSGreg Roach failure: function (data) { 51dd6b2bfcSGreg Roach modal_content.innerHTML = data.html; 52*2a12145eSGreg Roach }, 53dd6b2bfcSGreg Roach }); 54dd6b2bfcSGreg Roach }); 55dd6b2bfcSGreg Roach</script> 56