/usr/share/phpmyadmin/js/dist
Edit: /usr/share/phpmyadmin/js/dist/normalization.js (24237B)
"use strict";
/**
* @fileoverview events handling from normalization page
* @name normalization
*
* @requires jQuery
*/
// eslint-disable-next-line no-unused-vars
/* global centralColumnList:writable */
// js/functions.js
/**
* AJAX scripts for normalization
*
*/
var normalizeto = '1nf';
var primaryKey;
var dataParsed = null;
function appendHtmlColumnsList() {
$.post('index.php?route=/normalization', {
'ajax_request': true,
'db': CommonParams.get('db'),
'table': CommonParams.get('table'),
'server': CommonParams.get('server'),
'getColumns': true
}, function (data) {
if (data.success === true) {
$('select[name=makeAtomic]').html(data.message);
}
});
}
function goTo3NFStep1(newTables) {
var tables = newTables;
if (Object.keys(tables).length === 1) {
tables = [CommonParams.get('table')];
}
$.post('index.php?route=/normalization', {
'ajax_request': true,
'db': CommonParams.get('db'),
'server': CommonParams.get('server'),
'tables': tables,
'step': '3.1'
}, function (data) {
$('#page_content').find('h3').html(Messages.str3NFNormalization);
$('#mainContent').find('legend').html(data.legendText);
$('#mainContent').find('h4').html(data.headText);
$('#mainContent').find('p').html(data.subText);
$('#mainContent').find('#extra').html(data.extra);
$('#extra').find('form').each(function () {
var formId = $(this).attr('id');
var colName = $(this).data('colname');
$('#' + formId + ' input[value=\'' + colName + '\']').next().remove();
$('#' + formId + ' input[value=\'' + colName + '\']').remove();
});
$('#mainContent').find('#newCols').html('');
$('.tblFooters').html('');
if (data.subText !== '') {
$('
').attr({
type: 'button',
value: Messages.strDone,
class: 'btn btn-primary'
}).on('click', function () {
processDependencies('', true);
}).appendTo('.tblFooters');
}
});
}
function goTo2NFStep1() {
$.post('index.php?route=/normalization', {
'ajax_request': true,
'db': CommonParams.get('db'),
'table': CommonParams.get('table'),
'server': CommonParams.get('server'),
'step': '2.1'
}, function (data) {
$('#page_content h3').html(Messages.str2NFNormalization);
$('#mainContent legend').html(data.legendText);
$('#mainContent h4').html(data.headText);
$('#mainContent p').html(data.subText);
$('#mainContent #extra').html(data.extra);
$('#mainContent #newCols').html('');
if (data.subText !== '') {
$('
').attr({
type: 'submit',
value: Messages.strDone,
class: 'btn btn-primary'
}).on('click', function () {
processDependencies(data.primary_key);
}).appendTo('.tblFooters');
} else {
if (normalizeto === '3nf') {
$('#mainContent #newCols').html(Messages.strToNextStep);
setTimeout(function () {
goTo3NFStep1([CommonParams.get('table')]);
}, 3000);
}
}
});
}
function goToFinish1NF() {
if (normalizeto !== '1nf') {
goTo2NFStep1();
return true;
}
$('#mainContent legend').html(Messages.strEndStep);
$('#mainContent h4').html('
' + Functions.sprintf(Messages.strFinishMsg, Functions.escapeHtml(CommonParams.get('table'))) + ' ');
$('#mainContent p').html('');
$('#mainContent #extra').html('');
$('#mainContent #newCols').html('');
$('.tblFooters').html('');
} // eslint-disable-next-line no-unused-vars
function goToStep4() {
$.post('index.php?route=/normalization', {
'ajax_request': true,
'db': CommonParams.get('db'),
'table': CommonParams.get('table'),
'server': CommonParams.get('server'),
'step4': true
}, function (data) {
$('#mainContent legend').html(data.legendText);
$('#mainContent h4').html(data.headText);
$('#mainContent p').html(data.subText);
$('#mainContent #extra').html(data.extra);
$('#mainContent #newCols').html('');
$('.tblFooters').html('');
for (var pk in primaryKey) {
$('#extra input[value=\'' + Functions.escapeJsString(primaryKey[pk]) + '\']').attr('disabled', 'disabled');
}
});
}
function goToStep3() {
$.post('index.php?route=/normalization', {
'ajax_request': true,
'db': CommonParams.get('db'),
'table': CommonParams.get('table'),
'server': CommonParams.get('server'),
'step3': true
}, function (data) {
$('#mainContent legend').html(data.legendText);
$('#mainContent h4').html(data.headText);
$('#mainContent p').html(data.subText);
$('#mainContent #extra').html(data.extra);
$('#mainContent #newCols').html('');
$('.tblFooters').html('');
primaryKey = JSON.parse(data.primary_key);
for (var pk in primaryKey) {
$('#extra input[value=\'' + Functions.escapeJsString(primaryKey[pk]) + '\']').attr('disabled', 'disabled');
}
});
}
function goToStep2(extra) {
$.post('index.php?route=/normalization', {
'ajax_request': true,
'db': CommonParams.get('db'),
'table': CommonParams.get('table'),
'server': CommonParams.get('server'),
'step2': true
}, function (data) {
$('#mainContent legend').html(data.legendText);
$('#mainContent h4').html(data.headText);
$('#mainContent p').html(data.subText);
$('#mainContent #extra,#mainContent #newCols').html('');
$('.tblFooters').html('');
if (data.hasPrimaryKey === '1') {
if (extra === 'goToStep3') {
$('#mainContent h4').html(Messages.strPrimaryKeyAdded);
$('#mainContent p').html(Messages.strToNextStep);
}
if (extra === 'goToFinish1NF') {
goToFinish1NF();
} else {
setTimeout(function () {
goToStep3();
}, 3000);
}
} else {
// form to select columns to make primary
$('#mainContent #extra').html(data.extra);
}
});
}
function goTo2NFFinish(pd) {
var tables = {};
for (var dependson in pd) {
tables[dependson] = $('#extra input[name="' + dependson + '"]').val();
}
var datastring = {
'ajax_request': true,
'db': CommonParams.get('db'),
'table': CommonParams.get('table'),
'server': CommonParams.get('server'),
'pd': JSON.stringify(pd),
'newTablesName': JSON.stringify(tables),
'createNewTables2NF': 1
};
$.ajax({
type: 'POST',
url: 'index.php?route=/normalization',
data: datastring,
async: false,
success: function success(data) {
if (data.success === true) {
if (data.queryError === false) {
if (normalizeto === '3nf') {
$('#pma_navigation_reload').trigger('click');
goTo3NFStep1(tables);
return true;
}
$('#mainContent legend').html(data.legendText);
$('#mainContent h4').html(data.headText);
$('#mainContent p').html('');
$('#mainContent #extra').html('');
$('.tblFooters').html('');
} else {
Functions.ajaxShowMessage(data.extra, false);
}
$('#pma_navigation_reload').trigger('click');
} else {
Functions.ajaxShowMessage(data.error, false);
}
}
});
}
function goTo3NFFinish(newTables) {
for (var table in newTables) {
for (var newtbl in newTables[table]) {
var updatedname = $('#extra input[name="' + newtbl + '"]').val();
newTables[table][updatedname] = newTables[table][newtbl];
if (updatedname !== newtbl) {
delete newTables[table][newtbl];
}
}
}
var datastring = {
'ajax_request': true,
'db': CommonParams.get('db'),
'server': CommonParams.get('server'),
'newTables': JSON.stringify(newTables),
'createNewTables3NF': 1
};
$.ajax({
type: 'POST',
url: 'index.php?route=/normalization',
data: datastring,
async: false,
success: function success(data) {
if (data.success === true) {
if (data.queryError === false) {
$('#mainContent legend').html(data.legendText);
$('#mainContent h4').html(data.headText);
$('#mainContent p').html('');
$('#mainContent #extra').html('');
$('.tblFooters').html('');
} else {
Functions.ajaxShowMessage(data.extra, false);
}
$('#pma_navigation_reload').trigger('click');
} else {
Functions.ajaxShowMessage(data.error, false);
}
}
});
}
var backup = '';
function goTo2NFStep2(pd, primaryKey) {
$('#newCols').html('');
$('#mainContent legend').html(Messages.strStep + ' 2.2 ' + Messages.strConfirmPd);
$('#mainContent h4').html(Messages.strSelectedPd);
$('#mainContent p').html(Messages.strPdHintNote);
var extra = '
';
var pdFound = false;
for (var dependson in pd) {
if (dependson !== primaryKey) {
pdFound = true;
extra += '
' + Functions.escapeHtml(dependson) + ' -> ' + Functions.escapeHtml(pd[dependson].toString()) + '
';
}
}
if (!pdFound) {
extra += '
' + Messages.strNoPdSelected + '
';
extra += '
';
} else {
extra += '
';
var datastring = {
'ajax_request': true,
'db': CommonParams.get('db'),
'table': CommonParams.get('table'),
'server': CommonParams.get('server'),
'pd': JSON.stringify(pd),
'getNewTables2NF': 1
};
$.ajax({
type: 'POST',
url: 'index.php?route=/normalization',
data: datastring,
async: false,
success: function success(data) {
if (data.success === true) {
extra += data.message;
} else {
Functions.ajaxShowMessage(data.error, false);
}
}
});
}
$('#mainContent #extra').html(extra);
$('.tblFooters').html('