diff --git a/js/src/modules/functions.js b/js/src/modules/functions.js index 833e35c72f..72950db7ee 100644 --- a/js/src/modules/functions.js +++ b/js/src/modules/functions.js @@ -56,36 +56,6 @@ let sqlAutoCompleteDefaultTable = ''; */ window.centralColumnList = []; -/** - * Array to hold 'Primary' index columns. - * @type {array} - */ -window.primaryIndexes = []; - -/** - * Array to hold 'Unique' index columns. - * @type {array} - */ -window.uniqueIndexes = []; - -/** - * Array to hold 'Index' columns. - * @type {array} - */ -window.indexes = []; - -/** - * Array to hold 'Fulltext' columns. - * @type {array} - */ -window.fulltextIndexes = []; - -/** - * Array to hold 'Spatial' columns. - * @type {array} - */ -window.spatialIndexes = []; - /** * Make sure that ajax requests will not be cached by appending a random variable to their parameters. * @return {function} diff --git a/js/src/modules/indexes.js b/js/src/modules/indexes.js index 14becaf751..64a32c1f06 100644 --- a/js/src/modules/indexes.js +++ b/js/src/modules/indexes.js @@ -14,6 +14,47 @@ import { ajaxRemoveMessage, ajaxShowMessage } from './ajax-message.js'; */ const Indexes = {}; +/** + * Array to hold 'Primary' index columns. + * @type {array} + */ +let primaryColumns = []; + +/** + * Array to hold 'Unique' index columns. + * @type {array} + */ +let uniqueColumns = []; + +/** + * Array to hold 'Index' columns. + * @type {array} + */ +let indexColumns = []; + +/** + * Array to hold 'Fulltext' columns. + * @type {array} + */ +let fulltextColumns = []; + +/** + * Array to hold 'Spatial' columns. + * @type {array} + */ +let spatialColumns = []; + +/** + * @return {void} + */ +Indexes.resetColumnLists = () => { + primaryColumns = []; + uniqueColumns = []; + indexColumns = []; + fulltextColumns = []; + spatialColumns = []; +}; + /** * Returns the array of indexes based on the index choice * @@ -22,23 +63,23 @@ const Indexes = {}; * @return {null|object} */ Indexes.getIndexArray = function (indexChoice) { - var sourceArray = null; + let sourceArray = null; switch (indexChoice.toLowerCase()) { case 'primary': - sourceArray = window.primaryIndexes; + sourceArray = primaryColumns; break; case 'unique': - sourceArray = window.uniqueIndexes; + sourceArray = uniqueColumns; break; case 'index': - sourceArray = window.indexes; + sourceArray = indexColumns; break; case 'fulltext': - sourceArray = window.fulltextIndexes; + sourceArray = fulltextColumns; break; case 'spatial': - sourceArray = window.spatialIndexes; + sourceArray = spatialColumns; break; default: return null; @@ -570,12 +611,7 @@ Indexes.off = () => function () { * @return {function} */ Indexes.on = () => function () { - // Re-initialize variables. - window.primaryIndexes = []; - window.uniqueIndexes = []; - window.indexes = []; - window.fulltextIndexes = []; - window.spatialIndexes = []; + Indexes.resetColumnLists(); // for table creation form var $engineSelector = $('.create_table_form select[name=tbl_storage_engine]'); diff --git a/js/src/table/structure.js b/js/src/table/structure.js index 1ba9c57766..897528a8d4 100644 --- a/js/src/table/structure.js +++ b/js/src/table/structure.js @@ -5,6 +5,7 @@ import { Navigation } from '../modules/navigation.js'; import { CommonActions, CommonParams } from '../modules/common.js'; import highlightSql from '../modules/sql-highlight.js'; import { ajaxRemoveMessage, ajaxShowMessage } from '../modules/ajax-message.js'; +import { Indexes } from '../modules/indexes.js'; /** * @fileoverview functions used on the table structure page @@ -58,11 +59,7 @@ AJAX.registerTeardown('table/structure.js', function () { }); AJAX.registerOnload('table/structure.js', function () { - // Re-initialize variables. - window.primaryIndexes = []; - window.indexes = []; - window.fulltextIndexes = []; - window.spatialIndexes = []; + Indexes.resetColumnLists(); /** *Ajax action for submitting the "Column Change" and "Add Column" form