Skip to content

Commit e7c7e6e

Browse files
committed
Extract Indexed.checkIndexType() to a module
Signed-off-by: Maurício Meneghini Fauth <mauricio@fauth.dev>
1 parent b4b43e3 commit e7c7e6e

3 files changed

Lines changed: 87 additions & 85 deletions

File tree

‎js/src/modules/functions.js‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import $ from 'jquery';
22
import { AJAX } from './ajax.js';
33
import { Navigation } from './navigation.js';
44
import { CommonParams } from './common.js';
5-
import { Indexes } from './indexes.js';
65
import { Config } from './config.js';
76
import tooltip from './tooltip.js';
87
import highlightSql from './sql-highlight.js';
@@ -12,6 +11,7 @@ import { escapeHtml } from './functions/escape.js';
1211
import getImageTag from './functions/getImageTag.js';
1312
import handleRedirectAndReload from './functions/handleRedirectAndReload.js';
1413
import refreshMainContent from './functions/refreshMainContent.js';
14+
import checkIndexType from './indexes/checkIndexType.js';
1515

1616
/* global DatabaseStructure */ // js/database/structure.js
1717
/* global firstDayOfCalendar, themeImagePath */ // templates/javascript/variables.twig
@@ -2759,7 +2759,7 @@ Functions.indexRenameDialog = function (url, title, callbackSuccess, callbackFai
27592759
};
27602760

