Merge pull request #1531 from rakeshkaundilya/master
#1613 Central columns: action on multiple columns
This commit is contained in:
commit
0321f554eb
@ -66,10 +66,25 @@ $cfgCentralColumns = PMA_centralColumnsGetParams();
|
||||
$pmadb = $cfgCentralColumns['db'];
|
||||
$pmatable = $cfgCentralColumns['table'];
|
||||
$max_rows = $GLOBALS['cfg']['MaxRows'];
|
||||
|
||||
if (isset($_REQUEST['edit_central_columns_page'])) {
|
||||
$selected_fld = $_REQUEST['selected_fld'];
|
||||
$selected_db = $_REQUEST['db'];
|
||||
$edit_central_column_page = PMA_getHTMLforEditingPage($selected_fld, $selected_db);
|
||||
$response->addHTML($edit_central_column_page);
|
||||
exit;
|
||||
}
|
||||
if (isset($_POST['multi_edit_central_column_save'])) {
|
||||
$message = PMA_updateMultipleColumn();
|
||||
if (!is_bool($message)) {
|
||||
$response->isSuccess(false);
|
||||
$response->addJSON('message', $message);
|
||||
}
|
||||
}
|
||||
if (isset($_POST['delete_save'])) {
|
||||
$col_name = array();
|
||||
$col_name[] = $_REQUEST['col_name'];
|
||||
$tmp_msg = PMA_deleteColumnsFromList($col_name, false);
|
||||
parse_str($_POST['col_name'], $col_name);
|
||||
$tmp_msg = PMA_deleteColumnsFromList($col_name['selected_fld'], false);
|
||||
}
|
||||
if (isset($_REQUEST['total_rows']) && $_REQUEST['total_rows']) {
|
||||
$total_rows = $_REQUEST['total_rows'];
|
||||
@ -106,6 +121,7 @@ $deleteRowForm = '<form method="post" id="del_form" action="db_central_columns.p
|
||||
. '<input type="hidden" name="delete_save" value="delete"></form>';
|
||||
$response->addHTML($deleteRowForm);
|
||||
$table_struct = '<div id="tableslistcontainer">'
|
||||
. '<form name="tableslistcontainer">'
|
||||
. '<table id="table_columns" class="tablesorter" '
|
||||
. 'style="min-width:100%" class="data">';
|
||||
$response->addHTML($table_struct);
|
||||
@ -124,7 +140,10 @@ foreach ($result as $row) {
|
||||
$odd_row = !$odd_row;
|
||||
$row_num++;
|
||||
}
|
||||
$response->addHTML('</table></div>');
|
||||
$response->addHTML('</table>');
|
||||
$tablefooter = PMA_getCentralColumnsTableFooter($pmaThemeImage, $text_dir);
|
||||
$response->addHTML($tablefooter);
|
||||
$response->addHTML('</form></div>');
|
||||
$message = PMA_Message::success(
|
||||
sprintf(__('Showing rows %1$s - %2$s.'), ($pos + 1), ($pos + count($result)))
|
||||
);
|
||||
|
||||
@ -12,6 +12,7 @@
|
||||
* Actions ajaxified here:
|
||||
* Inline Edit and save of a result row
|
||||
* Delete a row
|
||||
* Multiple edit and delete option
|
||||
*
|
||||
*/
|
||||
|
||||
@ -27,11 +28,16 @@ AJAX.registerTeardown('db_central_columns.js', function () {
|
||||
$('#column-select').unbind('change');
|
||||
$("#add_col_div>a").unbind('click');
|
||||
$('#add_new').unbind('submit');
|
||||
$('#multi_edit_central_columns').unbind('submit');
|
||||
$("select.default_type").unbind('change');
|
||||
$("button[name='delete_central_columns']").unbind('click');
|
||||
$("button[name='edit_central_columns']").unbind('click');
|
||||
});
|
||||
|
||||
AJAX.registerOnload('db_central_columns.js', function () {
|
||||
$('#tableslistcontainer input,#tableslistcontainer select,.default_value,.open_enum_editor').hide();
|
||||
$('#tableslistcontainer input,#tableslistcontainer select,#tableslistcontainer .default_value,#tableslistcontainer .open_enum_editor').hide();
|
||||
$('#tableslistcontainer .checkall').show();
|
||||
$('#tableslistcontainer .checkall_box').show();
|
||||
if ($('#table_columns tbody tr').length > 0) {
|
||||
$("#table_columns").tablesorter({
|
||||
headers: {
|
||||
@ -41,6 +47,41 @@ AJAX.registerOnload('db_central_columns.js', function () {
|
||||
}
|
||||
});
|
||||
}
|
||||
$('#tableslistcontainer button[name="delete_central_columns"]').click(function(event){
|
||||
event.preventDefault();
|
||||
var multi_delete_columns = $('.checkall:checkbox:checked').serialize();
|
||||
if(multi_delete_columns === ''){
|
||||
PMA_ajaxShowMessage(PMA_messages.strRadioUnchecked);
|
||||
return false;
|
||||
}
|
||||
PMA_ajaxShowMessage();
|
||||
$("#del_col_name").val(multi_delete_columns);
|
||||
$("#del_form").submit();
|
||||
});
|
||||
$('#tableslistcontainer button[name="edit_central_columns"]').click(function(event){
|
||||
event.preventDefault();
|
||||
var editColumnList = $('.checkall:checkbox:checked').serialize();
|
||||
if(editColumnList === ''){
|
||||
PMA_ajaxShowMessage(PMA_messages.strRadioUnchecked);
|
||||
return false;
|
||||
}
|
||||
var editColumnData = editColumnList+ '&edit_central_columns_page=true&ajax_request=true&ajax_page_request=true&token='+PMA_commonParams.get('token')+'&db='+PMA_commonParams.get('db');
|
||||
PMA_ajaxShowMessage();
|
||||
$.get('db_central_columns.php', editColumnData, AJAX.responseHandler);
|
||||
});
|
||||
$('#multi_edit_central_columns').submit(function(event){
|
||||
event.preventDefault();
|
||||
event.stopPropagation();
|
||||
var multi_column_edit_data = $("#multi_edit_central_columns").serialize()+'&multi_edit_central_column_save=true&ajax_request=true&ajax_page_request=true&token='+PMA_commonParams.get('token')+'&db='+PMA_commonParams.get('db');
|
||||
PMA_ajaxShowMessage();
|
||||
$.post('db_central_columns.php', multi_column_edit_data, AJAX.responseHandler);
|
||||
});
|
||||
$('#multi_edit_central_columns #cancel_multi_edit').click(function(event){
|
||||
event.preventDefault();
|
||||
var cancel_edit = 'ajax_request=true&ajax_page_request=true&token='+PMA_commonParams.get('token')+'&db='+PMA_commonParams.get('db');
|
||||
PMA_ajaxShowMessage();
|
||||
$.get('db_central_columns.php', cancel_edit, AJAX.responseHandler);
|
||||
});
|
||||
$('#add_new td').each(function(){
|
||||
if ($(this).attr('name') !== 'undefined') {
|
||||
$(this).find('input,select:first').attr('name', $(this).attr('name'));
|
||||
@ -80,7 +121,7 @@ AJAX.registerOnload('db_central_columns.js', function () {
|
||||
var question = PMA_messages.strDeleteCentralColumnWarning;
|
||||
$td.PMA_confirm(question, null, function (url) {
|
||||
rownum = $td.data('rownum');
|
||||
$("#del_col_name").val($('#f_' + rownum + ' td[name=col_name] span').html());
|
||||
$("#del_col_name").val("selected_fld%5B%5D="+$('#checkbox_row_' + rownum ).val());
|
||||
$("#del_form").submit();
|
||||
});
|
||||
});
|
||||
@ -92,6 +133,7 @@ AJAX.registerOnload('db_central_columns.js', function () {
|
||||
$('#edit_' + rownum).show();
|
||||
$('#f_' + rownum + ' td span').show();
|
||||
$('#f_' + rownum + ' input, #f_' + rownum + ' select,#f_'+rownum+' .default_value, #f_' + rownum + ' .open_enum_editor').hide();
|
||||
$('#tableslistcontainer .checkall').show();
|
||||
});
|
||||
$('.edit_save_form').click(function(event) {
|
||||
//alert(1);
|
||||
@ -131,7 +173,7 @@ AJAX.registerOnload('db_central_columns.js', function () {
|
||||
$('#f_' + rownum + ' td[name=col_length] span').text($('#f_' + rownum + ' input[name=col_length]').val()).html();
|
||||
$('#f_' + rownum + ' td[name=collation] span').text($('#f_' + rownum + ' select[name=collation]').val()).html();
|
||||
$('#f_' + rownum + ' td[name=col_attribute] span').text($('#f_' + rownum + ' select[name=col_attribute]').val()).html();
|
||||
$('#f_' + rownum + ' td[name=col_isNull] span').text($('#f_' + rownum + ' input[name=col_isNull]').val()).html();
|
||||
$('#f_' + rownum + ' td[name=col_isNull] span').text($('#f_' + rownum +' input[name=col_isNull]').is(":checked")?"Yes":"No").html();
|
||||
$('#f_' + rownum + ' td[name=col_extra] span').text($('#f_' + rownum + ' select[name=col_extra]').val()).html();
|
||||
$('#f_' + rownum + ' td[name=col_default] span').text($('#f_' + rownum + ' :input[name=col_default]').val()).html();
|
||||
}
|
||||
@ -139,6 +181,7 @@ AJAX.registerOnload('db_central_columns.js', function () {
|
||||
$('#edit_' + rownum).show();
|
||||
$('#f_' + rownum + ' td span').show();
|
||||
$('#f_' + rownum + ' input, #f_' + rownum + ' select,#f_' + rownum + ' .default_value, #f_' + rownum + ' .open_enum_editor').hide();
|
||||
$('#tableslistcontainer .checkall').show();
|
||||
},
|
||||
error: function() {
|
||||
PMA_ajaxShowMessage(
|
||||
@ -186,7 +229,7 @@ AJAX.registerOnload('db_central_columns.js', function () {
|
||||
$('#add_new').submit(function(event){
|
||||
$('#add_new').toggle();
|
||||
});
|
||||
$("select.default_type").change(function () {
|
||||
$("#tableslistcontainer select.default_type").change(function () {
|
||||
if ($(this).val() === 'USER_DEFINED') {
|
||||
$(this).siblings('.default_value').attr('name','col_default');
|
||||
$(this).attr('name','col_default_sel');
|
||||
|
||||
@ -553,6 +553,43 @@ function PMA_updateOneColumn($db, $orig_col_name, $col_name, $col_type,
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Update Multiple column in central columns list if a chnage is requested
|
||||
*
|
||||
* @return true|PMA_Message
|
||||
*/
|
||||
function PMA_updateMultipleColumn()
|
||||
{
|
||||
$db = $_POST['db'];
|
||||
$col_name = $_POST['field_name'];
|
||||
$orig_col_name = $_POST['orig_col_name'];
|
||||
$col_default = $_POST['field_default_type'];
|
||||
$col_extra = $_POST['col_extra'];
|
||||
$col_length = $_POST['field_length'];
|
||||
$col_attribute = $_POST['field_attribute'];
|
||||
$col_type = $_POST['field_type'];
|
||||
$collation = $_POST['field_collation'];
|
||||
$col_isNull = array();
|
||||
$num_central_fields = count($orig_col_name);
|
||||
for ($i = 0; $i < $num_central_fields ; $i++) {
|
||||
$col_isNull[$i] = isset($_POST['field_null'][$i])?1:0;
|
||||
if ($col_default[$i] == 'NONE') {
|
||||
$col_default[$i] = "";
|
||||
} else if ($col_default[$i] == 'USER_DEFINED') {
|
||||
$col_default[$i] = $_POST['field_default_value'][$i];
|
||||
}
|
||||
$message = PMA_updateOneColumn(
|
||||
$db, $orig_col_name[$i], $col_name[$i], $col_type[$i],
|
||||
$col_attribute[$i],$col_length[$i], $col_isNull[$i], $collation[$i],
|
||||
$col_extra[$i], $col_default[$i]
|
||||
);
|
||||
if (!is_bool($message)) {
|
||||
return $message;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* get the html for table navigation in Central columns page
|
||||
*
|
||||
@ -645,6 +682,7 @@ function PMA_getCentralColumnsTableHeader($class='', $title='', $actionCount=0)
|
||||
}
|
||||
$tableheader = '<thead>';
|
||||
$tableheader .= '<tr>'
|
||||
. '<th class="' . $class . '"></th>'
|
||||
. $action
|
||||
. '<th class="" style="display:none"></th>'
|
||||
. '<th class="' . $class . '" title="' . $title . '" data-column="name">'
|
||||
@ -668,6 +706,26 @@ function PMA_getCentralColumnsTableHeader($class='', $title='', $actionCount=0)
|
||||
return $tableheader;
|
||||
}
|
||||
|
||||
/**
|
||||
* Function generate and return the table header for
|
||||
* multiple edit central columns page
|
||||
*
|
||||
* @param array $header_cells headers list
|
||||
*
|
||||
* @return string html for table header in central columns multi edit page
|
||||
*/
|
||||
function PMA_getCentralColumnsEditTableHeader($header_cells)
|
||||
{
|
||||
$html = '<table id="table_columns" class="noclick">';
|
||||
$html .= '<caption class="tblHeaders">' . __('Structure');
|
||||
$html .= '<tr>';
|
||||
foreach ($header_cells as $header_val) {
|
||||
$html .= '<th>' . $header_val . '</th>';
|
||||
}
|
||||
$html .= '</tr>';
|
||||
return $html;
|
||||
}
|
||||
|
||||
/**
|
||||
* build the dropdown select html for tables of given database
|
||||
*
|
||||
@ -776,6 +834,11 @@ function PMA_getHTMLforCentralColumnsTableRow($row, $odd_row, $row_num, $db)
|
||||
$db
|
||||
)
|
||||
. '<input type="hidden" name="edit_save" value="save">'
|
||||
. '<td class="nowrap">'
|
||||
. '<input type="checkbox" class="checkall" name="selected_fld[]" '
|
||||
. 'value="' . htmlspecialchars($row['col_name']) . '" '
|
||||
. 'id="checkbox_row_' . $row_num . '"/>'
|
||||
. '</td>'
|
||||
. '<td id="edit_' . $row_num . '" class="edit center">'
|
||||
. '<a href="#">' . PMA_Util::getIcon('b_edit.png', __('Edit')) . '</a></td>'
|
||||
. '<td class="del_row" data-rownum = "' . $row_num . '">'
|
||||
@ -866,6 +929,87 @@ function PMA_getHTMLforCentralColumnsTableRow($row, $odd_row, $row_num, $db)
|
||||
return $tableHtml;
|
||||
}
|
||||
|
||||
/**
|
||||
* build html for editing a row in central columns table
|
||||
*
|
||||
* @param array $row array contains complete information of
|
||||
* a particular row of central list table
|
||||
* @param boolean $odd_row set true if the row is at odd number position
|
||||
* @param int $row_num position the row in the table
|
||||
*
|
||||
* @return html of a particular row in the central columns table.
|
||||
*/
|
||||
function PMA_getHTMLforCentralColumnsEditTableRow($row, $odd_row, $row_num)
|
||||
{
|
||||
$tableHtml = '<tr class="' . ($odd_row ? 'odd' : 'even') . '">'
|
||||
. '<input name="orig_col_name[' . $row_num . ']" type="hidden" '
|
||||
. 'value="' . htmlspecialchars($row['col_name']) . '">'
|
||||
. '<td name="col_name" class="nowrap">'
|
||||
. PMA_getHtmlForColumnName(
|
||||
$row_num, 0, 0, array('Field'=>$row['col_name']),
|
||||
array('central_columnswork'=>false)
|
||||
)
|
||||
. '</td>';
|
||||
$tableHtml .=
|
||||
'<td name = "col_type" class="nowrap">'
|
||||
. PMA_getHtmlForColumnType(
|
||||
$row_num, 1, 0, /*overload*/mb_strtoupper($row['col_type']), array()
|
||||
)
|
||||
. '</td>';
|
||||
$tableHtml .=
|
||||
'<td class="nowrap" name="col_length">'
|
||||
. PMA_getHtmlForColumnLength($row_num, 2, 0, 8, $row['col_length'])
|
||||
. '</td>';
|
||||
|
||||
$tableHtml .=
|
||||
'<td name="collation" class="nowrap">'
|
||||
. PMA_getHtmlForColumnCollation(
|
||||
$row_num, 3, 0, array('Collation'=>$row['col_collation'])
|
||||
)
|
||||
. '</td>';
|
||||
$tableHtml .=
|
||||
'<td class="nowrap" name="col_attribute">'
|
||||
. PMA_getHtmlForColumnAttribute(
|
||||
$row_num, 4, 0, array("attribute"=>$row['col_attribute']),
|
||||
array(), false, null
|
||||
)
|
||||
. '</td>';
|
||||
$tableHtml .=
|
||||
'<td class="nowrap" name="col_isNull">'
|
||||
. PMA_getHtmlForColumnNull($row_num, 5, 0, array('Null'=>$row['col_isNull']))
|
||||
. '</td>';
|
||||
$extra_val = $row['col_extra'];
|
||||
$tableHtml .=
|
||||
'<td class="nowrap" name="col_extra">'
|
||||
. '<select name="col_extra[' . $row_num . ']">'
|
||||
. '<option value="" ' . ($extra_val==""?'selected="selected"':'') . '></option>'
|
||||
. '<option ' . ($extra_val=="auto_increment"?'selected="selected"':'') . ''
|
||||
. ' value="auto_increment">' . __('auto_increment') . '</option>'
|
||||
. '</select>'
|
||||
. '</td>';
|
||||
$meta = array();
|
||||
if (!isset($row['col_default']) || $row['col_default'] == '') {
|
||||
$meta['DefaultType'] = 'NONE';
|
||||
} else {
|
||||
if ($row['col_default'] == 'CURRENT_TIMESTAMP'
|
||||
|| $row['col_default'] == 'NULL'
|
||||
) {
|
||||
$meta['DefaultType'] = $row['col_default'];
|
||||
} else {
|
||||
$meta['DefaultType'] = 'USER_DEFINED';
|
||||
$meta['DefaultValue'] = $row['col_default'];
|
||||
}
|
||||
}
|
||||
$tableHtml .=
|
||||
'<td class="nowrap" name="col_default">'
|
||||
. PMA_getHtmlForColumnDefault(
|
||||
$row_num, 6, 0, /*overload*/mb_strtoupper($row['col_type']), '', $meta
|
||||
)
|
||||
. '</td>';
|
||||
$tableHtml .= '</tr>';
|
||||
return $tableHtml;
|
||||
}
|
||||
|
||||
/**
|
||||
* get the list of columns in given database excluding
|
||||
* the columns present in current table
|
||||
@ -910,6 +1054,47 @@ function PMA_getCentralColumnsListRaw($db, $table)
|
||||
return json_encode($columns_list);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get HTML for "check all" check box with "with selected" dropdown
|
||||
*
|
||||
* @param string $pmaThemeImage pma theme image url
|
||||
* @param string $text_dir url for text directory
|
||||
*
|
||||
* @return string $html_output
|
||||
*/
|
||||
function PMA_getCentralColumnsTableFooter($pmaThemeImage, $text_dir)
|
||||
{
|
||||
$html_output = PMA_Util::getWithSelected(
|
||||
$pmaThemeImage, $text_dir, "tableslistcontainer"
|
||||
);
|
||||
$html_output .= PMA_Util::getButtonOrImage(
|
||||
'edit_central_columns', 'mult_submit change_central_columns',
|
||||
'submit_mult_change', __('Edit'), 'b_edit.png', 'edit central columns'
|
||||
);
|
||||
$html_output .= PMA_Util::getButtonOrImage(
|
||||
'delete_central_columns', 'mult_submit', 'submit_mult_central_columns_remove',
|
||||
__('Delete'), 'centralColumns_delete.png',
|
||||
'remove_from_central_columns'
|
||||
);
|
||||
return $html_output;
|
||||
}
|
||||
|
||||
/**
|
||||
* function generate and return the table footer for
|
||||
* multiple edit central columns page
|
||||
*
|
||||
* @return html for table footer in central columns multi edit page
|
||||
*/
|
||||
function PMA_getCentralColumnsEditTableFooter()
|
||||
{
|
||||
$html_output = '<fieldset>'
|
||||
. '<input type="submit" '
|
||||
. 'name="save_multi_central_column_edit" value="' . __('Save') . '" />'
|
||||
. '<input type="button" '
|
||||
. 'id="cancel_multi_edit" value="' . __('Cancel') . '" />'
|
||||
. '</fieldset>';
|
||||
return $html_output;
|
||||
}
|
||||
/**
|
||||
* Column `col_extra` is used to store both extra and attributes for a column.
|
||||
* This method separates them.
|
||||
@ -961,6 +1146,7 @@ function PMA_getHTMLforAddNewColumn($db)
|
||||
. '<table>';
|
||||
$addNewColumn .= PMA_getCentralColumnsTableHeader();
|
||||
$addNewColumn .= '<tr>'
|
||||
. '<td></td>'
|
||||
. '<td name="col_name" class="nowrap">'
|
||||
. PMA_getHtmlForColumnName(
|
||||
0, 0, 0, array(), array('central_columnswork'=>false)
|
||||
@ -999,4 +1185,43 @@ function PMA_getHTMLforAddNewColumn($db)
|
||||
$addNewColumn .= '</table></form></div>';
|
||||
return $addNewColumn;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get HTML for editing page central columns
|
||||
*
|
||||
* @param array $selected_fld Array containing the selected fields
|
||||
* @param string $selected_db String containing the name of database
|
||||
*
|
||||
* @return string HTML for complete editing page for central columns
|
||||
*/
|
||||
function PMA_getHTMLforEditingPage($selected_fld,$selected_db)
|
||||
{
|
||||
$html = '<form id="multi_edit_central_columns">';
|
||||
$header_cells = array(
|
||||
__('Name'), __('Type'), __('Length/Values'), __('Collation'),
|
||||
__('Attributes'), __('Null'), __('Extra'), __('Default')
|
||||
);
|
||||
$html .= PMA_getCentralColumnsEditTableHeader($header_cells);
|
||||
$selected_fld_safe = array();
|
||||
foreach ($selected_fld as $key) {
|
||||
$selected_fld_safe[] = PMA_Util::sqlAddSlashes($key);
|
||||
}
|
||||
$columns_list = implode("','", $selected_fld_safe);
|
||||
$columns_list = "'" . $columns_list . "'";
|
||||
$list_detail_cols = PMA_findExistingColNames($selected_db, $columns_list, true);
|
||||
$odd_row = false;
|
||||
$row_num = 0;
|
||||
foreach ($list_detail_cols as $row) {
|
||||
$tableHtmlRow = PMA_getHTMLforCentralColumnsEditTableRow(
|
||||
$row, $odd_row, $row_num
|
||||
);
|
||||
$html .= $tableHtmlRow;
|
||||
$odd_row = !$odd_row;
|
||||
$row_num++;
|
||||
}
|
||||
$html .= '</table>';
|
||||
$html .= PMA_getCentralColumnsEditTableFooter();
|
||||
$html .= '</form>';
|
||||
return $html;
|
||||
}
|
||||
?>
|
||||
|
||||
Loading…
Reference in New Issue
Block a user