Skip to content

Commit 91167fb

Browse files
committed
Create the DesignerConfig JS object
This removes the properties from the Window object. Signed-off-by: Maurício Meneghini Fauth <mauricio@fauth.dev>
1 parent 4be069c commit 91167fb

6 files changed

Lines changed: 164 additions & 134 deletions

File tree

‎js/src/designer/config.js‎

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
export const DesignerConfig = {
2+
/** @type {any[]} */
3+
jTabs: [],
4+
5+
/** @type {any[]} */
6+
hTabs: [],
7+
8+
/** @type {any[]} */
9+
contr: [],
10+
11+
/** @type {any[]} */
12+
displayField: [],
13+
14+
/** @type {number} */
15+
server: 0,
16+
17+
/** @type {number} */
18+
selectedPage: -1,
19+
20+
/** @type {string} */
21+
db: '',
22+
23+
/** @type {boolean} */
24+
designerTablesEnabled: false,
25+
};

‎js/src/designer/history.js‎

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import $ from 'jquery';
22
import { Functions } from '../modules/functions.js';
33
import getImageTag from '../modules/functions/getImageTag.js';
4+
import { DesignerConfig } from './config.js';
45

56
/**
67
* @fileoverview function used in this file builds history tab and generates query.
@@ -667,21 +668,21 @@ DesignerHistory.queryFrom = function () {
667668
// if master table (key2) matches with tab used get all keys and check if tab_left matches
668669
// after this check if master table (key2) matches with tab left then check if any foreign matches with master .
669670
for (i = 0; i < 2; i++) {
670-
for (K in window.contr) {
671-
for (key in window.contr[K]) {// contr name
672-
for (key2 in window.contr[K][key]) {// table name
671+
for (K in DesignerConfig.contr) {
672+
for (key in DesignerConfig.contr[K]) {// contr name
673+
for (key2 in DesignerConfig.contr[K][key]) {// table name
673674
parts = key2.split('.');
674675
if (DesignerHistory.found(tabUsed, parts[1]) > 0) {
675-
for (key3 in window.contr[K][key][key2]) {
676-
parts1 = window.contr[K][key][key2][key3][0].split('.');
676+
for (key3 in DesignerConfig.contr[K][key][key2]) {
677+
parts1 = DesignerConfig.contr[K][key][key2][key3][0].split('.');
677678
if (DesignerHistory.found(tabLeft, parts1[1]) > 0) {
678679
if (DesignerHistory.found(constraintsAdded, key) > 0) {
679680
query += ' AND ' + '`' + parts[1] + '`.`' + key3 + '` = ';
680-
query += '`' + parts1[1] + '`.`' + window.contr[K][key][key2][key3][1] + '` ';
681+
query += '`' + parts1[1] + '`.`' + DesignerConfig.contr[K][key][key2][key3][1] + '` ';
681682
} else {
682683
query += '\n' + 'LEFT JOIN ';
683684
query += '`' + parts[1] + '` ON ';
684-
query += '`' + parts1[1] + '`.`' + window.contr[K][key][key2][key3][1] + '` = ';
685+
query += '`' + parts1[1] + '`.`' + DesignerConfig.contr[K][key][key2][key3][1] + '` = ';
685686
query += '`' + parts[1] + '`.`' + key3 + '` ';
686687

687688
constraintsAdded.push(key);
@@ -698,21 +699,21 @@ DesignerHistory.queryFrom = function () {
698699
tabUsed = DesignerHistory.addArray(tTabLeft, tabUsed);
699700
tabLeft = DesignerHistory.removeArray(tTabLeft, tabLeft);
700701
tTabLeft = [];
701-
for (K in window.contr) {
702-
for (key in window.contr[K]) {
703-
for (key2 in window.contr[K][key]) {// table name
702+
for (K in DesignerConfig.contr) {
703+
for (key in DesignerConfig.contr[K]) {
704+
for (key2 in DesignerConfig.contr[K][key]) {// table name
704705
parts = key2.split('.');
705706
if (DesignerHistory.found(tabLeft, parts[1]) > 0) {
706-
for (key3 in window.contr[K][key][key2]) {
707-
parts1 = window.contr[K][key][key2][key3][0].split('.');
707+
for (key3 in DesignerConfig.contr[K][key][key2]) {
708+
parts1 = DesignerConfig.contr[K][key][key2][key3][0].split('.');
708709
if (DesignerHistory.found(tabUsed, parts1[1]) > 0) {
709710
if (DesignerHistory.found(constraintsAdded, key) > 0) {
710711
query += ' AND ' + '`' + parts[1] + '`.`' + key3 + '` = ';
711-
query += '`' + parts1[1] + '`.`' + window.contr[K][key][key2][key3][1] + '` ';
712+
query += '`' + parts1[1] + '`.`' + DesignerConfig.contr[K][key][key2][key3][1] + '` ';
712713
} else {
713714
query += '\n' + 'LEFT JOIN ';
714715
query += '`' + parts[1] + '` ON ';
715-
query += '`' + parts1[1] + '`.`' + window.contr[K][key][key2][key3][1] + '` = ';
716+
query += '`' + parts1[1] + '`.`' + DesignerConfig.contr[K][key][key2][key3][1] + '` = ';
716717
query += '`' + parts[1] + '`.`' + key3 + '` ';
717718

718719
constraintsAdded.push(key);

‎js/src/designer/init.js‎

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,12 @@ import { DesignerOfflineDB } from './database.js';
44
import { DesignerHistory } from './history.js';
55
import { DesignerMove } from './move.js';
66
import { DesignerPage } from './page.js';
7+
import { DesignerConfig } from './config.js';
78

89
/**
910
* Initializes the data required to run Designer, then fires it up.
1011
*/
1112

