Skip to content

Commit

Permalink
Resolve merge conflicts and some code cleanup for functions.js
Browse files Browse the repository at this point in the history
Signed-Off-By: Piyush Vijay <piyushvijay.1997@gmail.com>
  • Loading branch information
Piyush3079 committed Aug 17, 2018
1 parent bfc9d62 commit c0856b2
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 192 deletions.
190 changes: 0 additions & 190 deletions js/functions.js
Expand Up @@ -2693,196 +2693,6 @@ AJAX.registerTeardown('functions.js', function () {
$(document).off('change', 'input[name=partition_count],input[name=subpartition_count],select[name=partition_by]');
});

/**
* jQuery coding for 'Create Table'. Used on db_operations.php,
* db_structure.php and db_tracking.php (i.e., wherever
* PhpMyAdmin\Display\CreateTable is used)
*
* Attach Ajax Event handlers for Create Table
*/
AJAX.registerOnload('functions.js', function () {
/**
* Attach event handler for submission of create table form (save)
*/
$(document).on('submit', 'form.create_table_form.ajax', function (event) {
event.preventDefault();

/**
* @var the_form object referring to the create table form
*/
var $form = $(this);

/*
* First validate the form; if there is a problem, avoid submitting it
*
* checkTableEditForm() needs a pure element and not a jQuery object,
* this is why we pass $form[0] as a parameter (the jQuery object
* is actually an array of DOM elements)
*/

if (checkTableEditForm($form[0], $form.find('input[name=orig_num_fields]').val())) {
PMA_prepareForAjaxRequest($form);
if (PMA_checkReservedWordColumns($form)) {
PMA_ajaxShowMessage(PMA_messages.strProcessingRequest);
// User wants to submit the form
$.post($form.attr('action'), $form.serialize() + PMA_commonParams.get('arg_separator') + 'do_save_data=1', function (data) {
if (typeof data !== 'undefined' && data.success === true) {
$('#properties_message')
.removeClass('error')
.html('');
PMA_ajaxShowMessage(data.message);
// Only if the create table dialog (distinct panel) exists
var $createTableDialog = $('#create_table_dialog');
if ($createTableDialog.length > 0) {
$createTableDialog.dialog('close').remove();
}
$('#tableslistcontainer').before(data.formatted_sql);

/**
* @var tables_table Object referring to the <tbody> element that holds the list of tables
*/
var tables_table = $('#tablesForm').find('tbody').not('#tbl_summary_row');
// this is the first table created in this db
if (tables_table.length === 0) {
PMA_commonActions.refreshMain(
PMA_commonParams.get('opendb_url')
);
} else {
/**
* @var curr_last_row Object referring to the last <tr> element in {@link tables_table}
*/
var curr_last_row = $(tables_table).find('tr:last');
/**
* @var curr_last_row_index_string String containing the index of {@link curr_last_row}
*/
var curr_last_row_index_string = $(curr_last_row).find('input:checkbox').attr('id').match(/\d+/)[0];
/**
* @var curr_last_row_index Index of {@link curr_last_row}
*/
var curr_last_row_index = parseFloat(curr_last_row_index_string);
/**
* @var new_last_row_index Index of the new row to be appended to {@link tables_table}
*/
var new_last_row_index = curr_last_row_index + 1;
/**
* @var new_last_row_id String containing the id of the row to be appended to {@link tables_table}
*/
var new_last_row_id = 'checkbox_tbl_' + new_last_row_index;

data.new_table_string = data.new_table_string.replace(/checkbox_tbl_/, new_last_row_id);
// append to table
$(data.new_table_string)
.appendTo(tables_table);

// Sort the table
$(tables_table).PMA_sort_table('th');

// Adjust summary row
PMA_adjustTotals();
}

// Refresh navigation as a new table has been added
PMA_reloadNavigation();
// Redirect to table structure page on creation of new table
var argsep = PMA_commonParams.get('arg_separator');
var params_12 = 'ajax_request=true' + argsep + 'ajax_page_request=true';
if (! (history && history.pushState)) {
params_12 += PMA_MicroHistory.menus.getRequestParam();
}
tblStruct_url = 'tbl_structure.php?server=' + data._params.server +
argsep + 'db=' + data._params.db + argsep + 'token=' + data._params.token +
argsep + 'goto=db_structure.php' + argsep + 'table=' + data._params.table + '';
$.get(tblStruct_url, params_12, AJAX.responseHandler);
} else {
PMA_ajaxShowMessage(
'<div class="error">' + data.error + '</div>',
false
);
}
}); // end $.post()
}
} // end if (checkTableEditForm() )
}); // end create table form (save)

/**
* Submits the intermediate changes in the table creation form
* to refresh the UI accordingly
*/
function submitChangesInCreateTableForm (actionParam) {
/**
* @var the_form object referring to the create table form
*/
var $form = $('form.create_table_form.ajax');

var $msgbox = PMA_ajaxShowMessage(PMA_messages.strProcessingRequest);
PMA_prepareForAjaxRequest($form);

// User wants to add more fields to the table
$.post($form.attr('action'), $form.serialize() + '&' + actionParam, function (data) {
if (typeof data !== 'undefined' && data.success) {
var $pageContent = $('#page_content');
$pageContent.html(data.message);
PMA_highlightSQL($pageContent);
PMA_verifyColumnsProperties();
PMA_hideShowConnection($('.create_table_form select[name=tbl_storage_engine]'));
PMA_ajaxRemoveMessage($msgbox);
} else {
PMA_ajaxShowMessage(data.error);
}
}); // end $.post()
}

/**
* Attach event handler for create table form (add fields)
*/
$(document).on('click', 'form.create_table_form.ajax input[name=submit_num_fields]', function (event) {
event.preventDefault();
submitChangesInCreateTableForm('submit_num_fields=1');
}); // end create table form (add fields)

$(document).on('keydown', 'form.create_table_form.ajax input[name=added_fields]', function (event) {
if (event.keyCode === 13) {
event.preventDefault();
event.stopImmediatePropagation();
$(this)
.closest('form')
.find('input[name=submit_num_fields]')
.trigger('click');
}
});

/**
* Attach event handler to manage changes in number of partitions and subpartitions
*/
$(document).on('change', 'input[name=partition_count],input[name=subpartition_count],select[name=partition_by]', function (event) {
$this = $(this);
$form = $this.parents('form');
if ($form.is('.create_table_form.ajax')) {
submitChangesInCreateTableForm('submit_partition_change=1');
} else {
$form.submit();
}
});

$(document).on('change', 'input[value=AUTO_INCREMENT]', function () {
if (this.checked) {
var col = /\d/.exec($(this).attr('name'));
col = col[0];
var $selectFieldKey = $('select[name="field_key[' + col + ']"]');
if ($selectFieldKey.val() === 'none_' + col) {
$selectFieldKey.val('primary_' + col).trigger('change');
}
}
});
$('body')
.off('click', 'input.preview_sql')
.on('click', 'input.preview_sql', function () {
var $form = $(this).closest('form');
PMA_previewSQL($form);
});
});


/**
* Validates the password field in a form
*
Expand Down
2 changes: 1 addition & 1 deletion js/src/db_central_columns.js
@@ -1,5 +1,5 @@
/* vim: set expandtab sw=4 ts=4 sts=4: */
import { $ } from './utils/extend_jquery';
import { $ } from './utils/JqueryExtended';
import './plugins/jquery/jquery.tablesorter';
import { PMA_Messages as PMA_messages } from './variables/export_variables';
import { PMA_ajaxShowMessage } from './utils/show_ajax_messages';
Expand Down
2 changes: 1 addition & 1 deletion js/src/db_tracking.js
@@ -1,4 +1,4 @@
import { $ } from './utils/extend_jquery';
import { $ } from './utils/JqueryExtended';
import './plugins/jquery/jquery.tablesorter';
import PMA_commonParams from './variables/common_params';
import { PMA_Messages as PMA_messages } from './variables/export_variables';
Expand Down

0 comments on commit c0856b2

Please sign in to comment.