Skip to content

Commit 196dad2

Browse files
committed
Extract some sql.js functions from functions.js file
Signed-off-by: Maurício Meneghini Fauth <mauricio@fauth.dev>
1 parent 8cee139 commit 196dad2

2 files changed

Lines changed: 192 additions & 191 deletions

File tree

js/src/functions.js

Lines changed: 0 additions & 185 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,6 @@
1414
*/
1515
var Functions = {};
1616

17-
/**
18-
* @type {boolean} lock for the sqlbox textarea in the querybox
19-
*/
20-
let sqlBoxLocked = false;
21-
22-
/**
23-
* @type {boolean[]} holds elements which content should only selected once
24-
*/
25-
const onlyOnceElements = [];
26-
2717
/**
2818
* @var {number} ajaxMessageCount Number of AJAX messages shown since page load
2919
*/
@@ -628,25 +618,6 @@ Functions.displayPasswordGenerateButton = function () {
628618
}
629619
};
630620

631-
/**
632-
* selects the content of a given object, f.e. a textarea
633-
*
634-
* @param {HTMLTextAreaElement} element Element of which the content will be selected
635-
*/
636-
Functions.selectContent = function (element) {
637-
if (onlyOnceElements[element.name]) {
638-
return;
639-
}
640-
641-
onlyOnceElements[element.name] = true;
642-
643-
if (sqlBoxLocked) {
644-
return;
645-
}
646-
647-
element.select();
648-
};
649-
650621
/**
651622
* Displays a confirmation box before submitting a "DROP/DELETE/ALTER" query.
652623
* This function is called while clicking links
@@ -1113,162 +1084,6 @@ Functions.setSelectOptions = function (theForm, theSelect, doCheck) {
11131084
return true;
11141085
};
11151086

1116-
/**
1117-
* Sets current value for query box.
1118-
* @param {string} query
1119-
* @return {void}
1120-
*/
1121-
Functions.setQuery = function (query) {
1122-
if (codeMirrorEditor) {
1123-
codeMirrorEditor.setValue(query);
1124-
codeMirrorEditor.focus();
1125-
} else if (document.sqlform) {
1126-
document.sqlform.sql_query.value = query;
1127-
document.sqlform.sql_query.focus();
1128-
}
1129-
};
1130-
1131-
/**
1132-
* Create quick sql statements.
1133-
*
1134-
* @param {'clear'|'format'|'saved'|'selectall'|'select'|'insert'|'update'|'delete'} queryType
1135-
*
1136-
*/
1137-
Functions.insertQuery = function (queryType) {
1138-
var table;
1139-
if (queryType === 'clear') {
1140-
Functions.setQuery('');
1141-
return;
1142-
} else if (queryType === 'format') {
1143-
if (codeMirrorEditor) {
1144-
$('#querymessage').html(Messages.strFormatting +
1145-
'&nbsp;<img class="ajaxIcon" src="' +
1146-
themeImagePath + 'ajax_clock_small.gif" alt="">');
1147-
var params = {
1148-
'ajax_request': true,
1149-
'sql': codeMirrorEditor.getValue(),
1150-
'server': CommonParams.get('server')
1151-
};
1152-
$.ajax({
1153-
type: 'POST',
1154-
url: 'index.php?route=/database/sql/format',
1155-
data: params,
1156-
success: function (data) {
1157-
if (data.success) {
1158-
codeMirrorEditor.setValue(data.sql);
1159-
}
1160-
$('#querymessage').html('');
1161-
},
1162-
error: function () {
1163-
$('#querymessage').html('');
1164-
}
1165-
});
1166-
}
1167-
return;
1168-
} else if (queryType === 'saved') {
1169-
var db = $('input[name="db"]').val();
1170-
table = $('input[name="table"]').val();
1171-
var key = db;
1172-
if (table !== undefined) {
1173-
key += '.' + table;
1174-
}
1175-
key = 'autoSavedSql_' + key;
1176-
if (isStorageSupported('localStorage') &&
1177-
typeof window.localStorage.getItem(key) === 'string') {
1178-
Functions.setQuery(window.localStorage.getItem(key));
1179-
} else if (Cookies.get(key, { path: CommonParams.get('rootPath') })) {
1180-
Functions.setQuery(Cookies.get(key, { path: CommonParams.get('rootPath') }));
1181-
} else {
1182-
Functions.ajaxShowMessage(Messages.strNoAutoSavedQuery);
1183-
}
1184-
return;
1185-
}
1186-
1187-
var query = '';
1188-
var myListBox = document.sqlform.dummy;
1189-
table = document.sqlform.table.value;
1190-
1191-
if (myListBox.options.length > 0) {
1192-
sqlBoxLocked = true;
1193-
var columnsList = '';
1194-
var valDis = '';
1195-
var editDis = '';
1196-
var NbSelect = 0;
1197-
for (var i = 0; i < myListBox.options.length; i++) {
1198-
NbSelect++;
1199-
if (NbSelect > 1) {
1200-
columnsList += ', ';
1201-
valDis += ',';
1202-
editDis += ',';
1203-
}
1204-
columnsList += myListBox.options[i].value;
1205-
valDis += '\'[value-' + NbSelect + ']\'';
1206-
editDis += myListBox.options[i].value + '=\'[value-' + NbSelect + ']\'';
1207-
}
1208-
if (queryType === 'selectall') {
1209-
query = 'SELECT * FROM `' + table + '` WHERE 1';
1210-
} else if (queryType === 'select') {
1211-
query = 'SELECT ' + columnsList + ' FROM `' + table + '` WHERE 1';
1212-
} else if (queryType === 'insert') {
1213-
query = 'INSERT INTO `' + table + '`(' + columnsList + ') VALUES (' + valDis + ')';
1214-
} else if (queryType === 'update') {
1215-
query = 'UPDATE `' + table + '` SET ' + editDis + ' WHERE 1';
1216-
} else if (queryType === 'delete') {
1217-
query = 'DELETE FROM `' + table + '` WHERE 0';
1218-
}
1219-
Functions.setQuery(query);
1220-
sqlBoxLocked = false;
1221-
}
1222-
};
1223-
1224-
/**
1225-
* Inserts multiple fields.
1226-
*
1227-
*/
1228-
Functions.insertValueQuery = function () {
1229-
var myQuery = document.sqlform.sql_query;
1230-
var myListBox = document.sqlform.dummy;
1231-
1232-
if (myListBox.options.length > 0) {
1233-
sqlBoxLocked = true;
1234-
var columnsList = '';
1235-
var NbSelect = 0;
1236-
for (var i = 0; i < myListBox.options.length; i++) {
1237-
if (myListBox.options[i].selected) {
1238-
NbSelect++;
1239-
if (NbSelect > 1) {
1240-
columnsList += ', ';
1241-
}
1242-
columnsList += myListBox.options[i].value;
1243-
}
1244-
}
1245-
1246-
/* CodeMirror support */
1247-
if (codeMirrorEditor) {
1248-
codeMirrorEditor.replaceSelection(columnsList);
1249-
codeMirrorEditor.focus();
1250-
// IE support
1251-
} else if (document.selection) {
1252-
myQuery.focus();
1253-
var sel = document.selection.createRange();
1254-
sel.text = columnsList;
1255-
// MOZILLA/NETSCAPE support
1256-
} else if (document.sqlform.sql_query.selectionStart || document.sqlform.sql_query.selectionStart === '0') {
1257-
var startPos = document.sqlform.sql_query.selectionStart;
1258-
var endPos = document.sqlform.sql_query.selectionEnd;
1259-
var SqlString = document.sqlform.sql_query.value;
1260-
1261-
myQuery.value = SqlString.substring(0, startPos) + columnsList + SqlString.substring(endPos, SqlString.length);
1262-
myQuery.focus();
1263-
} else {
1264-
myQuery.value += columnsList;
1265-
}
1266-
1267-
// eslint-disable-next-line no-unused-vars
1268-
sqlBoxLocked = false;
1269-
}
1270-
};
1271-
12721087
/**
12731088
* Updates the input fields for the parameters based on the query
12741089
*/

0 commit comments

Comments
 (0)