Skip to content

Commit 7039a1f

Browse files
Merge pull request #19241 from MauricioFauth/function-global-removal
Remove the Functions JS global object
2 parents 61c13b0 + d65d0b2 commit 7039a1f

40 files changed

Lines changed: 416 additions & 451 deletions

resources/js/global.d.ts

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,18 +15,12 @@ interface Window {
1515
}
1616

1717
interface JQuery {
18-
getPostData: () => string;
19-
2018
sortableTable: (method: any) => any;
2119

2220
noSelect: (p?: any) => any;
2321

2422
menuResizer: (method: string|Function) => any;
2523

26-
confirm: (question: string, url: string, callbackFn: Function, openCallback?: Function) => boolean;
27-
28-
sortTable: (textSelector: string) => JQuery<HTMLElement>;
29-
3024
filterByValue: (value: any) => any;
3125

3226
uiTooltip(): JQuery;

resources/js/src/database/events.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import $ from 'jquery';
22
import { AJAX } from '../modules/ajax.ts';
3-
import { Functions } from '../modules/functions.ts';
3+
import { addDatepicker, getSqlEditor, slidingMessage } from '../modules/functions.ts';
44
import { Navigation } from '../modules/navigation.ts';
55
import { ajaxRemoveMessage, ajaxShowMessage } from '../modules/ajax-message.ts';
66
import getJsConfirmCommonParam from '../modules/functions/getJsConfirmCommonParam.ts';
@@ -144,7 +144,7 @@ const DatabaseEvents = {
144144
* to the Export textarea.
145145
*/
146146
var $elm = $ajaxDialog.find('textarea');
147-
Functions.getSqlEditor($elm);
147+
getSqlEditor($elm);
148148
} // end showExport()
149149
}, // end exportDialog()
150150
editorDialog: function (isNew, $this) {
@@ -220,7 +220,7 @@ const DatabaseEvents = {
220220

221221
// Item created successfully
222222
ajaxRemoveMessage($msg);
223-
Functions.slidingMessage(data.message);
223+
slidingMessage(data.message);
224224
that.$ajaxDialog.dialog('close');
225225
// If we are in 'edit' mode, we must
226226
// remove the reference to the old row.
@@ -350,11 +350,11 @@ const DatabaseEvents = {
350350

351351
$(this).find('input[name=item_name]').trigger('focus');
352352
$(this).find('input.datefield').each(function () {
353-
Functions.addDatepicker($(this).css('width', '95%'), 'date');
353+
addDatepicker($(this).css('width', '95%'), 'date');
354354
});
355355

356356
$(this).find('input.datetimefield').each(function () {
357-
Functions.addDatepicker($(this).css('width', '95%'), 'datetime');
357+
addDatepicker($(this).css('width', '95%'), 'datetime');
358358
});
359359

360360
// @ts-ignore
@@ -383,7 +383,7 @@ const DatabaseEvents = {
383383
var linterOptions = {
384384
editorType: 'event',
385385
};
386-
that.syntaxHiglighter = Functions.getSqlEditor($elm, {}, 'vertical', linterOptions);
386+
that.syntaxHiglighter = getSqlEditor($elm, {}, 'vertical', linterOptions);
387387
window.codeMirrorEditor = that.syntaxHiglighter;
388388
}); // end $.get()
389389
},
@@ -457,7 +457,7 @@ const DatabaseEvents = {
457457
// Get rid of the "Loading" message
458458
ajaxRemoveMessage($msg);
459459
// Show the query that we just executed
460-
Functions.slidingMessage(data.sql_query);
460+
slidingMessage(data.sql_query);
461461
Navigation.reload();
462462
}); // end $.post()
463463
});

resources/js/src/database/multi_table_query.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import $ from 'jquery';
22
import { AJAX } from '../modules/ajax.ts';
3-
import { Functions } from '../modules/functions.ts';
3+
import { getSqlEditor } from '../modules/functions.ts';
44
import { CommonParams } from '../modules/common.ts';
55
import { ajaxShowMessage } from '../modules/ajax-message.ts';
66
import { escapeBacktick } from '../modules/functions/escape.ts';
@@ -38,7 +38,7 @@ AJAX.registerTeardown('database/multi_table_query.js', function () {
3838
});
3939

