Extract Functions.createViewModal() to a module
Signed-off-by: Maurício Meneghini Fauth <mauricio@fauth.dev>
This commit is contained in:
parent
f2ff55f605
commit
5348e09627
@ -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}
|
||||
|
||||
48
js/src/modules/functions/handleCreateViewModal.js
Normal file
48
js/src/modules/functions/handleCreateViewModal.js
Normal file
@ -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<HTMLElement>} $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);
|
||||
}
|
||||
});
|
||||
}
|
||||
@ -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 */
|
||||
|
||||
Loading…
Reference in New Issue
Block a user