diff options
author | Maurício Meneghini Fauth <mauricio@fauth.dev> | 2022-06-19 08:05:46 +0300 |
---|---|---|
committer | Maurício Meneghini Fauth <mauricio@fauth.dev> | 2022-06-19 22:48:10 +0300 |
commit | 799bf45f54fd686a7e90f0c61ab68f62aba29b11 (patch) | |
tree | 12aa74525075d44ed12dee55807b98159e8c4191 | |
parent | f5d738db59a7430c96b3824458d89e01c331450a (diff) |
Move `Functions.handleSimulateQueryButton` to sql.js file
Signed-off-by: Maurício Meneghini Fauth <mauricio@fauth.dev>
-rw-r--r-- | js/src/functions.js | 32 | ||||
-rw-r--r-- | js/src/sql.js | 35 |
2 files changed, 33 insertions, 34 deletions
diff --git a/js/src/functions.js b/js/src/functions.js index 92a5f08a94..347f996969 100644 --- a/js/src/functions.js +++ b/js/src/functions.js @@ -1129,38 +1129,6 @@ Functions.setQuery = function (query) { }; /** - * Handles 'Simulate query' button on SQL query box. - * - * @return {void} - */ -Functions.handleSimulateQueryButton = function () { - var updateRegExp = new RegExp('^\\s*UPDATE\\s+((`[^`]+`)|([A-Za-z0-9_$]+))\\s+SET\\s', 'i'); - var deleteRegExp = new RegExp('^\\s*DELETE\\s+FROM\\s', 'i'); - var query = ''; - - if (codeMirrorEditor) { - query = codeMirrorEditor.getValue(); - } else { - query = $('#sqlquery').val(); - } - - var $simulateDml = $('#simulate_dml'); - if (updateRegExp.test(query) || deleteRegExp.test(query)) { - if (! $simulateDml.length) { - $('#button_submit_query') - .before('<input type="button" id="simulate_dml"' + - 'tabindex="199" class="btn btn-primary" value="' + - Messages.strSimulateDML + - '">'); - } - } else { - if ($simulateDml.length) { - $simulateDml.remove(); - } - } -}; - -/** * Create quick sql statements. * * @param {'clear'|'format'|'saved'|'selectall'|'select'|'insert'|'update'|'delete'} queryType diff --git a/js/src/sql.js b/js/src/sql.js index 0d5326bb08..feb63ace46 100644 --- a/js/src/sql.js +++ b/js/src/sql.js @@ -182,6 +182,37 @@ Sql.getFieldName = function ($tableResults, $thisField) { }; /** + * Handles 'Simulate query' button on SQL query box. + * + * @return {void} + */ +const handleSimulateQueryButton = function () { + const updateRegExp = new RegExp('^\\s*UPDATE\\s+((`[^`]+`)|([A-Za-z0-9_$]+))\\s+SET\\s', 'i'); + const deleteRegExp = new RegExp('^\\s*DELETE\\s+FROM\\s', 'i'); + let query = ''; + + if (codeMirrorEditor) { + query = codeMirrorEditor.getValue(); + } else { + query = $('#sqlquery').val(); + } + + const $simulateDml = $('#simulate_dml'); + if (updateRegExp.test(query) || deleteRegExp.test(query)) { + if (! $simulateDml.length) { + $('#button_submit_query').before( + '<input type="button" id="simulate_dml"' + + 'tabindex="199" class="btn btn-primary" value="' + Messages.strSimulateDML + '">' + ); + } + } else { + if ($simulateDml.length) { + $simulateDml.remove(); + } + } +}; + +/** * Unbind all event handlers before tearing down a page */ AJAX.registerTeardown('sql.js', function () { @@ -716,7 +747,7 @@ AJAX.registerOnload('sql.js', function () { }); $('body').on('keyup', '#sqlqueryform', function () { - Functions.handleSimulateQueryButton(); + handleSimulateQueryButton(); }); /** @@ -855,7 +886,7 @@ AJAX.registerOnload('sql.js', function () { $(document).on('click', 'input.sqlbutton', function (evt) { Functions.insertQuery(evt.target.id); - Functions.handleSimulateQueryButton(); + handleSimulateQueryButton(); return false; }); }); |