From 5348e096271c1b76913ce83db150dffdb088b202 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maur=C3=ADcio=20Meneghini=20Fauth?= Date: Fri, 9 Dec 2022 10:47:43 -0300 Subject: [PATCH] Extract Functions.createViewModal() to a module MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: MaurĂ­cio Meneghini Fauth --- js/src/modules/functions.js | 41 +--------------- .../functions/handleCreateViewModal.js | 48 +++++++++++++++++++ js/src/modules/navigation.js | 3 +- 3 files changed, 52 insertions(+), 40 deletions(-) create mode 100644 js/src/modules/functions/handleCreateViewModal.js diff --git a/js/src/modules/functions.js b/js/src/modules/functions.js index cabb89a245..c2177793b1 100644 --- a/js/src/modules/functions.js +++ b/js/src/modules/functions.js @@ -7,6 +7,7 @@ import { Config } from './config.js'; import tooltip from './tooltip.js'; import highlightSql from './sql-highlight.js'; import { ajaxRemoveMessage, ajaxShowMessage } from './ajax-message.js'; +import handleCreateViewModal from './functions/handleCreateViewModal.js'; /* global ChartType, ColumnType, DataTable, JQPlotChartFactory */ // js/chart.js /* global DatabaseStructure */ // js/database/structure.js @@ -3457,7 +3458,7 @@ Functions.onloadCreateView = function () { */ $(document).on('click', 'a.create_view.ajax', function (e) { e.preventDefault(); - Functions.createViewModal($(this)); + handleCreateViewModal($(this)); }); /** * Attach Ajax event handlers for input fields in the editor @@ -3482,44 +3483,6 @@ Functions.onloadCreateView = function () { } }; -Functions.createViewModal = function ($this) { - var $msg = ajaxShowMessage(); - var sep = CommonParams.get('arg_separator'); - var params = Functions.getJsConfirmCommonParam(this, $this.getPostData()); - params += sep + 'ajax_dialog=1'; - $.post($this.attr('href'), params, function (data) { - if (typeof data !== 'undefined' && data.success === true) { - ajaxRemoveMessage($msg); - $('#createViewModalGoButton').on('click', function () { - if (typeof window.CodeMirror !== 'undefined') { - window.codeMirrorEditor.save(); - } - $msg = ajaxShowMessage(); - $.post('index.php?route=/view/create', $('#createViewModal').find('form').serialize(), function (data) { - ajaxRemoveMessage($msg); - if (typeof data !== 'undefined' && data.success === true) { - $('#createViewModal').modal('hide'); - $('.result_query').html(data.message); - Navigation.reload(); - } else { - ajaxShowMessage(data.error); - } - }); - }); - $('#createViewModal').find('.modal-body').first().html(data.message); - // Attach syntax highlighted editor - $('#createViewModal').on('shown.bs.modal', function () { - window.codeMirrorEditor = Functions.getSqlEditor($('#createViewModal').find('textarea')); - $('input:visible[type=text]', $('#createViewModal')).first().trigger('focus'); - $('#createViewModal').off('shown.bs.modal'); - }); - $('#createViewModal').modal('show'); - } else { - ajaxShowMessage(data.error); - } - }); -}; - /** * Makes the breadcrumbs and the menu bar float at the top of the viewport. * @return {function} diff --git a/js/src/modules/functions/handleCreateViewModal.js b/js/src/modules/functions/handleCreateViewModal.js new file mode 100644 index 0000000000..3799c3a476 --- /dev/null +++ b/js/src/modules/functions/handleCreateViewModal.js @@ -0,0 +1,48 @@ +import $ from 'jquery'; +import { ajaxRemoveMessage, ajaxShowMessage } from '../ajax-message.js'; +import { CommonParams } from '../common.js'; +import { Functions } from '../functions.js'; +import { Navigation } from '../navigation.js'; + +/** + * @param {JQuery} $this + * + * @return {void} + */ +export default function handleCreateViewModal ($this) { + var $msg = ajaxShowMessage(); + var sep = CommonParams.get('arg_separator'); + var params = Functions.getJsConfirmCommonParam(this, $this.getPostData()); + params += sep + 'ajax_dialog=1'; + $.post($this.attr('href'), params, function (data) { + if (typeof data !== 'undefined' && data.success === true) { + ajaxRemoveMessage($msg); + $('#createViewModalGoButton').on('click', function () { + if (typeof window.CodeMirror !== 'undefined') { + window.codeMirrorEditor.save(); + } + $msg = ajaxShowMessage(); + $.post('index.php?route=/view/create', $('#createViewModal').find('form').serialize(), function (data) { + ajaxRemoveMessage($msg); + if (typeof data !== 'undefined' && data.success === true) { + $('#createViewModal').modal('hide'); + $('.result_query').html(data.message); + Navigation.reload(); + } else { + ajaxShowMessage(data.error); + } + }); + }); + $('#createViewModal').find('.modal-body').first().html(data.message); + // Attach syntax highlighted editor + $('#createViewModal').on('shown.bs.modal', function () { + window.codeMirrorEditor = Functions.getSqlEditor($('#createViewModal').find('textarea')); + $('input:visible[type=text]', $('#createViewModal')).first().trigger('focus'); + $('#createViewModal').off('shown.bs.modal'); + }); + $('#createViewModal').modal('show'); + } else { + ajaxShowMessage(data.error); + } + }); +} diff --git a/js/src/modules/navigation.js b/js/src/modules/navigation.js index 01d88533ab..06a21cf8ec 100644 --- a/js/src/modules/navigation.js +++ b/js/src/modules/navigation.js @@ -4,6 +4,7 @@ import { CommonParams } from './common.js'; import { Config } from './config.js'; import tooltip from './tooltip.js'; import { ajaxRemoveMessage, ajaxShowMessage } from './ajax-message.js'; +import handleCreateViewModal from './functions/handleCreateViewModal.js'; /** * function used in or for navigation panel @@ -451,7 +452,7 @@ Navigation.onload = () => function () { /** New view */ $(document).on('click', 'li.new_view a.ajax', function (event) { event.preventDefault(); - Functions.createViewModal($(this)); + handleCreateViewModal($(this)); }); /** Hide navigation tree item */