Add CreateTable and TableColumns module for adding table in db_structure.php.

Signed-Off-By: Piyush Vijay <piyushvijay.1997@gmail.com>
This commit is contained in:
Piyush Vijay 2018-07-27 18:22:29 +05:30
parent eae0c753bb
commit 6e790e72e5
2 changed files with 174 additions and 0 deletions

View File

@ -0,0 +1,93 @@
import PMA_commonParams from '../../variables/common_params';
import { PMA_Messages as PMA_messages } from '../../variables/export_variables';
/**
* Check if a form's element is empty.
* An element containing only spaces is also considered empty
*
* @param object the form
* @param string the name of the form field to put the focus on
*
* @return boolean whether the form field is empty or not
*/
function emptyCheckTheField (theForm, theFieldName) {
var theField = theForm.elements[theFieldName];
var space_re = new RegExp('\\s+');
return theField.value.replace(space_re, '') === '';
} // end of the 'emptyCheckTheField()' function
export function checkTableEditForm (theForm, fieldsCnt) {
// TODO: avoid sending a message if user just wants to add a line
// on the form but has not completed at least one field name
var atLeastOneField = 0;
var i;
var elm;
var elm2;
var elm3;
var val;
var id;
for (i = 0; i < fieldsCnt; i++) {
id = '#field_' + i + '_2';
elm = $(id);
val = elm.val();
if (val === 'VARCHAR' || val === 'CHAR' || val === 'BIT' || val === 'VARBINARY' || val === 'BINARY') {
elm2 = $('#field_' + i + '_3');
val = parseInt(elm2.val(), 10);
elm3 = $('#field_' + i + '_1');
if (isNaN(val) && elm3.val() !== '') {
elm2.select();
alert(PMA_messages.strEnterValidLength);
elm2.focus();
return false;
}
}
if (atLeastOneField === 0) {
id = 'field_' + i + '_1';
if (!emptyCheckTheField(theForm, id)) {
atLeastOneField = 1;
}
}
}
if (atLeastOneField === 0) {
var theField = theForm.elements.field_0_1;
alert(PMA_messages.strFormEmpty);
theField.focus();
return false;
}
// at least this section is under jQuery
var $input = $('input.textfield[name=\'table\']');
if ($input.val() === '') {
alert(PMA_messages.strFormEmpty);
$input.focus();
return false;
}
return true;
} // enf of the 'checkTableEditForm()' function
/**
* check for reserved keyword column name
*
* @param jQuery Object $form Form
*
* @returns true|false
*/
export function PMA_checkReservedWordColumns ($form) {
var is_confirmed = true;
$.ajax({
type: 'POST',
url: 'tbl_structure.php',
data: $form.serialize() + PMA_commonParams.get('arg_separator') + 'reserved_word_check=1',
success: function (data) {
if (typeof data.success !== 'undefined' && data.success === true) {
is_confirmed = confirm(data.message);
}
},
async:false
});
return is_confirmed;
}

View File

@ -0,0 +1,81 @@
/**
* Hides/shows the "Open in ENUM/SET editor" message, depending on the data type of the column currently selected
*/
function PMA_showNoticeForEnum (selectElement) {
var enum_notice_id = selectElement.attr('id').split('_')[1];
enum_notice_id += '_' + (parseInt(selectElement.attr('id').split('_')[2], 10) + 1);
var selectedType = selectElement.val();
if (selectedType === 'ENUM' || selectedType === 'SET') {
$('p#enum_notice_' + enum_notice_id).show();
} else {
$('p#enum_notice_' + enum_notice_id).hide();
}
}
/**
* Hides/shows the default value input field, depending on the default type
* Ticks the NULL checkbox if NULL is chosen as default value.
*/
function PMA_hideShowDefaultValue ($default_type) {
if ($default_type.val() === 'USER_DEFINED') {
$default_type.siblings('.default_value').show().focus();
} else {
$default_type.siblings('.default_value').hide();
if ($default_type.val() === 'NULL') {
var $null_checkbox = $default_type.closest('tr').find('.allow_null');
$null_checkbox.prop('checked', true);
}
}
}
/**
* Hides/shows the input field for column expression based on whether
* VIRTUAL/PERSISTENT is selected
*
* @param $virtuality virtuality dropdown
*/
function PMA_hideShowExpression ($virtuality) {
if ($virtuality.val() === '') {
$virtuality.siblings('.expression').hide();
} else {
$virtuality.siblings('.expression').show();
}
}
/**
* Show notices for ENUM columns; add/hide the default value
*
*/
export function PMA_verifyColumnsProperties () {
$('select.column_type').each(function () {
PMA_showNoticeForEnum($(this));
});
$('select.default_type').each(function () {
PMA_hideShowDefaultValue($(this));
});
$('select.virtuality').each(function () {
PMA_hideShowExpression($(this));
});
}
/**
* If the chosen storage engine is FEDERATED show connection field. Hide otherwise
*
* @param $engine_selector storage engine selector
*/
export function PMA_hideShowConnection ($engine_selector) {
var $connection = $('.create_table_form input[name=connection]');
var index = $connection.parent('td').index() + 1;
var $labelTh = $connection.parents('tr').prev('tr').children('th:nth-child(' + index + ')');
if ($engine_selector.val() !== 'FEDERATED') {
$connection
.prop('disabled', true)
.parent('td').hide();
$labelTh.hide();
} else {
$connection
.prop('disabled', false)
.parent('td').show();
$labelTh.show();
}
}