diff --git a/js/src/functions.js b/js/src/functions.js index f618033982..ee563379f3 100644 --- a/js/src/functions.js +++ b/js/src/functions.js @@ -3376,6 +3376,39 @@ AJAX.registerOnload('functions.js', function () { Functions.indexDialogModal = function (routeUrl, url, title, callbackSuccess, callbackFailure) { /* Remove the hidden dialogs if there are*/ var modal = $('#indexDialogModal'); + + const indexDialogPreviewModal = document.getElementById('indexDialogPreviewModal'); + indexDialogPreviewModal.addEventListener('shown.bs.modal', () => { + const modalBody = indexDialogPreviewModal.querySelector('.modal-body'); + const $form = $('#index_frm'); + const formUrl = $form.attr('action'); + const sep = CommonParams.get('arg_separator'); + const formData = $form.serialize() + + sep + 'do_save_data=1' + + sep + 'preview_sql=1' + + sep + 'ajax_request=1'; + $.post({ + url: formUrl, + data: formData, + success: response => { + if (! response.success) { + modalBody.innerHTML = ''; + return; + } + + modalBody.innerHTML = response.sql_data; + Functions.highlightSql($('#indexDialogPreviewModal')); + }, + error: () => { + modalBody.innerHTML = ''; + } + }); + }); + indexDialogPreviewModal.addEventListener('hidden.bs.modal', () => { + indexDialogPreviewModal.querySelector('.modal-body').innerHTML = '
' + + '' + Messages.strLoading + '
'; + }); + /** * @var button_options Object that stores the options * passed to jQueryUI dialog @@ -3427,11 +3460,7 @@ Functions.indexDialogModal = function (routeUrl, url, title, callbackSuccess, ca } }); // end $.post() }); - $('#indexDialogModalPreviewButton').on('click', function () { - // Function for Previewing SQL - var $form = $('#index_frm'); - Functions.previewSql($form); - }); + var $msgbox = Functions.ajaxShowMessage(); $.post(routeUrl, url, function (data) { if (typeof data !== 'undefined' && data.success === false) { diff --git a/templates/modals/index_dialog_modal.twig b/templates/modals/index_dialog_modal.twig index 3649464d3b..a079504763 100644 --- a/templates/modals/index_dialog_modal.twig +++ b/templates/modals/index_dialog_modal.twig @@ -7,10 +7,28 @@ +