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