diff --git a/js/src/database/events.ts b/js/src/database/events.ts
index 22e0155462..32b4db0a7a 100644
--- a/js/src/database/events.ts
+++ b/js/src/database/events.ts
@@ -99,43 +99,43 @@ const DatabaseEvents = {
ajaxRemoveMessage($msg);
function showExport (data) {
- if (data.success === true) {
- ajaxRemoveMessage($msg);
- /**
- * @var buttonOptions Object containing options
- * for jQueryUI dialog buttons
- */
- var buttonOptions = {
- [window.Messages.strClose]: {
- text: window.Messages.strClose,
- class: 'btn btn-primary',
- click: function () {
- $(this).dialog('close').remove();
- },
- },
- };
- /**
- * Display the dialog to the user
- */
- data.message = '';
- var $ajaxDialog = $('
' + data.message + '
').dialog({
- classes: {
- 'ui-dialog-titlebar-close': 'btn-close'
- },
- width: 500,
- buttons: buttonOptions,
- title: data.title
- });
- // Attach syntax highlighted editor to export dialog
- /**
- * @var $elm jQuery object containing the reference
- * to the Export textarea.
- */
- var $elm = $ajaxDialog.find('textarea');
- Functions.getSqlEditor($elm);
- } else {
+ if (data.success !== true) {
ajaxShowMessage(data.error, false);
+ return;
}
+ ajaxRemoveMessage($msg);
+ /**
+ * @var buttonOptions Object containing options
+ * for jQueryUI dialog buttons
+ */
+ var buttonOptions = {
+ [window.Messages.strClose]: {
+ text: window.Messages.strClose,
+ class: 'btn btn-primary',
+ click: function () {
+ $(this).dialog('close').remove();
+ },
+ },
+ };
+ /**
+ * Display the dialog to the user
+ */
+ data.message = '';
+ var $ajaxDialog = $('
' + data.message + '
').dialog({
+ classes: {
+ 'ui-dialog-titlebar-close': 'btn-close'
+ },
+ width: 500,
+ buttons: buttonOptions,
+ title: data.title
+ });
+ // Attach syntax highlighted editor to export dialog
+ /**
+ * @var $elm jQuery object containing the reference
+ * to the Export textarea.
+ */
+ var $elm = $ajaxDialog.find('textarea');
+ Functions.getSqlEditor($elm);
} // end showExport()
}, // end exportDialog()
editorDialog: function (isNew, $this) {
@@ -158,195 +158,195 @@ const DatabaseEvents = {
*/
var $msg = ajaxShowMessage();
$.get($this.attr('href'), { 'ajax_request': true }, function (data) {
- if (data.success === true) {
- // We have successfully fetched the editor form
- ajaxRemoveMessage($msg);
- /**
- * @var buttonOptions Object containing options
- * for jQueryUI dialog buttons
- */
- var buttonOptions = {
- [window.Messages.strGo]: {
- text: window.Messages.strGo,
- class: 'btn btn-primary',
- },
- [window.Messages.strClose]: {
- text: window.Messages.strClose,
- class: 'btn btn-secondary',
- },
- };
- // Now define the function that is called when
- // the user presses the "Go" button
- buttonOptions[window.Messages.strGo].click = function () {
- // Move the data from the codemirror editor back to the
- // textarea, where it can be used in the form submission.
- if (typeof window.CodeMirror !== 'undefined') {
- that.syntaxHiglighter.save();
- }
- // Validate editor and submit request, if passed.
- if (that.validate()) {
- /**
- * @var data Form data to be sent in the AJAX request
- */
- var data = $('form.rte_form').last().serialize();
- $msg = ajaxShowMessage(
- window.Messages.strProcessingRequest
- );
- var url = $('form.rte_form').last().attr('action');
- $.post(url, data, function (data) {
- if (data.success === true) {
- // Item created successfully
- ajaxRemoveMessage($msg);
- Functions.slidingMessage(data.message);
- that.$ajaxDialog.dialog('close');
- // If we are in 'edit' mode, we must
- // remove the reference to the old row.
- if (mode === 'edit' && $editRow !== null) {
- $editRow.remove();
- }
- // Sometimes, like when moving a trigger from
- // a table to another one, the new row should
- // not be inserted into the list. In this case
- // "data.insert" will be set to false.
- if (data.insert) {
- // Insert the new row at the correct
- // location in the list of items
- /**
- * @var text Contains the name of an item from
- * the list that is used in comparisons
- * to find the correct location where
- * to insert a new row.
- */
- var text = '';
- /**
- * @var inserted Whether a new item has been
- * inserted in the list or not
- */
- var inserted = false;
- $('table.data').find('tr').each(function () {
- text = $(this)
- .children('td')
- .eq(0)
- .find('strong')
- .text()
- .toUpperCase()
- .trim();
- if (text !== '' && text > data.name) {
- $(this).before(data.new_row);
- inserted = true;
- return false;
- }
- });
- if (! inserted) {
- // If we didn't manage to insert the row yet,
- // it must belong at the end of the list,
- // so we insert it there.
- $('table.data').append(data.new_row);
- }
- // Fade-in the new row
- $('tr.ajaxInsert')
- .show('slow')
- .removeClass('ajaxInsert');
- } else if ($('table.data').find('tr').has('td').length === 0) {
- // If we are not supposed to insert the new row,
- // we will now check if the table is empty and
- // needs to be hidden. This will be the case if
- // we were editing the only item in the list,
- // which we removed and will not be inserting
- // something else in its place.
- $('table.data').hide('slow', function () {
- $('#nothing2display').show('slow');
- });
- }
- // Now we have inserted the row at the correct
- // position, but surely at least some row classes
- // are wrong now. So we will iterate through
- // all rows and assign correct classes to them
- /**
- * @var ct Count of processed rows
- */
- var ct = 0;
- /**
- * @var rowclass Class to be attached to the row
- * that is being processed
- */
- var rowclass = '';
- $('table.data').find('tr').has('td').each(function () {
- rowclass = (ct % 2 === 0) ? 'odd' : 'even';
- $(this).removeClass().addClass(rowclass);
- ct++;
- });
- // If this is the first item being added, remove
- // the "No items" message and show the list.
- if ($('table.data').find('tr').has('td').length > 0 &&
- $('#nothing2display').is(':visible')
- ) {
- $('#nothing2display').hide('slow', function () {
- $('table.data').show('slow');
- });
- }
- Navigation.reload();
- } else {
- ajaxShowMessage(data.error, false);
- }
- }); // end $.post()
- } // end "if (that.validate())"
- }; // end of function that handles the submission of the Editor
- buttonOptions[window.Messages.strClose].click = function () {
- $(this).dialog('close');
- };
- /**
- * Display the dialog to the user
- */
- that.$ajaxDialog = $('
' + data.message + '
').dialog({
- classes: {
- 'ui-dialog-titlebar-close': 'btn-close'
- },
- width: 700,
- minWidth: 500,
- buttons: buttonOptions,
- // Issue #15810 - use button titles for modals (eg: new procedure)
- // Respect the order: title on href tag, href content, title sent in response
- title: $this.attr('title') || $this.text() || $(data.title).text(),
- modal: true,
- open: function () {
- $('#rteDialog').dialog('option', 'max-height', $(window).height());
- if ($('#rteDialog').parents('.ui-dialog').height() > $(window).height()) {
- $('#rteDialog').dialog('option', 'height', $(window).height());
- }
- $(this).find('input[name=item_name]').trigger('focus');
- $(this).find('input.datefield').each(function () {
- Functions.addDatepicker($(this).css('width', '95%'), 'date');
- });
- $(this).find('input.datetimefield').each(function () {
- Functions.addDatepicker($(this).css('width', '95%'), 'datetime');
- });
- $.datepicker.initialized = false;
- },
- close: function () {
- $(this).remove();
- }
- });
- /**
- * @var mode Used to remember whether the editor is in
- * "Edit" or "Add" mode
- */
- var mode = 'add';
- if ($('input[name=editor_process_edit]').length > 0) {
- mode = 'edit';
- }
- // Attach syntax highlighted editor to the definition
- /**
- * @var elm jQuery object containing the reference to
- * the Definition textarea.
- */
- var $elm = $('textarea[name=item_definition]').last();
- var linterOptions = {};
- linterOptions.eventEditor = true;
- that.syntaxHiglighter = Functions.getSqlEditor($elm, {}, 'both', linterOptions);
- } else {
+ if (data.success !== true) {
ajaxShowMessage(data.error, false);
+ return;
}
+ // We have successfully fetched the editor form
+ ajaxRemoveMessage($msg);
+ /**
+ * @var buttonOptions Object containing options
+ * for jQueryUI dialog buttons
+ */
+ var buttonOptions = {
+ [window.Messages.strGo]: {
+ text: window.Messages.strGo,
+ class: 'btn btn-primary',
+ },
+ [window.Messages.strClose]: {
+ text: window.Messages.strClose,
+ class: 'btn btn-secondary',
+ },
+ };
+ // Now define the function that is called when
+ // the user presses the "Go" button
+ buttonOptions[window.Messages.strGo].click = function () {
+ // Move the data from the codemirror editor back to the
+ // textarea, where it can be used in the form submission.
+ if (typeof window.CodeMirror !== 'undefined') {
+ that.syntaxHiglighter.save();
+ }
+ // Validate editor and submit request, if passed.
+ if (that.validate()) {
+ /**
+ * @var data Form data to be sent in the AJAX request
+ */
+ var data = $('form.rte_form').last().serialize();
+ $msg = ajaxShowMessage(
+ window.Messages.strProcessingRequest
+ );
+ var url = $('form.rte_form').last().attr('action');
+ $.post(url, data, function (data) {
+ if (data.success !== true) {
+ ajaxShowMessage(data.error, false);
+ return;
+ }
+ // Item created successfully
+ ajaxRemoveMessage($msg);
+ Functions.slidingMessage(data.message);
+ that.$ajaxDialog.dialog('close');
+ // If we are in 'edit' mode, we must
+ // remove the reference to the old row.
+ if (mode === 'edit' && $editRow !== null) {
+ $editRow.remove();
+ }
+ // Sometimes, like when moving a trigger from
+ // a table to another one, the new row should
+ // not be inserted into the list. In this case
+ // "data.insert" will be set to false.
+ if (data.insert) {
+ // Insert the new row at the correct
+ // location in the list of items
+ /**
+ * @var text Contains the name of an item from
+ * the list that is used in comparisons
+ * to find the correct location where
+ * to insert a new row.
+ */
+ var text = '';
+ /**
+ * @var inserted Whether a new item has been
+ * inserted in the list or not
+ */
+ var inserted = false;
+ $('table.data').find('tr').each(function () {
+ text = $(this)
+ .children('td')
+ .eq(0)
+ .find('strong')
+ .text()
+ .toUpperCase()
+ .trim();
+ if (text !== '' && text > data.name) {
+ $(this).before(data.new_row);
+ inserted = true;
+ return false;
+ }
+ });
+ if (! inserted) {
+ // If we didn't manage to insert the row yet,
+ // it must belong at the end of the list,
+ // so we insert it there.
+ $('table.data').append(data.new_row);
+ }
+ // Fade-in the new row
+ $('tr.ajaxInsert')
+ .show('slow')
+ .removeClass('ajaxInsert');
+ } else if ($('table.data').find('tr').has('td').length === 0) {
+ // If we are not supposed to insert the new row,
+ // we will now check if the table is empty and
+ // needs to be hidden. This will be the case if
+ // we were editing the only item in the list,
+ // which we removed and will not be inserting
+ // something else in its place.
+ $('table.data').hide('slow', function () {
+ $('#nothing2display').show('slow');
+ });
+ }
+ // Now we have inserted the row at the correct
+ // position, but surely at least some row classes
+ // are wrong now. So we will iterate through
+ // all rows and assign correct classes to them
+ /**
+ * @var ct Count of processed rows
+ */
+ var ct = 0;
+ /**
+ * @var rowclass Class to be attached to the row
+ * that is being processed
+ */
+ var rowclass = '';
+ $('table.data').find('tr').has('td').each(function () {
+ rowclass = (ct % 2 === 0) ? 'odd' : 'even';
+ $(this).removeClass().addClass(rowclass);
+ ct++;
+ });
+ // If this is the first item being added, remove
+ // the "No items" message and show the list.
+ if ($('table.data').find('tr').has('td').length > 0 &&
+ $('#nothing2display').is(':visible')
+ ) {
+ $('#nothing2display').hide('slow', function () {
+ $('table.data').show('slow');
+ });
+ }
+ Navigation.reload();
+ }); // end $.post()
+ } // end "if (that.validate())"
+ }; // end of function that handles the submission of the Editor
+ buttonOptions[window.Messages.strClose].click = function () {
+ $(this).dialog('close');
+ };
+ /**
+ * Display the dialog to the user
+ */
+ that.$ajaxDialog = $('
' + data.message + '
').dialog({
+ classes: {
+ 'ui-dialog-titlebar-close': 'btn-close'
+ },
+ width: 700,
+ minWidth: 500,
+ buttons: buttonOptions,
+ // Issue #15810 - use button titles for modals (eg: new procedure)
+ // Respect the order: title on href tag, href content, title sent in response
+ title: $this.attr('title') || $this.text() || $(data.title).text(),
+ modal: true,
+ open: function () {
+ $('#rteDialog').dialog('option', 'max-height', $(window).height());
+ if ($('#rteDialog').parents('.ui-dialog').height() > $(window).height()) {
+ $('#rteDialog').dialog('option', 'height', $(window).height());
+ }
+ $(this).find('input[name=item_name]').trigger('focus');
+ $(this).find('input.datefield').each(function () {
+ Functions.addDatepicker($(this).css('width', '95%'), 'date');
+ });
+ $(this).find('input.datetimefield').each(function () {
+ Functions.addDatepicker($(this).css('width', '95%'), 'datetime');
+ });
+ $.datepicker.initialized = false;
+ },
+ close: function () {
+ $(this).remove();
+ }
+ });
+ /**
+ * @var mode Used to remember whether the editor is in
+ * "Edit" or "Add" mode
+ */
+ var mode = 'add';
+ if ($('input[name=editor_process_edit]').length > 0) {
+ mode = 'edit';
+ }
+ // Attach syntax highlighted editor to the definition
+ /**
+ * @var elm jQuery object containing the reference to
+ * the Definition textarea.
+ */
+ var $elm = $('textarea[name=item_definition]').last();
+ var linterOptions = {};
+ linterOptions.eventEditor = true;
+ that.syntaxHiglighter = Functions.getSqlEditor($elm, {}, 'both', linterOptions);
}); // end $.get()
},
@@ -370,54 +370,54 @@ const DatabaseEvents = {
var $msg = ajaxShowMessage(window.Messages.strProcessingRequest);
var params = getJsConfirmCommonParam(this, $this.getPostData());
$.post(url, params, function (data) {
- if (data.success === true) {
- /**
- * @var $table Object containing reference
- * to the main list of elements
- */
- var $table = $currRow.parent();
- // Check how many rows will be left after we remove
- // the one that the user has requested us to remove
- if ($table.find('tr').length === 3) {
- // If there are two rows left, it means that they are
- // the header of the table and the rows that we are
- // about to remove, so after the removal there will be
- // nothing to show in the table, so we hide it.
- $table.hide('slow', function () {
- $(this).find('tr.even, tr.odd').remove();
- $('.withSelected').remove();
- $('#nothing2display').show('slow');
- });
- } else {
- $currRow.hide('slow', function () {
- $(this).remove();
- // Now we have removed the row from the list, but maybe
- // some row classes are wrong now. So we will iterate
- // through all rows and assign correct classes to them.
- /**
- * @var ct Count of processed rows
- */
- var ct = 0;
- /**
- * @var rowclass Class to be attached to the row
- * that is being processed
- */
- var rowclass = '';
- $table.find('tr').has('td').each(function () {
- rowclass = (ct % 2 === 1) ? 'odd' : 'even';
- $(this).removeClass().addClass(rowclass);
- ct++;
- });
- });
- }
- // Get rid of the "Loading" message
- ajaxRemoveMessage($msg);
- // Show the query that we just executed
- Functions.slidingMessage(data.sql_query);
- Navigation.reload();
- } else {
+ if (data.success !== true) {
ajaxShowMessage(data.error, false);
+ return;
}
+ /**
+ * @var $table Object containing reference
+ * to the main list of elements
+ */
+ var $table = $currRow.parent();
+ // Check how many rows will be left after we remove
+ // the one that the user has requested us to remove
+ if ($table.find('tr').length === 3) {
+ // If there are two rows left, it means that they are
+ // the header of the table and the rows that we are
+ // about to remove, so after the removal there will be
+ // nothing to show in the table, so we hide it.
+ $table.hide('slow', function () {
+ $(this).find('tr.even, tr.odd').remove();
+ $('.withSelected').remove();
+ $('#nothing2display').show('slow');
+ });
+ } else {
+ $currRow.hide('slow', function () {
+ $(this).remove();
+ // Now we have removed the row from the list, but maybe
+ // some row classes are wrong now. So we will iterate
+ // through all rows and assign correct classes to them.
+ /**
+ * @var ct Count of processed rows
+ */
+ var ct = 0;
+ /**
+ * @var rowclass Class to be attached to the row
+ * that is being processed
+ */
+ var rowclass = '';
+ $table.find('tr').has('td').each(function () {
+ rowclass = (ct % 2 === 1) ? 'odd' : 'even';
+ $(this).removeClass().addClass(rowclass);
+ ct++;
+ });
+ });
+ }
+ // Get rid of the "Loading" message
+ ajaxRemoveMessage($msg);
+ // Show the query that we just executed
+ Functions.slidingMessage(data.sql_query);
+ Navigation.reload();
}); // end $.post()
});
},
@@ -446,59 +446,59 @@ const DatabaseEvents = {
var params = getJsConfirmCommonParam(this, $anchor.getPostData());
$.post($anchor.attr('href'), params, function (data) {
returnCount++;
- if (data.success === true) {
- /**
- * @var $table Object containing reference
- * to the main list of elements
- */
- var $table = $currRow.parent();
- // Check how many rows will be left after we remove
- // the one that the user has requested us to remove
- if ($table.find('tr').length === 3) {
- // If there are two rows left, it means that they are
- // the header of the table and the rows that we are
- // about to remove, so after the removal there will be
- // nothing to show in the table, so we hide it.
- $table.hide('slow', function () {
- $(this).find('tr.even, tr.odd').remove();
- $('.withSelected').remove();
- $('#nothing2display').show('slow');
- });
- } else {
- $currRow.hide('fast', function () {
- // we will iterate
- // through all rows and assign correct classes to them.
- /**
- * @var ct Count of processed rows
- */
- var ct = 0;
- /**
- * @var rowclass Class to be attached to the row
- * that is being processed
- */
- var rowclass = '';
- $table.find('tr').has('td').each(function () {
- rowclass = (ct % 2 === 1) ? 'odd' : 'even';
- $(this).removeClass().addClass(rowclass);
- ct++;
- });
- });
- $currRow.remove();
- }
- if (returnCount === count) {
- if (success) {
- // Get rid of the "Loading" message
- ajaxRemoveMessage($msg);
- $('#rteListForm_checkall').prop({ checked: false, indeterminate: false });
- }
- Navigation.reload();
- }
- } else {
+ if (data.success !== true) {
ajaxShowMessage(data.error, false);
success = false;
if (returnCount === count) {
Navigation.reload();
}
+ return;
+ }
+ /**
+ * @var $table Object containing reference
+ * to the main list of elements
+ */
+ var $table = $currRow.parent();
+ // Check how many rows will be left after we remove
+ // the one that the user has requested us to remove
+ if ($table.find('tr').length === 3) {
+ // If there are two rows left, it means that they are
+ // the header of the table and the rows that we are
+ // about to remove, so after the removal there will be
+ // nothing to show in the table, so we hide it.
+ $table.hide('slow', function () {
+ $(this).find('tr.even, tr.odd').remove();
+ $('.withSelected').remove();
+ $('#nothing2display').show('slow');
+ });
+ } else {
+ $currRow.hide('fast', function () {
+ // we will iterate
+ // through all rows and assign correct classes to them.
+ /**
+ * @var ct Count of processed rows
+ */
+ var ct = 0;
+ /**
+ * @var rowclass Class to be attached to the row
+ * that is being processed
+ */
+ var rowclass = '';
+ $table.find('tr').has('td').each(function () {
+ rowclass = (ct % 2 === 1) ? 'odd' : 'even';
+ $(this).removeClass().addClass(rowclass);
+ ct++;
+ });
+ });
+ $currRow.remove();
+ }
+ if (returnCount === count) {
+ if (success) {
+ // Get rid of the "Loading" message
+ ajaxRemoveMessage($msg);
+ $('#rteListForm_checkall').prop({ checked: false, indeterminate: false });
+ }
+ Navigation.reload();
}
}); // end $.post()
}); // end drop_anchors.each()
diff --git a/js/src/database/routines.ts b/js/src/database/routines.ts
index ef796cff34..7614b9967f 100644
--- a/js/src/database/routines.ts
+++ b/js/src/database/routines.ts
@@ -114,43 +114,43 @@ const DatabaseRoutines = {
ajaxRemoveMessage($msg);
function showExport (data) {
- if (data.success === true) {
- ajaxRemoveMessage($msg);
- /**
- * @var buttonOptions Object containing options
- * for jQueryUI dialog buttons
- */
- var buttonOptions = {
- [window.Messages.strClose]: {
- text: window.Messages.strClose,
- class: 'btn btn-primary',
- click: function () {
- $(this).dialog('close').remove();
- }
- },
- };
- /**
- * Display the dialog to the user
- */
- data.message = '';
- var $ajaxDialog = $('
' + data.message + '
').dialog({
- classes: {
- 'ui-dialog-titlebar-close': 'btn-close'
- },
- width: 500,
- buttons: buttonOptions,
- title: data.title
- });
- // Attach syntax highlighted editor to export dialog
- /**
- * @var $elm jQuery object containing the reference
- * to the Export textarea.
- */
- var $elm = $ajaxDialog.find('textarea');
- Functions.getSqlEditor($elm);
- } else {
+ if (data.success !== true) {
ajaxShowMessage(data.error, false);
+ return;
}
+ ajaxRemoveMessage($msg);
+ /**
+ * @var buttonOptions Object containing options
+ * for jQueryUI dialog buttons
+ */
+ var buttonOptions = {
+ [window.Messages.strClose]: {
+ text: window.Messages.strClose,
+ class: 'btn btn-primary',
+ click: function () {
+ $(this).dialog('close').remove();
+ }
+ },
+ };
+ /**
+ * Display the dialog to the user
+ */
+ data.message = '';
+ var $ajaxDialog = $('
' + data.message + '
').dialog({
+ classes: {
+ 'ui-dialog-titlebar-close': 'btn-close'
+ },
+ width: 500,
+ buttons: buttonOptions,
+ title: data.title
+ });
+ // Attach syntax highlighted editor to export dialog
+ /**
+ * @var $elm jQuery object containing the reference
+ * to the Export textarea.
+ */
+ var $elm = $ajaxDialog.find('textarea');
+ Functions.getSqlEditor($elm);
} // end showExport()
}, // end exportDialog()
editorDialog: function (isNew, $this) {
@@ -173,197 +173,198 @@ const DatabaseRoutines = {
*/
var $msg = ajaxShowMessage();
$.get($this.attr('href'), { 'ajax_request': true }, function (data) {
- if (data.success === true) {
- var buttonOptions = {
- [window.Messages.strGo]: {
- text: window.Messages.strGo,
- class: 'btn btn-primary',
- },
- [window.Messages.strClose]: {
- text: window.Messages.strClose,
- class: 'btn btn-secondary',
- },
- };
- // We have successfully fetched the editor form
- ajaxRemoveMessage($msg);
- // Now define the function that is called when
- // the user presses the "Go" button
- buttonOptions[window.Messages.strGo].click = function () {
- // Move the data from the codemirror editor back to the
- // textarea, where it can be used in the form submission.
- if (typeof window.CodeMirror !== 'undefined') {
- that.syntaxHiglighter.save();
- }
- // Validate editor and submit request, if passed.
- if (that.validate()) {
- /**
- * @var data Form data to be sent in the AJAX request
- */
- var data = $('form.rte_form').last().serialize();
- $msg = ajaxShowMessage(
- window.Messages.strProcessingRequest
- );
- var url = $('form.rte_form').last().attr('action');
- $.post(url, data, function (data) {
- if (data.success === true) {
- // Item created successfully
- ajaxRemoveMessage($msg);
- Functions.slidingMessage(data.message);
- that.$ajaxDialog.dialog('close');
-
- var tableId = '#' + data.tableType + 'Table';
- // If we are in 'edit' mode, we must
- // remove the reference to the old row.
- if (mode === 'edit' && $editRow !== null) {
- $editRow.remove();
- }
- // Sometimes, like when moving a trigger from
- // a table to another one, the new row should
- // not be inserted into the list. In this case
- // "data.insert" will be set to false.
- if (data.insert) {
- // Insert the new row at the correct
- // location in the list of items
- /**
- * @var text Contains the name of an item from
- * the list that is used in comparisons
- * to find the correct location where
- * to insert a new row.
- */
- var text = '';
- /**
- * @var inserted Whether a new item has been
- * inserted in the list or not
- */
- var inserted = false;
- $(tableId + '.data').find('tr').each(function () {
- text = $(this)
- .children('td')
- .eq(0)
- .find('strong')
- .text()
- .toUpperCase()
- .trim();
- if (text !== '' && text > data.name) {
- $(this).before(data.new_row);
- inserted = true;
- return false;
- }
- });
- if (! inserted) {
- // If we didn't manage to insert the row yet,
- // it must belong at the end of the list,
- // so we insert it there.
- $(tableId + '.data').append(data.new_row);
- }
- // Fade-in the new row
- $('tr.ajaxInsert')
- .show('slow')
- .removeClass('ajaxInsert');
- } else if ($(tableId + '.data').find('tr').has('td').length === 0) {
- // If we are not supposed to insert the new row,
- // we will now check if the table is empty and
- // needs to be hidden. This will be the case if
- // we were editing the only item in the list,
- // which we removed and will not be inserting
- // something else in its place.
- $(tableId + '.data').hide('slow', function () {
- $('#nothing2display').show('slow');
- });
- }
- // Now we have inserted the row at the correct
- // position, but surely at least some row classes
- // are wrong now. So we will iterate through
- // all rows and assign correct classes to them
- /**
- * @var ct Count of processed rows
- */
- var ct = 0;
- /**
- * @var rowclass Class to be attached to the row
- * that is being processed
- */
- var rowclass = '';
- $(tableId + '.data').find('tr').has('td').each(function () {
- rowclass = (ct % 2 === 0) ? 'odd' : 'even';
- $(this).removeClass('odd even').addClass(rowclass);
- ct++;
- });
- // If this is the first item being added, remove
- // the "No items" message and show the list.
- if ($(tableId + '.data').find('tr').has('td').length > 0 &&
- $('#nothing2display').is(':visible')
- ) {
- $('#nothing2display').hide('slow', function () {
- $(tableId + '.data').show('slow');
- });
- }
- Navigation.reload();
- } else {
- ajaxShowMessage(data.error, false);
- }
- }); // end $.post()
- } // end "if (that.validate())"
- }; // end of function that handles the submission of the Editor
- buttonOptions[window.Messages.strClose].click = function () {
- $(this).dialog('close');
- };
- /**
- * Display the dialog to the user
- */
- that.$ajaxDialog = $('
' + data.message + '
').dialog({
- classes: {
- 'ui-dialog-titlebar-close': 'btn-close'
- },
- height: 400,
- width: 700,
- minWidth: 500,
- buttons: buttonOptions,
- // Issue #15810 - use button titles for modals (eg: new procedure)
- // Respect the order: title on href tag, href content, title sent in response
- title: $this.attr('title') || $this.text() || $(data.title).text(),
- modal: true,
- open: function () {
- $('#rteDialog').dialog('option', 'max-height', $(window).height());
- if ($('#rteDialog').parents('.ui-dialog').height() > $(window).height()) {
- $('#rteDialog').dialog('option', 'height', $(window).height());
- }
- $(this).find('input[name=item_name]').trigger('focus');
- $(this).find('input.datefield').each(function () {
- Functions.addDatepicker($(this).css('width', '95%'), 'date');
- });
- $(this).find('input.datetimefield').each(function () {
- Functions.addDatepicker($(this).css('width', '95%'), 'datetime');
- });
- $.datepicker.initialized = false;
- },
- close: function () {
- $(this).remove();
- }
- });
- /**
- * @var mode Used to remember whether the editor is in
- * "Edit" or "Add" mode
- */
- var mode = 'add';
- if ($('input[name=editor_process_edit]').length > 0) {
- mode = 'edit';
- }
- // Attach syntax highlighted editor to the definition
- /**
- * @var elm jQuery object containing the reference to
- * the Definition textarea.
- */
- var $elm = $('textarea[name=item_definition]').last();
- var linterOptions = {};
- linterOptions.routineEditor = true;
- that.syntaxHiglighter = Functions.getSqlEditor($elm, {}, 'both', linterOptions);
-
- // Execute item-specific code
- that.postDialogShow(data);
- } else {
+ if (data.success !== true) {
ajaxShowMessage(data.error, false);
+ return;
}
+ var buttonOptions = {
+ [window.Messages.strGo]: {
+ text: window.Messages.strGo,
+ class: 'btn btn-primary',
+ },
+ [window.Messages.strClose]: {
+ text: window.Messages.strClose,
+ class: 'btn btn-secondary',
+ },
+ };
+ // We have successfully fetched the editor form
+ ajaxRemoveMessage($msg);
+ // Now define the function that is called when
+ // the user presses the "Go" button
+ buttonOptions[window.Messages.strGo].click = function () {
+ // Move the data from the codemirror editor back to the
+ // textarea, where it can be used in the form submission.
+ if (typeof window.CodeMirror !== 'undefined') {
+ that.syntaxHiglighter.save();
+ }
+ // Validate editor and submit request, if passed.
+ if (! that.validate()) {
+ return;
+ }
+ /**
+ * @var data Form data to be sent in the AJAX request
+ */
+ var data = $('form.rte_form').last().serialize();
+ $msg = ajaxShowMessage(
+ window.Messages.strProcessingRequest
+ );
+ var url = $('form.rte_form').last().attr('action');
+ $.post(url, data, function (data) {
+ if (data.success !== true) {
+ ajaxShowMessage(data.error, false);
+ return;
+ }
+ // Item created successfully
+ ajaxRemoveMessage($msg);
+ Functions.slidingMessage(data.message);
+ that.$ajaxDialog.dialog('close');
+
+ var tableId = '#' + data.tableType + 'Table';
+ // If we are in 'edit' mode, we must
+ // remove the reference to the old row.
+ if (mode === 'edit' && $editRow !== null) {
+ $editRow.remove();
+ }
+ // Sometimes, like when moving a trigger from
+ // a table to another one, the new row should
+ // not be inserted into the list. In this case
+ // "data.insert" will be set to false.
+ if (data.insert) {
+ // Insert the new row at the correct
+ // location in the list of items
+ /**
+ * @var text Contains the name of an item from
+ * the list that is used in comparisons
+ * to find the correct location where
+ * to insert a new row.
+ */
+ var text = '';
+ /**
+ * @var inserted Whether a new item has been
+ * inserted in the list or not
+ */
+ var inserted = false;
+ $(tableId + '.data').find('tr').each(function () {
+ text = $(this)
+ .children('td')
+ .eq(0)
+ .find('strong')
+ .text()
+ .toUpperCase()
+ .trim();
+ if (text !== '' && text > data.name) {
+ $(this).before(data.new_row);
+ inserted = true;
+ return false;
+ }
+ });
+ if (! inserted) {
+ // If we didn't manage to insert the row yet,
+ // it must belong at the end of the list,
+ // so we insert it there.
+ $(tableId + '.data').append(data.new_row);
+ }
+ // Fade-in the new row
+ $('tr.ajaxInsert')
+ .show('slow')
+ .removeClass('ajaxInsert');
+ } else if ($(tableId + '.data').find('tr').has('td').length === 0) {
+ // If we are not supposed to insert the new row,
+ // we will now check if the table is empty and
+ // needs to be hidden. This will be the case if
+ // we were editing the only item in the list,
+ // which we removed and will not be inserting
+ // something else in its place.
+ $(tableId + '.data').hide('slow', function () {
+ $('#nothing2display').show('slow');
+ });
+ }
+ // Now we have inserted the row at the correct
+ // position, but surely at least some row classes
+ // are wrong now. So we will iterate through
+ // all rows and assign correct classes to them
+ /**
+ * @var ct Count of processed rows
+ */
+ var ct = 0;
+ /**
+ * @var rowclass Class to be attached to the row
+ * that is being processed
+ */
+ var rowclass = '';
+ $(tableId + '.data').find('tr').has('td').each(function () {
+ rowclass = (ct % 2 === 0) ? 'odd' : 'even';
+ $(this).removeClass('odd even').addClass(rowclass);
+ ct++;
+ });
+ // If this is the first item being added, remove
+ // the "No items" message and show the list.
+ if ($(tableId + '.data').find('tr').has('td').length > 0 &&
+ $('#nothing2display').is(':visible')
+ ) {
+ $('#nothing2display').hide('slow', function () {
+ $(tableId + '.data').show('slow');
+ });
+ }
+ Navigation.reload();
+ }); // end $.post()
+ }; // end of function that handles the submission of the Editor
+ buttonOptions[window.Messages.strClose].click = function () {
+ $(this).dialog('close');
+ };
+ /**
+ * Display the dialog to the user
+ */
+ that.$ajaxDialog = $('
' + data.message + '
').dialog({
+ classes: {
+ 'ui-dialog-titlebar-close': 'btn-close'
+ },
+ height: 400,
+ width: 700,
+ minWidth: 500,
+ buttons: buttonOptions,
+ // Issue #15810 - use button titles for modals (eg: new procedure)
+ // Respect the order: title on href tag, href content, title sent in response
+ title: $this.attr('title') || $this.text() || $(data.title).text(),
+ modal: true,
+ open: function () {
+ $('#rteDialog').dialog('option', 'max-height', $(window).height());
+ if ($('#rteDialog').parents('.ui-dialog').height() > $(window).height()) {
+ $('#rteDialog').dialog('option', 'height', $(window).height());
+ }
+ $(this).find('input[name=item_name]').trigger('focus');
+ $(this).find('input.datefield').each(function () {
+ Functions.addDatepicker($(this).css('width', '95%'), 'date');
+ });
+ $(this).find('input.datetimefield').each(function () {
+ Functions.addDatepicker($(this).css('width', '95%'), 'datetime');
+ });
+ $.datepicker.initialized = false;
+ },
+ close: function () {
+ $(this).remove();
+ }
+ });
+ /**
+ * @var mode Used to remember whether the editor is in
+ * "Edit" or "Add" mode
+ */
+ var mode = 'add';
+ if ($('input[name=editor_process_edit]').length > 0) {
+ mode = 'edit';
+ }
+ // Attach syntax highlighted editor to the definition
+ /**
+ * @var elm jQuery object containing the reference to
+ * the Definition textarea.
+ */
+ var $elm = $('textarea[name=item_definition]').last();
+ var linterOptions = {};
+ linterOptions.routineEditor = true;
+ that.syntaxHiglighter = Functions.getSqlEditor($elm, {}, 'both', linterOptions);
+
+ // Execute item-specific code
+ that.postDialogShow(data);
}); // end $.get()
},
@@ -387,54 +388,54 @@ const DatabaseRoutines = {
var $msg = ajaxShowMessage(window.Messages.strProcessingRequest);
var params = getJsConfirmCommonParam(this, $this.getPostData());
$.post(url, params, function (data) {
- if (data.success === true) {
- /**
- * @var $table Object containing reference
- * to the main list of elements
- */
- var $table = $currRow.parent().parent();
- // Check how many rows will be left after we remove
- // the one that the user has requested us to remove
- if ($table.find('tr').length === 3) {
- // If there are two rows left, it means that they are
- // the header of the table and the rows that we are
- // about to remove, so after the removal there will be
- // nothing to show in the table, so we hide it.
- $table.hide('slow', function () {
- $(this).find('tr.even, tr.odd').remove();
- $('.withSelected').remove();
- $('#nothing2display').show('slow');
- });
- } else {
- $currRow.hide('slow', function () {
- $(this).remove();
- // Now we have removed the row from the list, but maybe
- // some row classes are wrong now. So we will iterate
- // through all rows and assign correct classes to them.
- /**
- * @var ct Count of processed rows
- */
- var ct = 0;
- /**
- * @var rowclass Class to be attached to the row
- * that is being processed
- */
- var rowclass = '';
- $table.find('tr').has('td').each(function () {
- rowclass = (ct % 2 === 1) ? 'odd' : 'even';
- $(this).removeClass('odd even').addClass(rowclass);
- ct++;
- });
- });
- }
- // Get rid of the "Loading" message
- ajaxRemoveMessage($msg);
- // Show the query that we just executed
- Functions.slidingMessage(data.sql_query);
- Navigation.reload();
- } else {
+ if (data.success !== true) {
ajaxShowMessage(data.error, false);
+ return;
}
+ /**
+ * @var $table Object containing reference
+ * to the main list of elements
+ */
+ var $table = $currRow.parent().parent();
+ // Check how many rows will be left after we remove
+ // the one that the user has requested us to remove
+ if ($table.find('tr').length === 3) {
+ // If there are two rows left, it means that they are
+ // the header of the table and the rows that we are
+ // about to remove, so after the removal there will be
+ // nothing to show in the table, so we hide it.
+ $table.hide('slow', function () {
+ $(this).find('tr.even, tr.odd').remove();
+ $('.withSelected').remove();
+ $('#nothing2display').show('slow');
+ });
+ } else {
+ $currRow.hide('slow', function () {
+ $(this).remove();
+ // Now we have removed the row from the list, but maybe
+ // some row classes are wrong now. So we will iterate
+ // through all rows and assign correct classes to them.
+ /**
+ * @var ct Count of processed rows
+ */
+ var ct = 0;
+ /**
+ * @var rowclass Class to be attached to the row
+ * that is being processed
+ */
+ var rowclass = '';
+ $table.find('tr').has('td').each(function () {
+ rowclass = (ct % 2 === 1) ? 'odd' : 'even';
+ $(this).removeClass('odd even').addClass(rowclass);
+ ct++;
+ });
+ });
+ }
+ // Get rid of the "Loading" message
+ ajaxRemoveMessage($msg);
+ // Show the query that we just executed
+ Functions.slidingMessage(data.sql_query);
+ Navigation.reload();
}); // end $.post()
});
},
@@ -463,59 +464,59 @@ const DatabaseRoutines = {
var params = getJsConfirmCommonParam(this, $anchor.getPostData());
$.post($anchor.attr('href'), params, function (data) {
returnCount++;
- if (data.success === true) {
- /**
- * @var $table Object containing reference
- * to the main list of elements
- */
- var $table = $currRow.parent().parent();
- // Check how many rows will be left after we remove
- // the one that the user has requested us to remove
- if ($table.find('tr').length === 3) {
- // If there are two rows left, it means that they are
- // the header of the table and the rows that we are
- // about to remove, so after the removal there will be
- // nothing to show in the table, so we hide it.
- $table.hide('slow', function () {
- $(this).find('tr.even, tr.odd').remove();
- $('.withSelected').remove();
- $('#nothing2display').show('slow');
- });
- } else {
- $currRow.hide('fast', function () {
- // we will iterate
- // through all rows and assign correct classes to them.
- /**
- * @var ct Count of processed rows
- */
- var ct = 0;
- /**
- * @var rowclass Class to be attached to the row
- * that is being processed
- */
- var rowclass = '';
- $table.find('tr').has('td').each(function () {
- rowclass = (ct % 2 === 1) ? 'odd' : 'even';
- $(this).removeClass('odd even').addClass(rowclass);
- ct++;
- });
- });
- $currRow.remove();
- }
- if (returnCount === count) {
- if (success) {
- // Get rid of the "Loading" message
- ajaxRemoveMessage($msg);
- $('#rteListForm_checkall').prop({ checked: false, indeterminate: false });
- }
- Navigation.reload();
- }
- } else {
+ if (data.success !== true) {
ajaxShowMessage(data.error, false);
success = false;
if (returnCount === count) {
Navigation.reload();
}
+ return;
+ }
+ /**
+ * @var $table Object containing reference
+ * to the main list of elements
+ */
+ var $table = $currRow.parent().parent();
+ // Check how many rows will be left after we remove
+ // the one that the user has requested us to remove
+ if ($table.find('tr').length === 3) {
+ // If there are two rows left, it means that they are
+ // the header of the table and the rows that we are
+ // about to remove, so after the removal there will be
+ // nothing to show in the table, so we hide it.
+ $table.hide('slow', function () {
+ $(this).find('tr.even, tr.odd').remove();
+ $('.withSelected').remove();
+ $('#nothing2display').show('slow');
+ });
+ } else {
+ $currRow.hide('fast', function () {
+ // we will iterate
+ // through all rows and assign correct classes to them.
+ /**
+ * @var ct Count of processed rows
+ */
+ var ct = 0;
+ /**
+ * @var rowclass Class to be attached to the row
+ * that is being processed
+ */
+ var rowclass = '';
+ $table.find('tr').has('td').each(function () {
+ rowclass = (ct % 2 === 1) ? 'odd' : 'even';
+ $(this).removeClass('odd even').addClass(rowclass);
+ ct++;
+ });
+ });
+ $currRow.remove();
+ }
+ if (returnCount === count) {
+ if (success) {
+ // Get rid of the "Loading" message
+ ajaxRemoveMessage($msg);
+ $('#rteListForm_checkall').prop({ checked: false, indeterminate: false });
+ }
+ Navigation.reload();
}
}); // end $.post()
}); // end drop_anchors.each()
@@ -612,22 +613,21 @@ const DatabaseRoutines = {
this.$ajaxDialog.find('table.routine_params_table').last().find('tr').each(function () {
// Every parameter of a routine must have
// a non-empty direction, name and type
- if (isSuccess) {
- $(this).find(':input').each(function () {
- inputname = $(this).attr('name');
- if (inputname.startsWith('item_param_dir') ||
- inputname.startsWith('item_param_name') ||
- inputname.startsWith('item_param_type')) {
- if ($(this).val() === '') {
- $(this).trigger('focus');
- isSuccess = false;
- return false;
- }
- }
- });
- } else {
+ if (! isSuccess) {
return false;
}
+ $(this).find(':input').each(function () {
+ inputname = $(this).attr('name');
+ if (inputname.startsWith('item_param_dir') ||
+ inputname.startsWith('item_param_name') ||
+ inputname.startsWith('item_param_type')) {
+ if ($(this).val() === '') {
+ $(this).trigger('focus');
+ isSuccess = false;
+ return false;
+ }
+ }
+ });
});
if (! isSuccess) {
alert(window.Messages.strFormEmpty);
@@ -771,102 +771,103 @@ const DatabaseRoutines = {
var $msg = ajaxShowMessage();
var params = getJsConfirmCommonParam($this[0], $this.getPostData());
$.post($this.attr('href'), params, function (data) {
- if (data.success === true) {
- ajaxRemoveMessage($msg);
- // If 'data.dialog' is true we show a dialog with a form
- // to get the input parameters for routine, otherwise
- // we just show the results of the query
- if (data.dialog) {
- var buttonOptions = {
- [window.Messages.strGo]: {
- text: window.Messages.strGo,
- class: 'btn btn-primary',
- },
- [window.Messages.strClose]: {
- text: window.Messages.strClose,
- class: 'btn btn-secondary',
- },
- };
- // Define the function that is called when
- // the user presses the "Go" button
- buttonOptions[window.Messages.strGo].click = function () {
- /**
- * @var data Form data to be sent in the AJAX request
- */
- var data = $('form.rte_form').last().serialize();
- $msg = ajaxShowMessage(
- window.Messages.strProcessingRequest
- );
- $.post('index.php?route=/database/routines', data, function (data) {
- if (data.success === true) {
- // Routine executed successfully
- ajaxRemoveMessage($msg);
- Functions.slidingMessage(data.message);
- $ajaxDialog.dialog('close');
- } else {
- ajaxShowMessage(data.error, false);
- }
- });
- };
- buttonOptions[window.Messages.strClose].click = function () {
- $(this).dialog('close');
- };
- /**
- * Display the dialog to the user
- */
- var $ajaxDialog = $('
' + data.message + '
').dialog({
- classes: {
- 'ui-dialog-titlebar-close': 'btn-close'
- },
- width: 650,
- buttons: buttonOptions,
- title: data.title,
- modal: true,
- close: function () {
- $(this).remove();
- }
- });
- $ajaxDialog.find('input[name^=params]').first().trigger('focus');
- /**
- * Attach the datepickers to the relevant form fields
- */
- $ajaxDialog.find('input.datefield, input.datetimefield').each(function () {
- Functions.addDatepicker($(this).css('width', '95%'));
- });
- /*
- * Define the function if the user presses enter
- */
- $('form.rte_form').on('keyup', function (event) {
- event.preventDefault();
- if (event.keyCode === 13) {
- /**
- * @var data Form data to be sent in the AJAX request
- */
- var data = $(this).serialize();
- $msg = ajaxShowMessage(
- window.Messages.strProcessingRequest
- );
- var url = $(this).attr('action');
- $.post(url, data, function (data) {
- if (data.success === true) {
- // Routine executed successfully
- ajaxRemoveMessage($msg);
- Functions.slidingMessage(data.message);
- $('form.rte_form').off('keyup');
- $ajaxDialog.remove();
- } else {
- ajaxShowMessage(data.error, false);
- }
- });
- }
- });
- } else {
- // Routine executed successfully
- Functions.slidingMessage(data.message);
- }
- } else {
+ if (data.success !== true) {
ajaxShowMessage(data.error, false);
+ return;
}
+ ajaxRemoveMessage($msg);
+ // If 'data.dialog' is true we show a dialog with a form
+ // to get the input parameters for routine, otherwise
+ // we just show the results of the query
+ if (! data.dialog) {
+ // Routine executed successfully
+ Functions.slidingMessage(data.message);
+ return;
+ }
+ var buttonOptions = {
+ [window.Messages.strGo]: {
+ text: window.Messages.strGo,
+ class: 'btn btn-primary',
+ },
+ [window.Messages.strClose]: {
+ text: window.Messages.strClose,
+ class: 'btn btn-secondary',
+ },
+ };
+ // Define the function that is called when
+ // the user presses the "Go" button
+ buttonOptions[window.Messages.strGo].click = function () {
+ /**
+ * @var data Form data to be sent in the AJAX request
+ */
+ var data = $('form.rte_form').last().serialize();
+ $msg = ajaxShowMessage(
+ window.Messages.strProcessingRequest
+ );
+ $.post('index.php?route=/database/routines', data, function (data) {
+ if (data.success === true) {
+ // Routine executed successfully
+ ajaxRemoveMessage($msg);
+ Functions.slidingMessage(data.message);
+ $ajaxDialog.dialog('close');
+ } else {
+ ajaxShowMessage(data.error, false);
+ }
+ });
+ };
+ buttonOptions[window.Messages.strClose].click = function () {
+ $(this).dialog('close');
+ };
+ /**
+ * Display the dialog to the user
+ */
+ var $ajaxDialog = $('
' + data.message + '
').dialog({
+ classes: {
+ 'ui-dialog-titlebar-close': 'btn-close'
+ },
+ width: 650,
+ buttons: buttonOptions,
+ title: data.title,
+ modal: true,
+ close: function () {
+ $(this).remove();
+ }
+ });
+ $ajaxDialog.find('input[name^=params]').first().trigger('focus');
+ /**
+ * Attach the datepickers to the relevant form fields
+ */
+ $ajaxDialog.find('input.datefield, input.datetimefield').each(function () {
+ Functions.addDatepicker($(this).css('width', '95%'));
+ });
+ /*
+ * Define the function if the user presses enter
+ */
+ $('form.rte_form').on('keyup', function (event) {
+ event.preventDefault();
+ if (event.keyCode !== 13) {
+ return;
+ }
+ /**
+ * @var data Form data to be sent in the AJAX request
+ */
+ var data = $(this).serialize();
+ $msg = ajaxShowMessage(
+ window.Messages.strProcessingRequest
+ );
+ var url = $(this).attr('action');
+ $.post(url, data, function (data) {
+ if (data.success !== true) {
+ ajaxShowMessage(data.error, false);
+ return;
+ }
+ // Routine executed successfully
+ ajaxRemoveMessage($msg);
+ Functions.slidingMessage(data.message);
+ $('form.rte_form').off('keyup');
+ $ajaxDialog.remove();
+ });
+ });
}); // end $.post()
}
};
diff --git a/js/src/database/triggers.ts b/js/src/database/triggers.ts
index 79ea5fde9b..f8a565684f 100644
--- a/js/src/database/triggers.ts
+++ b/js/src/database/triggers.ts
@@ -108,43 +108,43 @@ const DatabaseTriggers = {
ajaxRemoveMessage($msg);
function showExport (data) {
- if (data.success === true) {
- ajaxRemoveMessage($msg);
- /**
- * @var buttonOptions Object containing options
- * for jQueryUI dialog buttons
- */
- var buttonOptions = {
- [window.Messages.strClose]: {
- text: window.Messages.strClose,
- class: 'btn btn-primary',
- },
- };
- buttonOptions[window.Messages.strClose].click = function () {
- $(this).dialog('close').remove();
- };
- /**
- * Display the dialog to the user
- */
- data.message = '';
- var $ajaxDialog = $('
' + data.message + '
').dialog({
- classes: {
- 'ui-dialog-titlebar-close': 'btn-close'
- },
- width: 500,
- buttons: buttonOptions,
- title: data.title
- });
- // Attach syntax highlighted editor to export dialog
- /**
- * @var $elm jQuery object containing the reference
- * to the Export textarea.
- */
- var $elm = $ajaxDialog.find('textarea');
- Functions.getSqlEditor($elm);
- } else {
+ if (data.success !== true) {
ajaxShowMessage(data.error, false);
+ return;
}
+ ajaxRemoveMessage($msg);
+ /**
+ * @var buttonOptions Object containing options
+ * for jQueryUI dialog buttons
+ */
+ var buttonOptions = {
+ [window.Messages.strClose]: {
+ text: window.Messages.strClose,
+ class: 'btn btn-primary',
+ },
+ };
+ buttonOptions[window.Messages.strClose].click = function () {
+ $(this).dialog('close').remove();
+ };
+ /**
+ * Display the dialog to the user
+ */
+ data.message = '';
+ var $ajaxDialog = $('
' + data.message + '
').dialog({
+ classes: {
+ 'ui-dialog-titlebar-close': 'btn-close'
+ },
+ width: 500,
+ buttons: buttonOptions,
+ title: data.title
+ });
+ // Attach syntax highlighted editor to export dialog
+ /**
+ * @var $elm jQuery object containing the reference
+ * to the Export textarea.
+ */
+ var $elm = $ajaxDialog.find('textarea');
+ Functions.getSqlEditor($elm);
} // end showExport()
}, // end exportDialog()
editorDialog: function (isNew, $this) {
@@ -167,191 +167,192 @@ const DatabaseTriggers = {
*/
var $msg = ajaxShowMessage();
$.get($this.attr('href'), { 'ajax_request': true }, function (data) {
- if (data.success === true) {
- var buttonOptions = {
- [window.Messages.strGo]: {
- text: window.Messages.strGo,
- class: 'btn btn-primary',
- },
- [window.Messages.strClose]: {
- text: window.Messages.strClose,
- class: 'btn btn-secondary',
- },
- };
- // We have successfully fetched the editor form
- ajaxRemoveMessage($msg);
- // Now define the function that is called when
- // the user presses the "Go" button
- buttonOptions[window.Messages.strGo].click = function () {
- // Move the data from the codemirror editor back to the
- // textarea, where it can be used in the form submission.
- if (typeof window.CodeMirror !== 'undefined') {
- that.syntaxHiglighter.save();
- }
- // Validate editor and submit request, if passed.
- if (that.validate()) {
- /**
- * @var data Form data to be sent in the AJAX request
- */
- var data = $('form.rte_form').last().serialize();
- $msg = ajaxShowMessage(
- window.Messages.strProcessingRequest
- );
- var url = $('form.rte_form').last().attr('action');
- $.post(url, data, function (data) {
- if (data.success === true) {
- // Item created successfully
- ajaxRemoveMessage($msg);
- Functions.slidingMessage(data.message);
- that.$ajaxDialog.dialog('close');
- // If we are in 'edit' mode, we must
- // remove the reference to the old row.
- if (mode === 'edit' && $editRow !== null) {
- $editRow.remove();
- }
- // Sometimes, like when moving a trigger from
- // a table to another one, the new row should
- // not be inserted into the list. In this case
- // "data.insert" will be set to false.
- if (data.insert) {
- // Insert the new row at the correct
- // location in the list of items
- /**
- * @var text Contains the name of an item from
- * the list that is used in comparisons
- * to find the correct location where
- * to insert a new row.
- */
- var text = '';
- /**
- * @var inserted Whether a new item has been
- * inserted in the list or not
- */
- var inserted = false;
- $('table.data').find('tr').each(function () {
- text = $(this)
- .children('td')
- .eq(0)
- .find('strong')
- .text()
- .toUpperCase()
- .trim();
- if (text !== '' && text > data.name) {
- $(this).before(data.new_row);
- inserted = true;
- return false;
- }
- });
- if (! inserted) {
- // If we didn't manage to insert the row yet,
- // it must belong at the end of the list,
- // so we insert it there.
- $('table.data').append(data.new_row);
- }
- // Fade-in the new row
- $('tr.ajaxInsert')
- .show('slow')
- .removeClass('ajaxInsert');
- } else if ($('table.data').find('tr').has('td').length === 0) {
- // If we are not supposed to insert the new row,
- // we will now check if the table is empty and
- // needs to be hidden. This will be the case if
- // we were editing the only item in the list,
- // which we removed and will not be inserting
- // something else in its place.
- $('table.data').hide('slow', function () {
- $('#nothing2display').show('slow');
- });
- }
- // Now we have inserted the row at the correct
- // position, but surely at least some row classes
- // are wrong now. So we will iterate through
- // all rows and assign correct classes to them
- /**
- * @var ct Count of processed rows
- */
- var ct = 0;
- /**
- * @var rowclass Class to be attached to the row
- * that is being processed
- */
- var rowclass = '';
- $('table.data').find('tr').has('td').each(function () {
- rowclass = (ct % 2 === 0) ? 'odd' : 'even';
- $(this).removeClass().addClass(rowclass);
- ct++;
- });
- // If this is the first item being added, remove
- // the "No items" message and show the list.
- if ($('table.data').find('tr').has('td').length > 0 &&
- $('#nothing2display').is(':visible')
- ) {
- $('#nothing2display').hide('slow', function () {
- $('table.data').show('slow');
- });
- }
- Navigation.reload();
- } else {
- ajaxShowMessage(data.error, false);
- }
- }); // end $.post()
- } // end "if (that.validate())"
- }; // end of function that handles the submission of the Editor
- buttonOptions[window.Messages.strClose].click = function () {
- $(this).dialog('close');
- };
- /**
- * Display the dialog to the user
- */
- that.$ajaxDialog = $('
' + data.message + '
').dialog({
- classes: {
- 'ui-dialog-titlebar-close': 'btn-close'
- },
- width: 700,
- minWidth: 500,
- buttons: buttonOptions,
- // Issue #15810 - use button titles for modals (eg: new procedure)
- // Respect the order: title on href tag, href content, title sent in response
- title: $this.attr('title') || $this.text() || $(data.title).text(),
- modal: true,
- open: function () {
- $('#rteDialog').dialog('option', 'max-height', $(window).height());
- if ($('#rteDialog').parents('.ui-dialog').height() > $(window).height()) {
- $('#rteDialog').dialog('option', 'height', $(window).height());
- }
- $(this).find('input[name=item_name]').trigger('focus');
- $(this).find('input.datefield').each(function () {
- Functions.addDatepicker($(this).css('width', '95%'), 'date');
- });
- $(this).find('input.datetimefield').each(function () {
- Functions.addDatepicker($(this).css('width', '95%'), 'datetime');
- });
- $.datepicker.initialized = false;
- },
- close: function () {
- $(this).remove();
- }
- });
- /**
- * @var mode Used to remember whether the editor is in
- * "Edit" or "Add" mode
- */
- var mode = 'add';
- if ($('input[name=editor_process_edit]').length > 0) {
- mode = 'edit';
- }
- // Attach syntax highlighted editor to the definition
- /**
- * @var elm jQuery object containing the reference to
- * the Definition textarea.
- */
- var $elm = $('textarea[name=item_definition]').last();
- var linterOptions = {};
- linterOptions.triggerEditor = true;
- that.syntaxHiglighter = Functions.getSqlEditor($elm, {}, 'both', linterOptions);
- } else {
+ if (data.success !== true) {
ajaxShowMessage(data.error, false);
+ return;
}
+ var buttonOptions = {
+ [window.Messages.strGo]: {
+ text: window.Messages.strGo,
+ class: 'btn btn-primary',
+ },
+ [window.Messages.strClose]: {
+ text: window.Messages.strClose,
+ class: 'btn btn-secondary',
+ },
+ };
+ // We have successfully fetched the editor form
+ ajaxRemoveMessage($msg);
+ // Now define the function that is called when
+ // the user presses the "Go" button
+ buttonOptions[window.Messages.strGo].click = function () {
+ // Move the data from the codemirror editor back to the
+ // textarea, where it can be used in the form submission.
+ if (typeof window.CodeMirror !== 'undefined') {
+ that.syntaxHiglighter.save();
+ }
+ // Validate editor and submit request, if passed.
+ if (! that.validate()) {
+ return;
+ }
+ /**
+ * @var data Form data to be sent in the AJAX request
+ */
+ var data = $('form.rte_form').last().serialize();
+ $msg = ajaxShowMessage(
+ window.Messages.strProcessingRequest
+ );
+ var url = $('form.rte_form').last().attr('action');
+ $.post(url, data, function (data) {
+ if (data.success !== true) {
+ ajaxShowMessage(data.error, false);
+ return;
+ }
+ // Item created successfully
+ ajaxRemoveMessage($msg);
+ Functions.slidingMessage(data.message);
+ that.$ajaxDialog.dialog('close');
+ // If we are in 'edit' mode, we must
+ // remove the reference to the old row.
+ if (mode === 'edit' && $editRow !== null) {
+ $editRow.remove();
+ }
+ // Sometimes, like when moving a trigger from
+ // a table to another one, the new row should
+ // not be inserted into the list. In this case
+ // "data.insert" will be set to false.
+ if (data.insert) {
+ // Insert the new row at the correct
+ // location in the list of items
+ /**
+ * @var text Contains the name of an item from
+ * the list that is used in comparisons
+ * to find the correct location where
+ * to insert a new row.
+ */
+ var text = '';
+ /**
+ * @var inserted Whether a new item has been
+ * inserted in the list or not
+ */
+ var inserted = false;
+ $('table.data').find('tr').each(function () {
+ text = $(this)
+ .children('td')
+ .eq(0)
+ .find('strong')
+ .text()
+ .toUpperCase()
+ .trim();
+ if (text !== '' && text > data.name) {
+ $(this).before(data.new_row);
+ inserted = true;
+ return false;
+ }
+ });
+ if (! inserted) {
+ // If we didn't manage to insert the row yet,
+ // it must belong at the end of the list,
+ // so we insert it there.
+ $('table.data').append(data.new_row);
+ }
+ // Fade-in the new row
+ $('tr.ajaxInsert')
+ .show('slow')
+ .removeClass('ajaxInsert');
+ } else if ($('table.data').find('tr').has('td').length === 0) {
+ // If we are not supposed to insert the new row,
+ // we will now check if the table is empty and
+ // needs to be hidden. This will be the case if
+ // we were editing the only item in the list,
+ // which we removed and will not be inserting
+ // something else in its place.
+ $('table.data').hide('slow', function () {
+ $('#nothing2display').show('slow');
+ });
+ }
+ // Now we have inserted the row at the correct
+ // position, but surely at least some row classes
+ // are wrong now. So we will iterate through
+ // all rows and assign correct classes to them
+ /**
+ * @var ct Count of processed rows
+ */
+ var ct = 0;
+ /**
+ * @var rowclass Class to be attached to the row
+ * that is being processed
+ */
+ var rowclass = '';
+ $('table.data').find('tr').has('td').each(function () {
+ rowclass = (ct % 2 === 0) ? 'odd' : 'even';
+ $(this).removeClass().addClass(rowclass);
+ ct++;
+ });
+ // If this is the first item being added, remove
+ // the "No items" message and show the list.
+ if ($('table.data').find('tr').has('td').length > 0 &&
+ $('#nothing2display').is(':visible')
+ ) {
+ $('#nothing2display').hide('slow', function () {
+ $('table.data').show('slow');
+ });
+ }
+ Navigation.reload();
+ }); // end $.post()
+ }; // end of function that handles the submission of the Editor
+ buttonOptions[window.Messages.strClose].click = function () {
+ $(this).dialog('close');
+ };
+ /**
+ * Display the dialog to the user
+ */
+ that.$ajaxDialog = $('
' + data.message + '
').dialog({
+ classes: {
+ 'ui-dialog-titlebar-close': 'btn-close'
+ },
+ width: 700,
+ minWidth: 500,
+ buttons: buttonOptions,
+ // Issue #15810 - use button titles for modals (eg: new procedure)
+ // Respect the order: title on href tag, href content, title sent in response
+ title: $this.attr('title') || $this.text() || $(data.title).text(),
+ modal: true,
+ open: function () {
+ $('#rteDialog').dialog('option', 'max-height', $(window).height());
+ if ($('#rteDialog').parents('.ui-dialog').height() > $(window).height()) {
+ $('#rteDialog').dialog('option', 'height', $(window).height());
+ }
+ $(this).find('input[name=item_name]').trigger('focus');
+ $(this).find('input.datefield').each(function () {
+ Functions.addDatepicker($(this).css('width', '95%'), 'date');
+ });
+ $(this).find('input.datetimefield').each(function () {
+ Functions.addDatepicker($(this).css('width', '95%'), 'datetime');
+ });
+ $.datepicker.initialized = false;
+ },
+ close: function () {
+ $(this).remove();
+ }
+ });
+ /**
+ * @var mode Used to remember whether the editor is in
+ * "Edit" or "Add" mode
+ */
+ var mode = 'add';
+ if ($('input[name=editor_process_edit]').length > 0) {
+ mode = 'edit';
+ }
+ // Attach syntax highlighted editor to the definition
+ /**
+ * @var elm jQuery object containing the reference to
+ * the Definition textarea.
+ */
+ var $elm = $('textarea[name=item_definition]').last();
+ var linterOptions = {};
+ linterOptions.triggerEditor = true;
+ that.syntaxHiglighter = Functions.getSqlEditor($elm, {}, 'both', linterOptions);
}); // end $.get()
},
@@ -375,54 +376,54 @@ const DatabaseTriggers = {
var $msg = ajaxShowMessage(window.Messages.strProcessingRequest);
var params = getJsConfirmCommonParam(this, $this.getPostData());
$.post(url, params, function (data) {
- if (data.success === true) {
- /**
- * @var $table Object containing reference
- * to the main list of elements
- */
- var $table = $currRow.parent();
- // Check how many rows will be left after we remove
- // the one that the user has requested us to remove
- if ($table.find('tr').length === 3) {
- // If there are two rows left, it means that they are
- // the header of the table and the rows that we are
- // about to remove, so after the removal there will be
- // nothing to show in the table, so we hide it.
- $table.hide('slow', function () {
- $(this).find('tr.even, tr.odd').remove();
- $('.withSelected').remove();
- $('#nothing2display').show('slow');
- });
- } else {
- $currRow.hide('slow', function () {
- $(this).remove();
- // Now we have removed the row from the list, but maybe
- // some row classes are wrong now. So we will iterate
- // through all rows and assign correct classes to them.
- /**
- * @var ct Count of processed rows
- */
- var ct = 0;
- /**
- * @var rowclass Class to be attached to the row
- * that is being processed
- */
- var rowclass = '';
- $table.find('tr').has('td').each(function () {
- rowclass = (ct % 2 === 1) ? 'odd' : 'even';
- $(this).removeClass().addClass(rowclass);
- ct++;
- });
- });
- }
- // Get rid of the "Loading" message
- ajaxRemoveMessage($msg);
- // Show the query that we just executed
- Functions.slidingMessage(data.sql_query);
- Navigation.reload();
- } else {
+ if (data.success !== true) {
ajaxShowMessage(data.error, false);
+ return;
}
+ /**
+ * @var $table Object containing reference
+ * to the main list of elements
+ */
+ var $table = $currRow.parent();
+ // Check how many rows will be left after we remove
+ // the one that the user has requested us to remove
+ if ($table.find('tr').length === 3) {
+ // If there are two rows left, it means that they are
+ // the header of the table and the rows that we are
+ // about to remove, so after the removal there will be
+ // nothing to show in the table, so we hide it.
+ $table.hide('slow', function () {
+ $(this).find('tr.even, tr.odd').remove();
+ $('.withSelected').remove();
+ $('#nothing2display').show('slow');
+ });
+ } else {
+ $currRow.hide('slow', function () {
+ $(this).remove();
+ // Now we have removed the row from the list, but maybe
+ // some row classes are wrong now. So we will iterate
+ // through all rows and assign correct classes to them.
+ /**
+ * @var ct Count of processed rows
+ */
+ var ct = 0;
+ /**
+ * @var rowclass Class to be attached to the row
+ * that is being processed
+ */
+ var rowclass = '';
+ $table.find('tr').has('td').each(function () {
+ rowclass = (ct % 2 === 1) ? 'odd' : 'even';
+ $(this).removeClass().addClass(rowclass);
+ ct++;
+ });
+ });
+ }
+ // Get rid of the "Loading" message
+ ajaxRemoveMessage($msg);
+ // Show the query that we just executed
+ Functions.slidingMessage(data.sql_query);
+ Navigation.reload();
}); // end $.post()
});
},
@@ -451,59 +452,59 @@ const DatabaseTriggers = {
var params = getJsConfirmCommonParam(this, $anchor.getPostData());
$.post($anchor.attr('href'), params, function (data) {
returnCount++;
- if (data.success === true) {
- /**
- * @var $table Object containing reference
- * to the main list of elements
- */
- var $table = $currRow.parent();
- // Check how many rows will be left after we remove
- // the one that the user has requested us to remove
- if ($table.find('tr').length === 3) {
- // If there are two rows left, it means that they are
- // the header of the table and the rows that we are
- // about to remove, so after the removal there will be
- // nothing to show in the table, so we hide it.
- $table.hide('slow', function () {
- $(this).find('tr.even, tr.odd').remove();
- $('.withSelected').remove();
- $('#nothing2display').show('slow');
- });
- } else {
- $currRow.hide('fast', function () {
- // we will iterate
- // through all rows and assign correct classes to them.
- /**
- * @var ct Count of processed rows
- */
- var ct = 0;
- /**
- * @var rowclass Class to be attached to the row
- * that is being processed
- */
- var rowclass = '';
- $table.find('tr').has('td').each(function () {
- rowclass = (ct % 2 === 1) ? 'odd' : 'even';
- $(this).removeClass().addClass(rowclass);
- ct++;
- });
- });
- $currRow.remove();
- }
- if (returnCount === count) {
- if (success) {
- // Get rid of the "Loading" message
- ajaxRemoveMessage($msg);
- $('#rteListForm_checkall').prop({ checked: false, indeterminate: false });
- }
- Navigation.reload();
- }
- } else {
+ if (data.success !== true) {
ajaxShowMessage(data.error, false);
success = false;
if (returnCount === count) {
Navigation.reload();
}
+ return;
+ }
+ /**
+ * @var $table Object containing reference
+ * to the main list of elements
+ */
+ var $table = $currRow.parent();
+ // Check how many rows will be left after we remove
+ // the one that the user has requested us to remove
+ if ($table.find('tr').length === 3) {
+ // If there are two rows left, it means that they are
+ // the header of the table and the rows that we are
+ // about to remove, so after the removal there will be
+ // nothing to show in the table, so we hide it.
+ $table.hide('slow', function () {
+ $(this).find('tr.even, tr.odd').remove();
+ $('.withSelected').remove();
+ $('#nothing2display').show('slow');
+ });
+ } else {
+ $currRow.hide('fast', function () {
+ // we will iterate
+ // through all rows and assign correct classes to them.
+ /**
+ * @var ct Count of processed rows
+ */
+ var ct = 0;
+ /**
+ * @var rowclass Class to be attached to the row
+ * that is being processed
+ */
+ var rowclass = '';
+ $table.find('tr').has('td').each(function () {
+ rowclass = (ct % 2 === 1) ? 'odd' : 'even';
+ $(this).removeClass().addClass(rowclass);
+ ct++;
+ });
+ });
+ $currRow.remove();
+ }
+ if (returnCount === count) {
+ if (success) {
+ // Get rid of the "Loading" message
+ ajaxRemoveMessage($msg);
+ $('#rteListForm_checkall').prop({ checked: false, indeterminate: false });
+ }
+ Navigation.reload();
}
}); // end $.post()
}); // end drop_anchors.each()
diff --git a/js/src/modules/functions.ts b/js/src/modules/functions.ts
index 515bcd7714..0a8d2f3719 100644
--- a/js/src/modules/functions.ts
+++ b/js/src/modules/functions.ts
@@ -161,45 +161,46 @@ function addDatepicker ($thisElement, type, options) {
* (only when jquery-ui-timepicker-addon.js is loaded)
*/
function addDateTimePicker () {
- if ($.timepicker !== undefined) {
- $('input.timefield, input.datefield, input.datetimefield').each(function () {
- var decimals = $(this).parent().attr('data-decimals');
- var type = $(this).parent().attr('data-type');
-
- var showMillisec = false;
- var showMicrosec = false;
- var timeFormat = 'HH:mm:ss';
- var hourMax = 23;
- // check for decimal places of seconds
- if (decimals > 0 && type.indexOf('time') !== -1) {
- if (decimals > 3) {
- showMillisec = true;
- showMicrosec = true;
- timeFormat = 'HH:mm:ss.lc';
- } else {
- showMillisec = true;
- timeFormat = 'HH:mm:ss.l';
- }
- }
- if (type === 'time') {
- hourMax = 99;
- }
- Functions.addDatepicker($(this), type, {
- showMillisec: showMillisec,
- showMicrosec: showMicrosec,
- timeFormat: timeFormat,
- hourMax: hourMax,
- firstDay: window.firstDayOfCalendar
- });
- // Add a tip regarding entering MySQL allowed-values
- // for TIME and DATE data-type
- if ($(this).hasClass('timefield')) {
- tooltip($(this), 'input', window.Messages.strMysqlAllowedValuesTipTime);
- } else if ($(this).hasClass('datefield')) {
- tooltip($(this), 'input', window.Messages.strMysqlAllowedValuesTipDate);
- }
- });
+ if ($.timepicker === undefined) {
+ return;
}
+ $('input.timefield, input.datefield, input.datetimefield').each(function () {
+ var decimals = $(this).parent().attr('data-decimals');
+ var type = $(this).parent().attr('data-type');
+
+ var showMillisec = false;
+ var showMicrosec = false;
+ var timeFormat = 'HH:mm:ss';
+ var hourMax = 23;
+ // check for decimal places of seconds
+ if (decimals > 0 && type.indexOf('time') !== -1) {
+ if (decimals > 3) {
+ showMillisec = true;
+ showMicrosec = true;
+ timeFormat = 'HH:mm:ss.lc';
+ } else {
+ showMillisec = true;
+ timeFormat = 'HH:mm:ss.l';
+ }
+ }
+ if (type === 'time') {
+ hourMax = 99;
+ }
+ Functions.addDatepicker($(this), type, {
+ showMillisec: showMillisec,
+ showMicrosec: showMicrosec,
+ timeFormat: timeFormat,
+ hourMax: hourMax,
+ firstDay: window.firstDayOfCalendar
+ });
+ // Add a tip regarding entering MySQL allowed-values
+ // for TIME and DATE data-type
+ if ($(this).hasClass('timefield')) {
+ tooltip($(this), 'input', window.Messages.strMysqlAllowedValuesTipTime);
+ } else if ($(this).hasClass('datefield')) {
+ tooltip($(this), 'input', window.Messages.strMysqlAllowedValuesTipDate);
+ }
+ });
}
/**
@@ -213,71 +214,71 @@ function addDateTimePicker () {
* @return {object|null}
*/
function getSqlEditor ($textarea, options, resize, lintOptions) {
- var resizeType = resize;
- if ($textarea.length > 0 && typeof window.CodeMirror !== 'undefined') {
- // merge options for CodeMirror
- var defaults = {
- lineNumbers: true,
- matchBrackets: true,
- extraKeys: { 'Ctrl-Space': 'autocomplete' },
- hintOptions: { 'completeSingle': false, 'completeOnSingleClick': true },
- indentUnit: 4,
- mode: 'text/x-mysql',
- lineWrapping: true
- };
-
- if (window.CodeMirror.sqlLint) {
- $.extend(defaults, {
- gutters: ['CodeMirror-lint-markers'],
- lint: {
- 'getAnnotations': window.CodeMirror.sqlLint,
- 'async': true,
- 'lintOptions': lintOptions
- }
- });
- }
-
- $.extend(true, defaults, options);
-
- // create CodeMirror editor
- var codemirrorEditor = window.CodeMirror.fromTextArea($textarea[0], defaults);
- // allow resizing
- if (! resizeType) {
- resizeType = 'vertical';
- }
- var handles = '';
- if (resizeType === 'vertical') {
- handles = 's';
- }
- if (resizeType === 'both') {
- handles = 'all';
- }
- if (resizeType === 'horizontal') {
- handles = 'e, w';
- }
- $(codemirrorEditor.getWrapperElement())
- .css('resize', resizeType)
- .resizable({
- handles: handles,
- resize: function () {
- codemirrorEditor.setSize($(this).width(), $(this).height());
- }
- });
- // enable autocomplete
- codemirrorEditor.on('inputRead', Functions.codeMirrorAutoCompleteOnInputRead);
-
- // page locking
- codemirrorEditor.on('change', function (e) {
- e.data = {
- value: 3,
- content: codemirrorEditor.isClean(),
- };
- AJAX.lockPageHandler(e);
- });
-
- return codemirrorEditor;
+ if ($textarea.length === 0 || typeof window.CodeMirror === 'undefined') {
+ return null;
}
- return null;
+ var resizeType = resize;
+ // merge options for CodeMirror
+ var defaults = {
+ lineNumbers: true,
+ matchBrackets: true,
+ extraKeys: { 'Ctrl-Space': 'autocomplete' },
+ hintOptions: { 'completeSingle': false, 'completeOnSingleClick': true },
+ indentUnit: 4,
+ mode: 'text/x-mysql',
+ lineWrapping: true
+ };
+
+ if (window.CodeMirror.sqlLint) {
+ $.extend(defaults, {
+ gutters: ['CodeMirror-lint-markers'],
+ lint: {
+ 'getAnnotations': window.CodeMirror.sqlLint,
+ 'async': true,
+ 'lintOptions': lintOptions
+ }
+ });
+ }
+
+ $.extend(true, defaults, options);
+
+ // create CodeMirror editor
+ var codemirrorEditor = window.CodeMirror.fromTextArea($textarea[0], defaults);
+ // allow resizing
+ if (! resizeType) {
+ resizeType = 'vertical';
+ }
+ var handles = '';
+ if (resizeType === 'vertical') {
+ handles = 's';
+ }
+ if (resizeType === 'both') {
+ handles = 'all';
+ }
+ if (resizeType === 'horizontal') {
+ handles = 'e, w';
+ }
+ $(codemirrorEditor.getWrapperElement())
+ .css('resize', resizeType)
+ .resizable({
+ handles: handles,
+ resize: function () {
+ codemirrorEditor.setSize($(this).width(), $(this).height());
+ }
+ });
+ // enable autocomplete
+ codemirrorEditor.on('inputRead', Functions.codeMirrorAutoCompleteOnInputRead);
+
+ // page locking
+ codemirrorEditor.on('change', function (e) {
+ e.data = {
+ value: 3,
+ content: codemirrorEditor.isClean(),
+ };
+ AJAX.lockPageHandler(e);
+ });
+
+ return codemirrorEditor;
}
/**
@@ -953,40 +954,40 @@ function setSelectOptions (theForm, theSelect, doCheck) {
* Updates the input fields for the parameters based on the query
*/
function updateQueryParameters () {
- if ($('#parameterized').is(':checked')) {
- var query = window.codeMirrorEditor ? window.codeMirrorEditor.getValue() : $('#sqlquery').val();
-
- var allParameters = query.match(/:[a-zA-Z0-9_]+/g);
- var parameters = [];
- // get unique parameters
- if (allParameters) {
- $.each(allParameters, function (i, parameter) {
- if ($.inArray(parameter, parameters) === -1) {
- parameters.push(parameter);
- }
- });
- } else {
- $('#parametersDiv').text(window.Messages.strNoParam);
- return;
- }
-
- var $temp = $('');
- $temp.append($('#parametersDiv').children());
+ if (! $('#parameterized').is(':checked')) {
$('#parametersDiv').empty();
+ return;
+ }
+ var query = window.codeMirrorEditor ? window.codeMirrorEditor.getValue() : $('#sqlquery').val();
- $.each(parameters, function (i, parameter) {
- var paramName = parameter.substring(1);
- var $param = $temp.find('#paramSpan_' + paramName);
- if (! $param.length) {
- $param = $('');
- $('').text(parameter).appendTo($param);
- $('').appendTo($param);
+ var allParameters = query.match(/:[a-zA-Z0-9_]+/g);
+ var parameters = [];
+ // get unique parameters
+ if (allParameters) {
+ $.each(allParameters, function (i, parameter) {
+ if ($.inArray(parameter, parameters) === -1) {
+ parameters.push(parameter);
}
- $('#parametersDiv').append($param);
});
} else {
- $('#parametersDiv').empty();
+ $('#parametersDiv').text(window.Messages.strNoParam);
+ return;
}
+
+ var $temp = $('');
+ $temp.append($('#parametersDiv').children());
+ $('#parametersDiv').empty();
+
+ $.each(parameters, function (i, parameter) {
+ var paramName = parameter.substring(1);
+ var $param = $temp.find('#paramSpan_' + paramName);
+ if (! $param.length) {
+ $param = $('');
+ $('').text(parameter).appendTo($param);
+ $('').appendTo($param);
+ }
+ $('#parametersDiv').append($param);
+ });
}
/**
@@ -1222,20 +1223,21 @@ function removeAutocompleteInfo () {
*/
function bindCodeMirrorToInlineEditor () {
var $inlineEditor = $('#sql_query_edit');
- if ($inlineEditor.length > 0) {
- if (typeof window.CodeMirror !== 'undefined') {
- var height = $inlineEditor.css('height');
- codeMirrorInlineEditor = Functions.getSqlEditor($inlineEditor);
- codeMirrorInlineEditor.getWrapperElement().style.height = height;
- codeMirrorInlineEditor.refresh();
- codeMirrorInlineEditor.focus();
- $(codeMirrorInlineEditor.getWrapperElement())
- .on('keydown', Functions.catchKeypressesFromSqlInlineEdit);
- } else {
- $inlineEditor
- .trigger('focus')
- .on('keydown', Functions.catchKeypressesFromSqlInlineEdit);
- }
+ if ($inlineEditor.length === 0) {
+ return;
+ }
+ if (typeof window.CodeMirror !== 'undefined') {
+ var height = $inlineEditor.css('height');
+ codeMirrorInlineEditor = Functions.getSqlEditor($inlineEditor);
+ codeMirrorInlineEditor.getWrapperElement().style.height = height;
+ codeMirrorInlineEditor.refresh();
+ codeMirrorInlineEditor.focus();
+ $(codeMirrorInlineEditor.getWrapperElement())
+ .on('keydown', Functions.catchKeypressesFromSqlInlineEdit);
+ } else {
+ $inlineEditor
+ .trigger('focus')
+ .on('keydown', Functions.catchKeypressesFromSqlInlineEdit);
}
}
@@ -1484,18 +1486,19 @@ function showNoticeForEnum (selectElement) {
* Hides/shows a warning message when LENGTH is used with inappropriate integer type
*/
function showWarningForIntTypes () {
- if ($('div#length_not_allowed').length) {
- var lengthRestrictions = $('select.column_type option').map(function () {
- return $(this).filter(':selected').attr('data-length-restricted');
- }).get();
+ if (! $('div#length_not_allowed').length) {
+ return;
+ }
+ var lengthRestrictions = $('select.column_type option').map(function () {
+ return $(this).filter(':selected').attr('data-length-restricted');
+ }).get();
- var restricationFound = lengthRestrictions.some(restriction => Number(restriction) === 1);
+ var restricationFound = lengthRestrictions.some(restriction => Number(restriction) === 1);
- if (restricationFound) {
- $('div#length_not_allowed').show();
- } else {
- $('div#length_not_allowed').hide();
- }
+ if (restricationFound) {
+ $('div#length_not_allowed').show();
+ } else {
+ $('div#length_not_allowed').hide();
}
}
@@ -1781,80 +1784,81 @@ function onloadCreateTableEvents (): void {
if (Functions.checkTableEditForm($form[0], $form.find('input[name=orig_num_fields]').val())) {
Functions.prepareForAjaxRequest($form);
- if (Functions.checkReservedWordColumns($form)) {
- ajaxShowMessage(window.Messages.strProcessingRequest);
- // User wants to submit the form
- $.post($form.attr('action'), $form.serialize() + CommonParams.get('arg_separator') + 'do_save_data=1', function (data) {
- if (typeof data !== 'undefined' && data.success === true) {
- $('#properties_message')
- .removeClass('alert-danger')
- .html('');
- ajaxShowMessage(data.message);
- // Only if the create table dialog (distinct panel) exists
- var $createTableDialog = $('#create_table_dialog');
- if ($createTableDialog.length > 0) {
- $createTableDialog.dialog('close').remove();
- }
- $('#tableslistcontainer').before(data.formatted_sql);
-
- /**
- * @var tables_table Object referring to the element that holds the list of tables
- */
- var tablesTable = $('#tablesForm').find('tbody').not('#tbl_summary_row');
- // this is the first table created in this db
- if (tablesTable.length === 0) {
- refreshMainContent(CommonParams.get('opendb_url'));
- } else {
- /**
- * @var curr_last_row Object referring to the last
element in {@link tablesTable}
- */
- var currLastRow = $(tablesTable).find('tr').last();
- /**
- * @var curr_last_row_index_string String containing the index of {@link currLastRow}
- */
- var currLastRowIndexString = $(currLastRow).find('input:checkbox').attr('id').match(/\d+/)[0];
- /**
- * @var curr_last_row_index Index of {@link currLastRow}
- */
- var currLastRowIndex = parseFloat(currLastRowIndexString);
- /**
- * @var new_last_row_index Index of the new row to be appended to {@link tablesTable}
- */
- var newLastRowIndex = currLastRowIndex + 1;
- /**
- * @var new_last_row_id String containing the id of the row to be appended to {@link tablesTable}
- */
- var newLastRowId = 'checkbox_tbl_' + newLastRowIndex;
-
- data.newTableString = data.newTableString.replace(/checkbox_tbl_/, newLastRowId);
- // append to table
- $(data.newTableString)
- .appendTo(tablesTable);
-
- // Sort the table
- $(tablesTable).sortTable('th');
-
- // Adjust summary row
- window.DatabaseStructure.adjustTotals();
- }
-
- // Refresh navigation as a new table has been added
- Navigation.reload();
- // Redirect to table structure page on creation of new table
- var argsep = CommonParams.get('arg_separator');
- var params12 = 'ajax_request=true' + argsep + 'ajax_page_request=true';
- var tableStructureUrl = 'index.php?route=/table/structure' + argsep + 'server=' + data.params.server +
- argsep + 'db=' + data.params.db + argsep + 'token=' + data.params.token +
- argsep + 'goto=' + encodeURIComponent('index.php?route=/database/structure') + argsep + 'table=' + data.params.table + '';
- $.get(tableStructureUrl, params12, AJAX.responseHandler);
- } else {
- ajaxShowMessage(
- '
' + data.error + '
',
- false
- );
- }
- }); // end $.post()
+ if (! Functions.checkReservedWordColumns($form)) {
+ return;
}
+ ajaxShowMessage(window.Messages.strProcessingRequest);
+ // User wants to submit the form
+ $.post($form.attr('action'), $form.serialize() + CommonParams.get('arg_separator') + 'do_save_data=1', function (data) {
+ if (typeof data === 'undefined' || data.success !== true) {
+ ajaxShowMessage(
+ '
' + data.error + '
',
+ false
+ );
+ return;
+ }
+ $('#properties_message')
+ .removeClass('alert-danger')
+ .html('');
+ ajaxShowMessage(data.message);
+ // Only if the create table dialog (distinct panel) exists
+ var $createTableDialog = $('#create_table_dialog');
+ if ($createTableDialog.length > 0) {
+ $createTableDialog.dialog('close').remove();
+ }
+ $('#tableslistcontainer').before(data.formatted_sql);
+
+ /**
+ * @var tables_table Object referring to the
element that holds the list of tables
+ */
+ var tablesTable = $('#tablesForm').find('tbody').not('#tbl_summary_row');
+ // this is the first table created in this db
+ if (tablesTable.length === 0) {
+ refreshMainContent(CommonParams.get('opendb_url'));
+ } else {
+ /**
+ * @var curr_last_row Object referring to the last
element in {@link tablesTable}
+ */
+ var currLastRow = $(tablesTable).find('tr').last();
+ /**
+ * @var curr_last_row_index_string String containing the index of {@link currLastRow}
+ */
+ var currLastRowIndexString = $(currLastRow).find('input:checkbox').attr('id').match(/\d+/)[0];
+ /**
+ * @var curr_last_row_index Index of {@link currLastRow}
+ */
+ var currLastRowIndex = parseFloat(currLastRowIndexString);
+ /**
+ * @var new_last_row_index Index of the new row to be appended to {@link tablesTable}
+ */
+ var newLastRowIndex = currLastRowIndex + 1;
+ /**
+ * @var new_last_row_id String containing the id of the row to be appended to {@link tablesTable}
+ */
+ var newLastRowId = 'checkbox_tbl_' + newLastRowIndex;
+
+ data.newTableString = data.newTableString.replace(/checkbox_tbl_/, newLastRowId);
+ // append to table
+ $(data.newTableString)
+ .appendTo(tablesTable);
+
+ // Sort the table
+ $(tablesTable).sortTable('th');
+
+ // Adjust summary row
+ window.DatabaseStructure.adjustTotals();
+ }
+
+ // Refresh navigation as a new table has been added
+ Navigation.reload();
+ // Redirect to table structure page on creation of new table
+ var argsep = CommonParams.get('arg_separator');
+ var params12 = 'ajax_request=true' + argsep + 'ajax_page_request=true';
+ var tableStructureUrl = 'index.php?route=/table/structure' + argsep + 'server=' + data.params.server +
+ argsep + 'db=' + data.params.db + argsep + 'token=' + data.params.token +
+ argsep + 'goto=' + encodeURIComponent('index.php?route=/database/structure') + argsep + 'table=' + data.params.table + '';
+ $.get(tableStructureUrl, params12, AJAX.responseHandler);
+ }); // end $.post()
}
}); // end create table form (save)
@@ -1875,16 +1879,16 @@ function onloadCreateTableEvents (): void {
// User wants to add more fields to the table
$.post($form.attr('action'), $form.serialize() + '&' + actionParam, function (data) {
- if (typeof data !== 'undefined' && data.success) {
- var $pageContent = $('#page_content');
- $pageContent.html(data.message);
- highlightSql($pageContent);
- Functions.verifyColumnsProperties();
- Functions.hideShowConnection($('.create_table_form select[name=tbl_storage_engine]'));
- ajaxRemoveMessage($msgbox);
- } else {
+ if (typeof data === 'undefined' || ! data.success) {
ajaxShowMessage(data.error);
+ return;
}
+ var $pageContent = $('#page_content');
+ $pageContent.html(data.message);
+ highlightSql($pageContent);
+ Functions.verifyColumnsProperties();
+ Functions.hideShowConnection($('.create_table_form select[name=tbl_storage_engine]'));
+ ajaxRemoveMessage($msgbox);
}); // end $.post()
}
@@ -1897,14 +1901,15 @@ function onloadCreateTableEvents (): void {
}); // end create table form (add fields)
$(document).on('keydown', 'form.create_table_form.ajax input[name=added_fields]', function (event) {
- if (event.keyCode === 13) {
- event.preventDefault();
- event.stopImmediatePropagation();
- $(this)
- .closest('form')
- .find('input[name=submit_num_fields]')
- .trigger('click');
+ if (event.keyCode !== 13) {
+ return;
}
+ event.preventDefault();
+ event.stopImmediatePropagation();
+ $(this)
+ .closest('form')
+ .find('input[name=submit_num_fields]')
+ .trigger('click');
});
/**
@@ -1921,13 +1926,14 @@ function onloadCreateTableEvents (): void {
});
$(document).on('change', 'input[value=AUTO_INCREMENT]', function () {
- if (this.checked) {
- var col = /\d/.exec($(this).attr('name'));
- col = col[0];
- var $selectFieldKey = $('select[name="field_key[' + col + ']"]');
- if ($selectFieldKey.val() === 'none_' + col) {
- $selectFieldKey.val('primary_' + col).trigger('change', [false]);
- }
+ if (! this.checked) {
+ return;
+ }
+ var col = /\d/.exec($(this).attr('name'));
+ col = col[0];
+ var $selectFieldKey = $('select[name="field_key[' + col + ']"]');
+ if ($selectFieldKey.val() === 'none_' + col) {
+ $selectFieldKey.val('primary_' + col).trigger('change', [false]);
}
});
$('body')
@@ -2682,16 +2688,17 @@ function indexDialogModal (routeUrl, url, title, callbackSuccess, callbackFailur
if (typeof data !== 'undefined' && data.success === false) {
// in the case of an error, show the error message returned.
ajaxShowMessage(data.error, false);
- } else {
- ajaxRemoveMessage($msgbox);
- // Show dialog if the request was successful
- modal.modal('show');
- modal.find('.modal-body').first().html(data.message);
- $('#indexDialogModalLabel').first().text(title);
- Functions.verifyColumnsProperties();
- modal.find('.tblFooters').remove();
- Functions.showIndexEditDialog(modal);
+ return;
}
+ ajaxRemoveMessage($msgbox);
+ // Show dialog if the request was successful
+ modal.modal('show');
+ // FIXME data may be undefiend
+ modal.find('.modal-body').first().html(data.message);
+ $('#indexDialogModalLabel').first().text(title);
+ Functions.verifyColumnsProperties();
+ modal.find('.tblFooters').remove();
+ Functions.showIndexEditDialog(modal);
}); // end $.get()
}
@@ -2960,27 +2967,28 @@ function onloadRecentFavoriteTables (): void {
}
// Sync favorite tables from localStorage to pmadb.
- if ($('#sync_favorite_tables').length) {
- $.ajax({
- url: $('#sync_favorite_tables').attr('href'),
- cache: false,
- type: 'POST',
- data: {
- 'favoriteTables': (isStorageSupported('localStorage') && typeof window.localStorage.favoriteTables !== 'undefined')
- ? window.localStorage.favoriteTables
- : '',
- 'server': CommonParams.get('server'),
- 'no_debug': true
- },
- success: function (data) {
- // Update localStorage.
- if (isStorageSupported('localStorage')) {
- window.localStorage.favoriteTables = data.favoriteTables;
- }
- $('#pma_favorite_list').html(data.list);
- }
- });
+ if (! $('#sync_favorite_tables').length) {
+ return;
}
+ $.ajax({
+ url: $('#sync_favorite_tables').attr('href'),
+ cache: false,
+ type: 'POST',
+ data: {
+ 'favoriteTables': (isStorageSupported('localStorage') && typeof window.localStorage.favoriteTables !== 'undefined')
+ ? window.localStorage.favoriteTables
+ : '',
+ 'server': CommonParams.get('server'),
+ 'no_debug': true
+ },
+ success: function (data) {
+ // Update localStorage.
+ if (isStorageSupported('localStorage')) {
+ window.localStorage.favoriteTables = data.favoriteTables;
+ }
+ $('#pma_favorite_list').html(data.list);
+ }
+ });
}
/**
@@ -3093,11 +3101,12 @@ function onloadCodeMirrorEditor (): void {
}
function teardownCodeMirrorEditor (): void {
- if (window.codeMirrorEditor) {
- $('#sqlquery').text(window.codeMirrorEditor.getValue());
- window.codeMirrorEditor.toTextArea();
- window.codeMirrorEditor = false;
+ if (! window.codeMirrorEditor) {
+ return;
}
+ $('#sqlquery').text(window.codeMirrorEditor.getValue());
+ window.codeMirrorEditor.toTextArea();
+ window.codeMirrorEditor = false;
}
function onloadLockPage (): void {
@@ -3227,28 +3236,29 @@ function onloadCreateView () {
*/
function floatingMenuBar () {
return function () {
- if ($('#floating_menubar').length && $('#PMA_disable_floating_menubar').length === 0) {
- var left = $('html').attr('dir') === 'ltr' ? 'left' : 'right';
- $('#floating_menubar')
- .css('margin-' + left, $('#pma_navigation').width() + $('#pma_navigation_resizer').width())
- .css(left, 0)
- .css({
- 'position': 'fixed',
- 'top': 0,
- 'width': '100%',
- 'z-index': 99
- })
- .append($('#server-breadcrumb'))
- .append($('#topmenucontainer'));
- // Allow the DOM to render, then adjust the padding on the body
- setTimeout(function () {
- $('body').css(
- 'padding-top',
- $('#floating_menubar').outerHeight(true)
- );
- $('#topmenu').menuResizer('resize');
- }, 4);
+ if (! $('#floating_menubar').length || $('#PMA_disable_floating_menubar').length !== 0) {
+ return;
}
+ var left = $('html').attr('dir') === 'ltr' ? 'left' : 'right';
+ $('#floating_menubar')
+ .css('margin-' + left, $('#pma_navigation').width() + $('#pma_navigation_resizer').width())
+ .css(left, 0)
+ .css({
+ 'position': 'fixed',
+ 'top': 0,
+ 'width': '100%',
+ 'z-index': 99
+ })
+ .append($('#server-breadcrumb'))
+ .append($('#topmenucontainer'));
+ // Allow the DOM to render, then adjust the padding on the body
+ setTimeout(function () {
+ $('body').css(
+ 'padding-top',
+ $('#floating_menubar').outerHeight(true)
+ );
+ $('#topmenu').menuResizer('resize');
+ }, 4);
};
}
@@ -3476,16 +3486,17 @@ window.recaptchaCallback = function () {
*/
function getKeyboardFormSubmitEventHandler () {
return function (e) {
- if ((e.ctrlKey && e.which === 13) || (e.altKey && e.which === 13)) {
- var $form = $(this).closest('form');
+ if (e.which !== 13 || ! (e.ctrlKey || e.altKey)) {
+ return;
+ }
+ var $form = $(this).closest('form');
- // There could be multiple submit buttons on the same form,
- // we assume all of them behave identical and just click one.
- if (! $form.find('input[type="submit"]').first() ||
- ! $form.find('input[type="submit"]').first().trigger('click')
- ) {
- $form.trigger('submit');
- }
+ // There could be multiple submit buttons on the same form,
+ // we assume all of them behave identical and just click one.
+ if (! $form.find('input[type="submit"]').first() ||
+ ! $form.find('input[type="submit"]').first().trigger('click')
+ ) {
+ $form.trigger('submit');
}
};
}