From eae0c753bb24d324db2a566ebf8f30d2b6314570 Mon Sep 17 00:00:00 2001 From: Piyush Vijay Date: Fri, 27 Jul 2018 18:21:14 +0530 Subject: [PATCH] Add prepare_ajax_request and preview_sql to modular code. Signed-Off-By: Piyush Vijay --- js/src/functions/AjaxRequest.js | 11 ++++++ js/src/functions/Sql/PreviewSql.js | 54 ++++++++++++++++++++++++++++++ 2 files changed, 65 insertions(+) create mode 100644 js/src/functions/AjaxRequest.js create mode 100644 js/src/functions/Sql/PreviewSql.js diff --git a/js/src/functions/AjaxRequest.js b/js/src/functions/AjaxRequest.js new file mode 100644 index 0000000000..1786446074 --- /dev/null +++ b/js/src/functions/AjaxRequest.js @@ -0,0 +1,11 @@ +/** + * Add a hidden field to the form to indicate that this will be an + * Ajax request (only if this hidden field does not exist) + * + * @param $form object the form + */ +export function PMA_prepareForAjaxRequest ($form) { + if (! $form.find('input:hidden').is('#ajax_request_hidden')) { + $form.append(''); + } +} diff --git a/js/src/functions/Sql/PreviewSql.js b/js/src/functions/Sql/PreviewSql.js new file mode 100644 index 0000000000..dac3acf560 --- /dev/null +++ b/js/src/functions/Sql/PreviewSql.js @@ -0,0 +1,54 @@ +import { PMA_Messages as PMA_messages } from '../../variables/export_variables'; +import PMA_commonParams from '../../variables/common_params'; +import { PMA_ajaxShowMessage, PMA_ajaxRemoveMessage } from '../../utils/show_ajax_messages'; +/** + * Requests SQL for previewing before executing. + * + * @param jQuery Object $form Form containing query data + * + * @return void + */ +export function PMA_previewSQL ($form) { + var form_url = $form.attr('action'); + var sep = PMA_commonParams.get('arg_separator'); + var form_data = $form.serialize() + + sep + 'do_save_data=1' + + sep + 'preview_sql=1' + + sep + 'ajax_request=1'; + var $msgbox = PMA_ajaxShowMessage(); + $.ajax({ + type: 'POST', + url: form_url, + data: form_data, + success: function (response) { + PMA_ajaxRemoveMessage($msgbox); + if (response.success) { + var $dialog_content = $('
') + .append(response.sql_data); + var button_options = {}; + button_options[PMA_messages.strClose] = function () { + $(this).dialog('close'); + }; + var $response_dialog = $dialog_content.dialog({ + minWidth: 550, + maxHeight: 400, + modal: true, + buttons: button_options, + title: PMA_messages.strPreviewSQL, + close: function () { + $(this).remove(); + }, + open: function () { + // Pretty SQL printing. + PMA_highlightSQL($(this)); + } + }); + } else { + PMA_ajaxShowMessage(response.message); + } + }, + error: function () { + PMA_ajaxShowMessage(PMA_messages.strErrorProcessingRequest); + } + }); +}