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