12-
/* global designerConfig */ // templates/database/designer/main.twig
13-
1413
AJAX.registerTeardown('designer/init.js', function () {
1514
DesignerHistory.vqbEditor = null;
1615
DesignerHistory.historyArray = [];
@@ -169,7 +168,7 @@ AJAX.registerOnload('designer/init.js', function () {
169168
return false;
170169
});
171170
$('#reloadPage').on('click', function () {
172-
DesignerMove.loadPage(window.selectedPage);
171+
DesignerMove.loadPage(DesignerConfig.selectedPage);
173172
});
174173
$('#angular_direct_button').on('click', function () {
175174
DesignerMove.angularDirect();
@@ -268,21 +267,24 @@ AJAX.registerOnload('designer/init.js', function () {
268267
return false;
269268
});
270269

271-
window.jTabs = designerConfig.scriptTables.j_tabs;
272-
window.hTabs = designerConfig.scriptTables.h_tabs;
273-
window.contr = designerConfig.scriptContr;
274-
window.displayField = designerConfig.scriptDisplayField;
275-
window.server = designerConfig.server;
276-
window.selectedPage = designerConfig.displayPage;
277-
window.db = designerConfig.db;
278-
window.designerTablesEnabled = designerConfig.tablesEnabled;
270+
// @ts-ignore
271+
const configValues = window.designerConfig;
272+
273+
DesignerConfig.jTabs = configValues.scriptTables.j_tabs;
274+
DesignerConfig.hTabs = configValues.scriptTables.h_tabs;
275+
DesignerConfig.contr = configValues.scriptContr;
276+
DesignerConfig.displayField = configValues.scriptDisplayField;
277+
DesignerConfig.server = configValues.server;
278+
DesignerConfig.selectedPage = configValues.displayPage;
279+
DesignerConfig.db = configValues.db;
280+
DesignerConfig.designerTablesEnabled = configValues.tablesEnabled;
279281

280282
DesignerMove.main();
281283

282-
if (! window.designerTablesEnabled) {
284+
if (! DesignerConfig.designerTablesEnabled) {
283285
DesignerOfflineDB.open(function (success) {
284286
if (success) {
285-
DesignerPage.showTablesInLandingPage(window.db);
287+
DesignerPage.showTablesInLandingPage(DesignerConfig.db);
286288
}
287289
});
288290
}

0 commit comments

Comments
 (0)