27612761
Functions.showIndexEditDialog = function ($outer) {
2762-
Indexes.checkIndexType();
2762+
checkIndexType();
27632763
Functions.checkIndexName('index_frm');
27642764
var $indexColumns = $('#index_columns');
27652765
$indexColumns.find('td').each(function () {

‎js/src/modules/indexes.js‎

Lines changed: 2 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import highlightSql from './sql-highlight.js';
77
import { ajaxRemoveMessage, ajaxShowMessage } from './ajax-message.js';
88
import getJsConfirmCommonParam from './functions/getJsConfirmCommonParam.js';
99
import refreshMainContent from './functions/refreshMainContent.js';
10+
import checkIndexType from './indexes/checkIndexType.js';
1011

1112
/**
1213
* @fileoverview function used for index manipulation pages
@@ -89,88 +90,6 @@ Indexes.getIndexArray = function (indexChoice) {
8990
return sourceArray;
9091
};
9192

92-
/**
93-
* Hides/shows the inputs and submits appropriately depending
94-
* on whether the index type chosen is 'SPATIAL' or not.
95-
*/
96-
Indexes.checkIndexType = function () {
97-
/**
98-
* @var {JQuery<HTMLElement}, Dropdown to select the index choice.
99-
*/
100-
var $selectIndexChoice = $('#select_index_choice');
101-
/**
102-
* @var {JQuery<HTMLElement}, Dropdown to select the index type.
103-
*/
104-
var $selectIndexType = $('#select_index_type');
105-
/**
106-
* @var {JQuery<HTMLElement}, Table header for the size column.
107-
*/
108-
var $sizeHeader = $('#index_columns').find('thead tr').children('th').eq(1);
109-
/**
110-
* @var {JQuery<HTMLElement}, Inputs to specify the columns for the index.
111-
*/
112-
var $columnInputs = $('select[name="index[columns][names][]"]');
113-
/**
114-
* @var {JQuery<HTMLElement}, Inputs to specify sizes for columns of the index.
115-
*/
116-
var $sizeInputs = $('input[name="index[columns][sub_parts][]"]');
117-
/**
118-
* @var {JQuery<HTMLElement}, Footer containing the controllers to add more columns
119-
*/
120-
var $addMore = $('#index_frm').find('.add_more');
121-
122-
if ($selectIndexChoice.val() === 'SPATIAL') {
123-
// Disable and hide the size column
124-
$sizeHeader.hide();
125-
$sizeInputs.each(function () {
126-
$(this)
127-
.prop('disabled', true)
128-
.parent('td').hide();
129-
});
130-
131-
// Disable and hide the columns of the index other than the first one
132-
var initial = true;
133-
$columnInputs.each(function () {
134-
var $columnInput = $(this);
135-
if (! initial) {
136-
$columnInput
137-
.prop('disabled', true)
138-
.parent('td').hide();
139-
} else {
140-
initial = false;
141-
}
142-
});
143-
144-
// Hide controllers to add more columns
145-
$addMore.hide();
146-
} else {
147-
// Enable and show the size column
148-
$sizeHeader.show();
149-
$sizeInputs.each(function () {
150-
$(this)
151-
.prop('disabled', false)
152-
.parent('td').show();
153-
});
154-
155-
// Enable and show the columns of the index
156-
$columnInputs.each(function () {
157-
$(this)
158-
.prop('disabled', false)
159-
.parent('td').show();
160-
});
161-
162-
// Show controllers to add more columns
163-
$addMore.show();
164-
}
165-
166-
if ($selectIndexChoice.val() === 'SPATIAL' ||
167-
$selectIndexChoice.val() === 'FULLTEXT') {
168-
$selectIndexType.val('').prop('disabled', true);
169-
} else {
170-
$selectIndexType.prop('disabled', false);
171-
}
172-
};
173-
17493
/**
17594
* Sets current index information into form parameters.
17695
*
@@ -643,7 +562,7 @@ Indexes.on = () => function () {
643562

644563
$(document).on('change', '#select_index_choice', function (event) {
645564
event.preventDefault();
646-
Indexes.checkIndexType();
565+
checkIndexType();
647566
Functions.checkIndexName('index_frm');
648567
});
649568

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
import $ from 'jquery';
2+
3+
/**
4+
* Hides/shows the inputs and submits appropriately depending
5+
* on whether the index type chosen is 'SPATIAL' or not.
6+
*/
7+
export default function checkIndexType () {
8+
/**
9+
* @var {JQuery<HTMLElement}, Dropdown to select the index choice.
10+
*/
11+
var $selectIndexChoice = $('#select_index_choice');
12+
/**
13+
* @var {JQuery<HTMLElement}, Dropdown to select the index type.
14+
*/
15+
var $selectIndexType = $('#select_index_type');
16+
/**
17+
* @var {JQuery<HTMLElement}, Table header for the size column.
18+
*/
19+
var $sizeHeader = $('#index_columns').find('thead tr').children('th').eq(1);
20+
/**
21+
* @var {JQuery<HTMLElement}, Inputs to specify the columns for the index.
22+
*/
23+
var $columnInputs = $('select[name="index[columns][names][]"]');
24+
/**
25+
* @var {JQuery<HTMLElement}, Inputs to specify sizes for columns of the index.
26+
*/
27+
var $sizeInputs = $('input[name="index[columns][sub_parts][]"]');
28+
/**
29+
* @var {JQuery<HTMLElement}, Footer containing the controllers to add more columns
30+
*/
31+
var $addMore = $('#index_frm').find('.add_more');
32+
33+
if ($selectIndexChoice.val() === 'SPATIAL') {
34+
// Disable and hide the size column
35+
$sizeHeader.hide();
36+
$sizeInputs.each(function () {
37+
$(this)
38+
.prop('disabled', true)
39+
.parent('td').hide();
40+
});
41+
42+
// Disable and hide the columns of the index other than the first one
43+
var initial = true;
44+
$columnInputs.each(function () {
45+
var $columnInput = $(this);
46+
if (! initial) {
47+
$columnInput
48+
.prop('disabled', true)
49+
.parent('td').hide();
50+
} else {
51+
initial = false;
52+
}
53+
});
54+
55+
// Hide controllers to add more columns
56+
$addMore.hide();
57+
} else {
58+
// Enable and show the size column
59+
$sizeHeader.show();
60+
$sizeInputs.each(function () {
61+
$(this)
62+
.prop('disabled', false)
63+
.parent('td').show();
64+
});
65+
66+
// Enable and show the columns of the index
67+
$columnInputs.each(function () {
68+
$(this)
69+
.prop('disabled', false)
70+
.parent('td').show();
71+
});
72+
73+
// Show controllers to add more columns
74+
$addMore.show();
75+
}
76+
77+
if ($selectIndexChoice.val() === 'SPATIAL' ||
78+
$selectIndexChoice.val() === 'FULLTEXT') {
79+
$selectIndexType.val('').prop('disabled', true);
80+
} else {
81+
$selectIndexType.prop('disabled', false);
82+
}
83+
}

0 commit comments

Comments
 (0)