4040
AJAX.registerOnload('database/multi_table_query.js', function () {
41-
var editor = Functions.getSqlEditor($('#MultiSqlquery'), {}, 'vertical');
41+
var editor = getSqlEditor($('#MultiSqlquery'), {}, 'vertical');
4242
$('.CodeMirror-line').css('text-align', 'left');
4343
editor.setSize(-1, 50);
4444

resources/js/src/database/operations.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import $ from 'jquery';
22
import { AJAX } from '../modules/ajax.ts';
3-
import { Functions } from '../modules/functions.ts';
3+
import { emptyCheckTheField, prepareForAjaxRequest } from '../modules/functions.ts';
44
import { Navigation } from '../modules/navigation.ts';
55
import { CommonParams } from '../modules/common.ts';
66
import { ajaxShowMessage } from '../modules/ajax-message.ts';
@@ -42,7 +42,7 @@ AJAX.registerOnload('database/operations.js', function () {
4242
$(document).on('submit', '#rename_db_form.ajax', function (event) {
4343
event.preventDefault();
4444

45-
if (Functions.emptyCheckTheField(this, 'newname')) {
45+
if (emptyCheckTheField(this, 'newname')) {
4646
ajaxShowMessage(window.Messages.strFormEmpty, false, 'error');
4747

4848
return false;
@@ -61,7 +61,7 @@ AJAX.registerOnload('database/operations.js', function () {
6161

6262
var question = escapeHtml('CREATE DATABASE ' + newDbName + ' / DROP DATABASE ' + oldDbName);
6363

64-
Functions.prepareForAjaxRequest($form);
64+
prepareForAjaxRequest($form);
6565

6666
$form.confirm(question, $form.attr('action'), function (url) {
6767
ajaxShowMessage(window.Messages.strRenamingDatabases, false);
@@ -94,15 +94,15 @@ AJAX.registerOnload('database/operations.js', function () {
9494
$(document).on('submit', '#copy_db_form.ajax', function (event) {
9595
event.preventDefault();
9696

97-
if (Functions.emptyCheckTheField(this, 'newname')) {
97+
if (emptyCheckTheField(this, 'newname')) {
9898
ajaxShowMessage(window.Messages.strFormEmpty, false, 'error');
9999

100100
return false;
101101
}
102102

103103
ajaxShowMessage(window.Messages.strCopyingDatabase, false);
104104
var $form = $(this);
105-
Functions.prepareForAjaxRequest($form);
105+
prepareForAjaxRequest($form);
106106
$.post($form.attr('action'), $form.serialize(), function (data) {
107107
// use messages that stay on screen
108108
$('.alert-success, .alert-danger').fadeOut();
@@ -139,7 +139,7 @@ AJAX.registerOnload('database/operations.js', function () {
139139
$(document).on('submit', '#change_db_charset_form.ajax', function (event) {
140140
event.preventDefault();
141141
var $form = $(this);
142-
Functions.prepareForAjaxRequest($form);
142+
prepareForAjaxRequest($form);
143143
ajaxShowMessage(window.Messages.strChangingCharset);
144144
$.post($form.attr('action'), $form.serialize(), function (data) {
145145
if (typeof data !== 'undefined' && data.success === true) {

resources/js/src/database/routines.ts

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import $ from 'jquery';
22
import { AJAX } from '../modules/ajax.ts';
3-
import { Functions } from '../modules/functions.ts';
3+
import { addDatepicker, getSqlEditor, slidingMessage } from '../modules/functions.ts';
44
import { Navigation } from '../modules/navigation.ts';
55
import { ajaxRemoveMessage, ajaxShowMessage } from '../modules/ajax-message.ts';
66
import getJsConfirmCommonParam from '../modules/functions/getJsConfirmCommonParam.ts';
@@ -160,7 +160,7 @@ const DatabaseRoutines = {
160160
* to the Export textarea.
161161
*/
162162
var $elm = $ajaxDialog.find('textarea');
163-
Functions.getSqlEditor($elm);
163+
getSqlEditor($elm);
164164
} // end showExport()
165165
}, // end exportDialog()
166166
editorDialog: function (isNew, $this) {
@@ -235,7 +235,7 @@ const DatabaseRoutines = {
235235

236236
// Item created successfully
237237
ajaxRemoveMessage($msg);
238-
Functions.slidingMessage(data.message);
238+
slidingMessage(data.message);
239239
that.$ajaxDialog.dialog('close');
240240

241241
var tableId = '#' + data.tableType + 'Table';
@@ -366,11 +366,11 @@ const DatabaseRoutines = {
366366

367367
$(this).find('input[name=item_name]').trigger('focus');
368368
$(this).find('input.datefield').each(function () {
369-
Functions.addDatepicker($(this).css('width', '95%'), 'date');
369+
addDatepicker($(this).css('width', '95%'), 'date');
370370
});
371371

372372
$(this).find('input.datetimefield').each(function () {
373-
Functions.addDatepicker($(this).css('width', '95%'), 'datetime');
373+
addDatepicker($(this).css('width', '95%'), 'datetime');
374374
});
375375

376376
// @ts-ignore
@@ -399,7 +399,7 @@ const DatabaseRoutines = {
399399
var linterOptions = {
400400
editorType: 'routine',
401401
};
402-
that.syntaxHiglighter = Functions.getSqlEditor($elm, {}, 'vertical', linterOptions);
402+
that.syntaxHiglighter = getSqlEditor($elm, {}, 'vertical', linterOptions);
403403
window.codeMirrorEditor = that.syntaxHiglighter;
404404
// Execute item-specific code
405405
that.postDialogShow(data);
@@ -475,7 +475,7 @@ const DatabaseRoutines = {
475475
// Get rid of the "Loading" message
476476
ajaxRemoveMessage($msg);
477477
// Show the query that we just executed
478-
Functions.slidingMessage(data.sql_query);
478+
slidingMessage(data.sql_query);
479479
Navigation.reload();
480480
}); // end $.post()
481481
});
@@ -847,7 +847,7 @@ const DatabaseRoutines = {
847847
// we just show the results of the query
848848
if (! data.dialog) {
849849
// Routine executed successfully
850-
Functions.slidingMessage(data.message);
850+
slidingMessage(data.message);
851851

852852
return;
853853
}
@@ -878,7 +878,7 @@ const DatabaseRoutines = {
878878
if (data.success === true) {
879879
// Routine executed successfully
880880
ajaxRemoveMessage($msg);
881-
Functions.slidingMessage(data.message);
881+
slidingMessage(data.message);
882882
$ajaxDialog.dialog('close');
883883
} else {
884884
ajaxShowMessage(data.error, false);
@@ -912,7 +912,7 @@ const DatabaseRoutines = {
912912
* Attach the datepickers to the relevant form fields
913913
*/
914914
$ajaxDialog.find('input.datefield, input.datetimefield').each(function () {
915-
Functions.addDatepicker($(this).css('width', '95%'));
915+
addDatepicker($(this).css('width', '95%'));
916916
});
917917

918918
/*
@@ -942,7 +942,7 @@ const DatabaseRoutines = {
942942

943943
// Routine executed successfully
944944
ajaxRemoveMessage($msg);
945-
Functions.slidingMessage(data.message);
945+
slidingMessage(data.message);
946946
$('form.rte_form').off('keyup');
947947
$ajaxDialog.remove();
948948
});

resources/js/src/database/search.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import $ from 'jquery';
22
import { AJAX } from '../modules/ajax.ts';
3-
import { Functions } from '../modules/functions.ts';
3+
import { prepareForAjaxRequest, setSelectOptions } from '../modules/functions.ts';
44
import { CommonParams } from '../modules/common.ts';
55
import highlightSql from '../modules/sql-highlight.ts';
66
import { ajaxRemoveMessage, ajaxShowMessage } from '../modules/ajax-message.ts';
@@ -226,7 +226,7 @@ AJAX.registerOnload('database/search.js', function () {
226226
// jQuery object to reuse
227227
var $form = $(this);
228228

229-
Functions.prepareForAjaxRequest($form);
229+
prepareForAjaxRequest($form);
230230

231231
var url = $form.serialize() + CommonParams.get('arg_separator') + 'submit_search=' + $('#buttonGo').val();
232232
$.post($form.attr('action'), url, function (data) {
@@ -267,13 +267,13 @@ AJAX.registerOnload('database/search.js', function () {
267267
});
268268

269269
$('#select_all').on('click', function () {
270-
Functions.setSelectOptions('db_search', 'criteriaTables[]', true);
270+
setSelectOptions('db_search', 'criteriaTables[]', true);
271271

272272
return false;
273273
});
274274

275275
$('#unselect_all').on('click', function () {
276-
Functions.setSelectOptions('db_search', 'criteriaTables[]', false);
276+
setSelectOptions('db_search', 'criteriaTables[]', false);
277277

278278
return false;
279279
});

resources/js/src/database/structure.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import $ from 'jquery';
22
import { AJAX } from '../modules/ajax.ts';
3-
import { Functions } from '../modules/functions.ts';
3+
import { getForeignKeyCheckboxLoader, loadForeignKeyCheckbox } from '../modules/functions.ts';
44
import { Navigation } from '../modules/navigation.ts';
55
import { CommonParams } from '../modules/common.ts';
66
import tooltip from '../modules/tooltip.ts';
@@ -342,7 +342,7 @@ AJAX.registerOnload('database/structure.js', function () {
342342
*/
343343
var question = window.Messages.strTruncateTableStrongWarning + ' ' +
344344
window.sprintf(window.Messages.strDoYouReally, 'TRUNCATE `' + escapeHtml(currTableName) + '`') +
345-
Functions.getForeignKeyCheckboxLoader();
345+
getForeignKeyCheckboxLoader();
346346

347347
$thisAnchor.confirm(question, $thisAnchor.attr('href'), function (url) {
348348
ajaxShowMessage(window.Messages.strProcessingRequest);
@@ -361,7 +361,7 @@ AJAX.registerOnload('database/structure.js', function () {
361361
ajaxShowMessage(window.Messages.strErrorProcessingRequest + ' : ' + data.error, false);
362362
}
363363
}); // end $.post()
364-
}, Functions.loadForeignKeyCheckbox);
364+
}, loadForeignKeyCheckbox);
365365
}); // end of Truncate Table Ajax action
366366

367367
/**
@@ -397,7 +397,7 @@ AJAX.registerOnload('database/structure.js', function () {
397397
window.sprintf(window.Messages.strDoYouReally, 'DROP VIEW `' + escapeHtml(currTableName) + '`');
398398
}
399399

400-
question += Functions.getForeignKeyCheckboxLoader();
400+
question += getForeignKeyCheckboxLoader();
401401

402402
$thisAnchor.confirm(question, $thisAnchor.attr('href'), function (url) {
403403
var $msg = ajaxShowMessage(window.Messages.strProcessingRequest);
@@ -415,7 +415,7 @@ AJAX.registerOnload('database/structure.js', function () {
415415
ajaxShowMessage(window.Messages.strErrorProcessingRequest + ' : ' + data.error, false);
416416
}
417417
}); // end $.post()
418-
}, Functions.loadForeignKeyCheckbox);
418+
}, loadForeignKeyCheckbox);
419419
}); // end of Drop Table Ajax action
420420

421421
// Add tooltip to favorite icons.

resources/js/src/designer/history.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import $ from 'jquery';
2-
import { Functions } from '../modules/functions.ts';
2+
import { getSqlEditor } from '../modules/functions.ts';
33
import getImageTag from '../modules/functions/getImageTag.ts';
44
import { DesignerConfig } from './config.ts';
55

@@ -856,7 +856,7 @@ const buildQuery = function () {
856856
*/
857857
var $elm = $('#buildQueryModal').find('textarea');
858858
if (! DesignerHistory.vqbEditor) {
859-
DesignerHistory.vqbEditor = Functions.getSqlEditor($elm);
859+
DesignerHistory.vqbEditor = getSqlEditor($elm);
860860
}
861861

862862
if (DesignerHistory.vqbEditor) {

resources/js/src/designer/move.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import $ from 'jquery';
2-
import { Functions } from '../modules/functions.ts';
2+
import { prepareForAjaxRequest } from '../modules/functions.ts';
33
import { CommonParams } from '../modules/common.ts';
44
import { ajaxRemoveMessage, ajaxShowMessage } from '../modules/ajax-message.ts';
55
import refreshMainContent from '../modules/functions/refreshMainContent.ts';
@@ -800,7 +800,7 @@ const submitSaveDialogAndClose = function (callback, modal) {
800800

801801
if (DesignerConfig.designerTablesEnabled) {
802802
var $msgbox = ajaxShowMessage(window.Messages.strProcessingRequest);
803-
Functions.prepareForAjaxRequest($form);
803+
prepareForAjaxRequest($form);
804804
$.post($form.attr('action'), $form.serialize() + DesignerMove.getUrlPos(), function (data) {
805805
if (data.success === false) {
806806
ajaxShowMessage(data.error, false);
@@ -931,7 +931,7 @@ const deletePages = function () {
931931

932932
var $messageBox = ajaxShowMessage(window.Messages.strProcessingRequest);
933933
var deletingCurrentPage = parseInt(selected) === DesignerConfig.selectedPage;
934-
Functions.prepareForAjaxRequest($form);
934+
prepareForAjaxRequest($form);
935935

936936
if (DesignerConfig.designerTablesEnabled) {
937937
$.post($form.attr('action'), $form.serialize(), function (data) {
@@ -1016,7 +1016,7 @@ const saveAs = function () {
10161016

10171017
var $msgbox = ajaxShowMessage(window.Messages.strProcessingRequest);
10181018
if (DesignerConfig.designerTablesEnabled) {
1019-
Functions.prepareForAjaxRequest($form);
1019+
prepareForAjaxRequest($form);
10201020
$.post($form.attr('action'), $form.serialize() + DesignerMove.getUrlPos(), function (data) {
10211021
if (data.success === false) {
10221022
ajaxShowMessage(data.error, false);

resources/js/src/export.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import $ from 'jquery';
22
import { AJAX } from './modules/ajax.ts';
3-
import { Functions } from './modules/functions.ts';
3+
import { setSelectOptions } from './modules/functions.ts';
44
import { CommonParams } from './modules/common.ts';
55
import highlightSql from './modules/sql-highlight.ts';
66
import { ajaxShowMessage } from './modules/ajax-message.ts';
@@ -1072,18 +1072,18 @@ AJAX.registerOnload('export.js', function () {
10721072
$('#column_alias_name').val('');
10731073
});
10741074

1075-
var setSelectOptions = function (doCheck) {
1076-
Functions.setSelectOptions('dump', 'db_select[]', doCheck);
1075+
var setDbSelectOptions = function (doCheck) {
1076+
setSelectOptions('dump', 'db_select[]', doCheck);
10771077
};
10781078

10791079
$('#db_select_all').on('click', function (e) {
10801080
e.preventDefault();
1081-
setSelectOptions(true);
1081+
setDbSelectOptions(true);
10821082
});
10831083

10841084
$('#db_unselect_all').on('click', function (e) {
10851085
e.preventDefault();
1086-
setSelectOptions(false);
1086+
setDbSelectOptions(false);
10871087
});
10881088

10891089
$('#buttonGo').on('click', function () {

0 commit comments

Comments
 (0)