The branch, master has been updated via a8afc24b425ef85b5deccc0b04163cc381a67947 (commit) via 143b830a7df4c6b53cc990f8783d4d4fe1a54cac (commit) via 92b179bf43c58c59deaad5342e6ca5bcb1239579 (commit) via a63532c666bfb8d4bb16e679744ffbee86c64a4b (commit) from f9ff30171adfb3637a2b135f178ffed5320535a2 (commit)
- Log ----------------------------------------------------------------- commit a8afc24b425ef85b5deccc0b04163cc381a67947 Author: Michal Čihař mcihar@novell.com Date: Tue Feb 8 11:54:51 2011 +0100
Changelog entry
commit 143b830a7df4c6b53cc990f8783d4d4fe1a54cac Author: Michal Čihař mcihar@novell.com Date: Tue Feb 8 11:54:02 2011 +0100
Make copy separate column
commit 92b179bf43c58c59deaad5342e6ca5bcb1239579 Author: Michal Čihař mcihar@novell.com Date: Tue Feb 8 11:53:28 2011 +0100
Whitespace cleanup
commit a63532c666bfb8d4bb16e679744ffbee86c64a4b Author: Jan Prachař jan.prachar@gmail.com Date: Fri Feb 4 01:21:32 2011 +0100
Add direct link to copy row of the displayed table.
-----------------------------------------------------------------------
Summary of changes: ChangeLog | 1 + js/sql.js | 30 +++++++++++----------- libraries/display_tbl.lib.php | 54 +++++++++++++++++++++++++++++++++------- tbl_change.php | 16 ++++++++++++ 4 files changed, 76 insertions(+), 25 deletions(-)
diff --git a/ChangeLog b/ChangeLog index 10d1b73..a283d89 100644 --- a/ChangeLog +++ b/ChangeLog @@ -133,6 +133,7 @@ - [interface] Add link to documentation for status variables. - [security] Redirect external links to avoid Referer leakage. - [interface] Default to not count tables in database. +- patch #3172172 [interface] Shortcut for copying table row.
3.3.10.0 (not yet released) - patch #3147400 [structure] Aria table size printed as unknown, diff --git a/js/sql.js b/js/sql.js index 593cbe7..5593446 100644 --- a/js/sql.js +++ b/js/sql.js @@ -60,7 +60,7 @@ function appendInlineAnchor() {
if (disp_mode == 'vertical') { // there can be one or two tr containing this class, depending - // on the ModifyDeleteAtLeft and ModifyDeleteAtRight cfg parameters + // on the ModifyDeleteAtLeft and ModifyDeleteAtRight cfg parameters $('#table_results tr') .find('.edit_row_anchor') .removeClass('.edit_row_anchor') @@ -108,8 +108,8 @@ function appendInlineAnchor() {
$('#rowsDeleteForm').find('thead, tbody').find('th').each(function() { var $this_th = $(this); - if ($this_th.attr('colspan') == 3) { - $this_th.attr('colspan', '4') + if ($this_th.attr('colspan') == 4) { + $this_th.attr('colspan', '5') } }); } @@ -203,7 +203,7 @@ $(document).ready(function() { return false; }) } - + /** * Ajax Event handler for 'SQL Query Submit' * @@ -226,9 +226,9 @@ $(document).ready(function() {
$.post($(this).attr('action'), $(this).serialize() , function(data) { if(data.success == true) { - // fade out previous success message, if any + // fade out previous success message, if any $('.success').fadeOut(); - // show a message that stays on screen + // show a message that stays on screen $('#sqlqueryform').before(data.message); $('#sqlqueryresults').show(); // this happens if a USE command was typed @@ -243,7 +243,7 @@ $(document).ready(function() { } } else if (data.success == false ) { - // show an error message that stays on screen + // show an error message that stays on screen $('#sqlqueryform').before(data.error); $('#sqlqueryresults').hide(); } @@ -276,7 +276,7 @@ $(document).ready(function() { event.preventDefault();
PMA_ajaxShowMessage(); - + /** * @var $the_form Object referring to the form element that paginates the results table */ @@ -400,7 +400,7 @@ $(document).ready(function() {
// We need to retrieve the value from the server for truncated/relation fields // Find the field name - + /** * @var this_field Object referring to this field (<td>) */ @@ -524,8 +524,8 @@ $(document).ready(function() { event.preventDefault();
/** - * @var $this_td Object referring to the td containing the - * "Inline Edit" link that was clicked to save the row that is + * @var $this_td Object referring to the td containing the + * "Inline Edit" link that was clicked to save the row that is * being edited * */ @@ -718,7 +718,7 @@ $(document).ready(function() { new_value = $test_element.text(); }
- + if($this_sibling.is('.relation')) { var field_name = getFieldName($this_sibling, disp_mode); $.each(data.relations, function(key, value) { @@ -727,7 +727,7 @@ $(document).ready(function() { return false; } }) - } + } if($this_sibling.is('.enum')) { new_html = new_value; } @@ -770,14 +770,14 @@ $(document).ready(function() { * vertical column highlighting in horizontal mode when hovering over the column header */ $('.column_heading').live('hover', function() { - PMA_changeClassForColumn($(this), 'hover'); + PMA_changeClassForColumn($(this), 'hover'); });
/** * vertical column marking in horizontal mode when clicking the column header */ $('.column_heading').live('click', function() { - PMA_changeClassForColumn($(this), 'marked'); + PMA_changeClassForColumn($(this), 'marked'); }); })
diff --git a/libraries/display_tbl.lib.php b/libraries/display_tbl.lib.php index 7d0299c..54d124e 100644 --- a/libraries/display_tbl.lib.php +++ b/libraries/display_tbl.lib.php @@ -641,11 +641,11 @@ function PMA_displayTableHeaders(&$is_display, &$fields_meta, $fields_cnt = 0, $ if ($_SESSION['tmp_user_values']['disp_direction'] == 'horizontal' || $_SESSION['tmp_user_values']['disp_direction'] == 'horizontalflipped') { $colspan = ($is_display['edit_lnk'] != 'nn' && $is_display['del_lnk'] != 'nn') - ? ' colspan="3"' + ? ' colspan="4"' : ''; } else { $rowspan = ($is_display['edit_lnk'] != 'nn' && $is_display['del_lnk'] != 'nn') - ? ' rowspan="3"' + ? ' rowspan="4"' : ''; }
@@ -1158,9 +1158,11 @@ function PMA_displayTableBody(&$dt_result, &$is_display, $map, $analyzed_sql) { 'sql_query' => $url_sql_query, 'goto' => 'sql.php', ); - $edit_url = 'tbl_change.php' . PMA_generate_common_url($_url_params); + $edit_url = 'tbl_change.php' . PMA_generate_common_url($_url_params + array('default_action' => 'update')); + $copy_url = 'tbl_change.php' . PMA_generate_common_url($_url_params + array('default_action' => 'insert'));
$edit_str = PMA_getIcon('b_edit.png', __('Edit'), true); + $copy_str = PMA_getIcon('b_insrow.png', __('Copy'), true);
// Class definitions required for inline editing jQuery scripts $edit_anchor_class = "edit_row_anchor"; @@ -1224,7 +1226,7 @@ function PMA_displayTableBody(&$dt_result, &$is_display, $map, $analyzed_sql) { if (! isset($js_conf)) { $js_conf = ''; } - echo PMA_generateCheckboxAndLinks('left', $del_url, $is_display, $row_no, $where_clause, $where_clause_html, $del_query, 'l', $edit_url, $edit_anchor_class, $edit_str, $del_str, $js_conf); + echo PMA_generateCheckboxAndLinks('left', $del_url, $is_display, $row_no, $where_clause, $where_clause_html, $del_query, 'l', $edit_url, $copy_url, $edit_anchor_class, $edit_str, $copy_str, $del_str, $js_conf); } // end if (1.3) } // end if (1)
@@ -1439,7 +1441,7 @@ function PMA_displayTableBody(&$dt_result, &$is_display, $map, $analyzed_sql) { if (! isset($js_conf)) { $js_conf = ''; } - echo PMA_generateCheckboxAndLinks('right', $del_url, $is_display, $row_no, $where_clause, $where_clause_html, $del_query, 'r', $edit_url, $edit_anchor_class, $edit_str, $del_str, $js_conf); + echo PMA_generateCheckboxAndLinks('right', $del_url, $is_display, $row_no, $where_clause, $where_clause_html, $del_query, 'r', $edit_url, $copy_url, $edit_anchor_class, $edit_str, $copy_str, $del_str, $js_conf); } // end if (3)
if ($_SESSION['tmp_user_values']['disp_direction'] == 'horizontal' @@ -1471,7 +1473,7 @@ function PMA_displayTableBody(&$dt_result, &$is_display, $map, $analyzed_sql) { }
if (isset($edit_url)) { - $vertical_display['edit'][$row_no] .= PMA_generateEditLink($edit_url, $alternating_color_class . ' ' . $edit_anchor_class . $vertical_class, $edit_str, $where_clause, $where_clause_html); + $vertical_display['edit'][$row_no] .= PMA_generateEditLink($edit_url, $copy_url, $alternating_color_class . ' ' . $edit_anchor_class . $vertical_class, $edit_str, $where_clause, $where_clause_html); } else { unset($vertical_display['edit'][$row_no]); } @@ -2490,7 +2492,7 @@ function PMA_generateCheckboxForMulti($del_url, $is_display, $row_no, $where_cla function PMA_generateEditLink($edit_url, $class, $edit_str, $where_clause, $where_clause_html) { $ret = ''; if (! empty($edit_url)) { - $ret .= '<td class="' . $class . '" align="center" ' . ' >' + $ret .= '<td class="' . $class . '" align="center" ' . ' ><span class="nowrap">' . PMA_linkOrButton($edit_url, $edit_str, array(), FALSE); /* * Where clause for selecting this row uniquely is provided as @@ -2499,7 +2501,34 @@ function PMA_generateEditLink($edit_url, $class, $edit_str, $where_clause, $wher if(! empty($where_clause)) { $ret .= '<input type="hidden" class="where_clause" value ="' . $where_clause_html . '" />'; } - $ret .= '</td>'; + $ret .= '</span></td>'; + } + return $ret; +} + +/** + * Generates an Copy link + * + * @uses PMA_linkOrButton() + * @param string $copy_url + * @param string $copy_str + * @param string $where_clause + * @param string $where_clause_html + * @return string the generated HTML + */ +function PMA_generateCopyLink($copy_url, $copy_str, $where_clause, $where_clause_html) { + $ret = ''; + if (! empty($copy_url)) { + $ret .= '<td align="center" ' . ' ><span class="nowrap">' + . PMA_linkOrButton($copy_url, $copy_str, array(), FALSE); + /* + * Where clause for selecting this row uniquely is provided as + * a hidden input. Used by jQuery scripts for handling inline editing + */ + if(! empty($where_clause)) { + $ret .= '<input type="hidden" class="where_clause" value ="' . $where_clause_html . '" />'; + } + $ret .= '</span></td>'; } return $ret; } @@ -2543,13 +2572,14 @@ function PMA_generateDeleteLink($del_url, $del_str, $js_conf, $class) { * @param string $del_query * @param string $id_suffix * @param string $edit_url + * @param string $copy_url * @param string $class * @param string $edit_str * @param string $del_str * @param string $js_conf * @return string the generated HTML */ -function PMA_generateCheckboxAndLinks($position, $del_url, $is_display, $row_no, $where_clause, $where_clause_html, $del_query, $id_suffix, $edit_url, $class, $edit_str, $del_str, $js_conf) { +function PMA_generateCheckboxAndLinks($position, $del_url, $is_display, $row_no, $where_clause, $where_clause_html, $del_query, $id_suffix, $edit_url, $copy_url, $class, $edit_str, $copy_str, $del_str, $js_conf) { $ret = '';
if ($position == 'left') { @@ -2557,12 +2587,16 @@ function PMA_generateCheckboxAndLinks($position, $del_url, $is_display, $row_no,
$ret .= PMA_generateEditLink($edit_url, $class, $edit_str, $where_clause, $where_clause_html, '');
+ $ret .= PMA_generateCopyLink($copy_url, $copy_str, $where_clause, $where_clause_html, ''); + $ret .= PMA_generateDeleteLink($del_url, $del_str, $js_conf, '', '');
} elseif ($position == 'right') { $ret .= PMA_generateDeleteLink($del_url, $del_str, $js_conf, '', '');
- $ret .= PMA_generateEditLink($edit_url, $class, $edit_str, $where_clause, $where_clause_html, ''); + $ret .= PMA_generateCopyLink($copy_url, $copy_str, $where_clause, $where_clause_html, ''); + + $ret .= PMA_generateEditLink($edit_url, $copy_url, $class, $edit_str, $where_clause, $where_clause_html, '');
$ret .= PMA_generateCheckboxForMulti($del_url, $is_display, $row_no, $where_clause_html, $del_query, $id_suffix='_right', '', '', ''); } diff --git a/tbl_change.php b/tbl_change.php index d77ae86..d18f59d 100644 --- a/tbl_change.php +++ b/tbl_change.php @@ -43,6 +43,9 @@ if (isset($_REQUEST['ShowFunctionFields'])) { if (isset($_REQUEST['ShowFieldTypesInDataEditView'])) { $cfg['ShowFieldTypesInDataEditView'] = $_REQUEST['ShowFieldTypesInDataEditView']; } +if (isset($_REQUEST['default_action'])) { + $default_action = $_REQUEST['default_action']; +}
/** * file listing @@ -184,6 +187,7 @@ if (isset($where_clause)) { } unset($unique_condition, $tmp_clause_is_unique); } + } } else { // no primary key given, just load first row - but what happens if table is empty? @@ -192,6 +196,11 @@ if (isset($where_clause)) { $rows = array_fill(0, $cfg['InsertRows'], false); }
+// Copying a row - fetched data will be inserted as a new row, therefore the where clause is needless. +if (isset($default_action) && $default_action === 'insert') { + unset($where_clause, $where_clauses); +} + // retrieve keys into foreign fields, if any $foreigners = PMA_getForeigners($db, $table);
@@ -488,6 +497,13 @@ foreach ($rows as $row_id => $vrow) {
$data = $vrow[$field['Field']]; } // end if... else... + + //when copying row, it is useful to empty auto-increment column to prevent duplicate key error + if (isset($default_action) && $default_action === 'insert') { + if ($field['Key'] === 'PRI' && strpos($field['Extra'], 'auto_increment') !== FALSE) { + $data = $special_chars_encoded = $special_chars = NULL; + } + } // If a timestamp field value is not included in an update // statement MySQL auto-update it to the current timestamp; // however, things have changed since MySQL 4.1, so
hooks/post-receive