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() ?> 5*aa6f03bbSGreg 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 18dd6b2bfcSGreg Roach document.getElementById('wt-modal-form').addEventListener('submit', function(event) { 19dd6b2bfcSGreg Roach event.preventDefault(); 20dd6b2bfcSGreg Roach let form = event.target; 21dd6b2bfcSGreg 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. 36dd6b2bfcSGreg Roach $(select) 37dd6b2bfcSGreg Roach .select2() 38dd6b2bfcSGreg Roach .empty() 39dd6b2bfcSGreg Roach .append(new Option(data.text, data.id)).val(data.id) 40dd6b2bfcSGreg Roach .trigger('change'); 41dd6b2bfcSGreg Roach 42dd6b2bfcSGreg Roach $('#wt-ajax-modal').modal('hide'); 43dd6b2bfcSGreg Roach } else { 44dd6b2bfcSGreg Roach modal_content.innerHTML = data.html; 45dd6b2bfcSGreg Roach } 46dd6b2bfcSGreg Roach }, 47dd6b2bfcSGreg Roach failure: function (data) { 48dd6b2bfcSGreg Roach modal_content.innerHTML = data.html; 49dd6b2bfcSGreg Roach } 50dd6b2bfcSGreg Roach }); 51dd6b2bfcSGreg Roach }); 52dd6b2bfcSGreg Roach</script> 53