From ed4e2bce55c148bfc1d71b06e1c0e02edfe40675 Mon Sep 17 00:00:00 2001 From: Saksham Gupta Date: Thu, 3 Jun 2021 14:17:01 +0530 Subject: [PATCH] Replace export SQL and rename exported dialogs with modal Signed-off-by: Saksham Gupta --- js/src/export.js | 112 ++++++++----------- templates/export.twig | 251 +++++++++++++++++++++++------------------- 2 files changed, 186 insertions(+), 177 deletions(-) diff --git a/js/src/export.js b/js/src/export.js index c74f567c92..31bc925574 100644 --- a/js/src/export.js +++ b/js/src/export.js @@ -230,22 +230,11 @@ AJAX.registerTeardown('export.js', function () { AJAX.registerOnload('export.js', function () { $('#showsqlquery').on('click', function () { // Creating a dialog box similar to preview sql container to show sql query - var modalOptions = {}; - modalOptions[Messages.strClose] = function () { - $(this).dialog('close'); - }; - $('#export_sql_modal_content').clone().dialog({ - minWidth: 550, - maxHeight: 400, - modal: true, - buttons: modalOptions, - title: Messages.strQuery, - close: function () { - $(this).remove(); - }, open: function () { - // Pretty SQL printing. - Functions.highlightSql($(this)); - } + var modal = $('#showSqlQueryModal'); + modal.modal('show'); + modal.on('shown.bs.modal', function () { + $('#showSqlQueryModalLabel').first().html(Messages.strQuery); + Functions.highlightSql(modal); }); }); @@ -804,59 +793,50 @@ Export.aliasSelectHandler = function (event) { */ Export.createAliasModal = function (event) { event.preventDefault(); - var dlgButtons = {}; - dlgButtons[Messages.strSaveAndClose] = function () { - $(this).dialog('close'); - $('#alias_modal').parent().appendTo($('form[name="dump"]')); - }; - $('#alias_modal').dialog({ - width: Math.min($(window).width() - 100, 700), - maxHeight: $(window).height(), - modal: true, - dialogClass: 'alias-dialog', - buttons: dlgButtons, - create: function () { - $(this).closest('.ui-dialog').find('.ui-button').addClass('btn btn-secondary'); - $(this).css('maxHeight', $(window).height() - 150); - var db = CommonParams.get('db'); - if (db) { - var option = $(''); - option.text(db); - option.attr('value', db); - $('#db_alias_select').append(option).val(db).trigger('change'); - } else { - var params = { - 'ajax_request': true, - 'server': CommonParams.get('server') - }; - $.post('index.php?route=/databases', params, function (response) { - if (response.success === true) { - $.each(response.databases, function (idx, value) { - var option = $(''); - option.text(value); - option.attr('value', value); - $('#db_alias_select').append(option); - }); - } else { - Functions.ajaxShowMessage(response.error, false); - } - }); - } - }, - close: function () { - var isEmpty = true; - $(this).find('input[type="text"]').each(function () { - // trim empty input fields on close - if ($(this).val()) { - isEmpty = false; + var modal = $('#renameExportModal'); + modal.modal('show'); + modal.on('shown.bs.modal', function () { + modal.closest('.ui-dialog').find('.ui-button').addClass('btn btn-secondary'); + var db = CommonParams.get('db'); + if (db) { + var option = $(''); + option.text(db); + option.attr('value', db); + $('#db_alias_select').append(option).val(db).trigger('change'); + } else { + var params = { + 'ajax_request': true, + 'server': CommonParams.get('server') + }; + $.post('index.php?route=/databases', params, function (response) { + if (response.success === true) { + $.each(response.databases, function (idx, value) { + var option = $(''); + option.text(value); + option.attr('value', value); + $('#db_alias_select').append(option); + }); } else { - $(this).parents('tr').remove(); + Functions.ajaxShowMessage(response.error, false); } }); - // Toggle checkbox based on aliases - $('input#btn_alias_config').prop('checked', !isEmpty); - }, - position: { my: 'center top', at: 'center top', of: window } + } + }); + modal.on('hidden.bs.modal', function () { + var isEmpty = true; + $(this).find('input[type="text"]').each(function () { + // trim empty input fields on close + if ($(this).val()) { + isEmpty = false; + } else { + $(this).parents('tr').remove(); + } + }); + // Toggle checkbox based on aliases + $('input#btn_alias_config').prop('checked', !isEmpty); + }); + $('#saveAndCloseBtn').on('click', function () { + $('#alias_modal').parent().appendTo($('form[name="dump"]')); }); }; diff --git a/templates/export.twig b/templates/export.twig index 4f9c5e107b..73404a090a 100644 --- a/templates/export.twig +++ b/templates/export.twig @@ -52,15 +52,29 @@ {# l10n: Button to show the SQL query on the export page #} -
-
- -
{{ sql_query }}
-
+
+
+
+
+ {% endif %} @@ -154,125 +168,140 @@ {% endif %} -
- - - - - - - - - {% for db, db_data in aliases %} - {% if db_data.alias is defined and db_data.alias is not null %} - - - - - - - {% endif %} - - {% for table, table_data in db_data.tables ?? [] %} - {% if table_data.alias is defined and table_data.alias is not null %} +
- {% trans 'Defined aliases' %} -
{% trans %}Database{% context %}Alias{% endtrans %}{{ db }} - - - -
+ - - + + + + + + {% for db, db_data in aliases %} + {% if db_data.alias is defined and db_data.alias is not null %} + + + + + + + {% endif %} + + {% for table, table_data in db_data.tables ?? [] %} + {% if table_data.alias is defined and table_data.alias is not null %} + + + + + + + {% endif %} + + {% for column, column_name in table_data.columns ?? [] %} + + + + + + + {% endfor %} + {% endfor %} + {% endfor %} + + + {# Empty row for javascript manipulations. #} + + + + - {% endif %} + +
{% trans %}Table{% context %}Alias{% endtrans %}{{ db }}.{{ table }} + {% trans 'Defined aliases' %} +
{% trans %}Database{% context %}Alias{% endtrans %}{{ db }} + + + +
{% trans %}Table{% context %}Alias{% endtrans %}{{ db }}.{{ table }} + + + +
{% trans %}Column{% context %}Alias{% endtrans %}{{ db }}.{{ table }}.{{ column }} + + + +
- +
- {% for column, column_name in table_data.columns ?? [] %} + + + + + + - - + + - {% endfor %} - {% endfor %} - {% endfor %} - - - {# Empty row for javascript manipulations. #} - - - - - - - - -
{% trans 'Define new aliases' %}
{% trans %}Column{% context %}Alias{% endtrans %}{{ db }}.{{ table }}.{{ column }} - + - + + + + +
- - - -
- - - - - - - - - - - - - - - - - - - - - - - - - -
{% trans 'Define new aliases' %}
- - - - - - - -
- - - - - - - -
- - - - - - - -
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + +