Add direct link to copy row of the displayed table.

This commit is contained in:
Jan Prachař
2011-02-04 01:21:32 +01:00
committed by Michal Čihař
parent f9ff30171a
commit a63532c666
3 changed files with 33 additions and 11 deletions

View File

@@ -74,6 +74,7 @@ function appendInlineAnchor() {
$cloned_tr.find('td') $cloned_tr.find('td')
.addClass('inline_edit_anchor') .addClass('inline_edit_anchor')
.find('span.sep, a:last').remove().end()
.find('a').attr('href', '#') .find('a').attr('href', '#')
.find('span') .find('span')
.text(' ' + PMA_messages['strInlineEdit']) .text(' ' + PMA_messages['strInlineEdit'])
@@ -98,6 +99,7 @@ function appendInlineAnchor() {
$img_object.attr('src', img_src); $img_object.attr('src', img_src);
$cloned_anchor.addClass('inline_edit_anchor') $cloned_anchor.addClass('inline_edit_anchor')
.find('span.sep, a:last').remove().end()
.find('a').attr('href', '#') .find('a').attr('href', '#')
.find('span') .find('span')
.text(' ' + PMA_messages['strInlineEdit']) .text(' ' + PMA_messages['strInlineEdit'])

View File

@@ -1158,7 +1158,8 @@ function PMA_displayTableBody(&$dt_result, &$is_display, $map, $analyzed_sql) {
'sql_query' => $url_sql_query, 'sql_query' => $url_sql_query,
'goto' => 'sql.php', '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); $edit_str = PMA_getIcon('b_edit.png', __('Edit'), true);
@@ -1224,7 +1225,7 @@ function PMA_displayTableBody(&$dt_result, &$is_display, $map, $analyzed_sql) {
if (! isset($js_conf)) { if (! isset($js_conf)) {
$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, $del_str, $js_conf);
} // end if (1.3) } // end if (1.3)
} // end if (1) } // end if (1)
@@ -1439,7 +1440,7 @@ function PMA_displayTableBody(&$dt_result, &$is_display, $map, $analyzed_sql) {
if (! isset($js_conf)) { if (! isset($js_conf)) {
$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, $del_str, $js_conf);
} // end if (3) } // end if (3)
if ($_SESSION['tmp_user_values']['disp_direction'] == 'horizontal' if ($_SESSION['tmp_user_values']['disp_direction'] == 'horizontal'
@@ -1471,7 +1472,7 @@ function PMA_displayTableBody(&$dt_result, &$is_display, $map, $analyzed_sql) {
} }
if (isset($edit_url)) { 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 { } else {
unset($vertical_display['edit'][$row_no]); unset($vertical_display['edit'][$row_no]);
} }
@@ -2481,17 +2482,19 @@ function PMA_generateCheckboxForMulti($del_url, $is_display, $row_no, $where_cla
* *
* @uses PMA_linkOrButton() * @uses PMA_linkOrButton()
* @param string $edit_url * @param string $edit_url
* @param string $copy_url
* @param string $class * @param string $class
* @param string $edit_str * @param string $edit_str
* @param string $where_clause * @param string $where_clause
* @param string $where_clause_html * @param string $where_clause_html
* @return string the generated HTML * @return string the generated HTML
*/ */
function PMA_generateEditLink($edit_url, $class, $edit_str, $where_clause, $where_clause_html) { function PMA_generateEditLink($edit_url, $copy_url, $class, $edit_str, $where_clause, $where_clause_html) {
$ret = ''; $ret = '';
if (! empty($edit_url)) { 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); . PMA_linkOrButton($edit_url, $edit_str, array(), FALSE) . '<span class="sep"> | </span>'
. PMA_linkOrButton($copy_url, __('Copy'), array(), FALSE);
/* /*
* Where clause for selecting this row uniquely is provided as * Where clause for selecting this row uniquely is provided as
* a hidden input. Used by jQuery scripts for handling inline editing * a hidden input. Used by jQuery scripts for handling inline editing
@@ -2499,7 +2502,7 @@ function PMA_generateEditLink($edit_url, $class, $edit_str, $where_clause, $wher
if(! empty($where_clause)) { if(! empty($where_clause)) {
$ret .= '<input type="hidden" class="where_clause" value ="' . $where_clause_html . '" />'; $ret .= '<input type="hidden" class="where_clause" value ="' . $where_clause_html . '" />';
} }
$ret .= '</td>'; $ret .= '</span></td>';
} }
return $ret; return $ret;
} }
@@ -2543,26 +2546,27 @@ function PMA_generateDeleteLink($del_url, $del_str, $js_conf, $class) {
* @param string $del_query * @param string $del_query
* @param string $id_suffix * @param string $id_suffix
* @param string $edit_url * @param string $edit_url
* @param string $copy_url
* @param string $class * @param string $class
* @param string $edit_str * @param string $edit_str
* @param string $del_str * @param string $del_str
* @param string $js_conf * @param string $js_conf
* @return string the generated HTML * @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, $del_str, $js_conf) {
$ret = ''; $ret = '';
if ($position == 'left') { if ($position == 'left') {
$ret .= PMA_generateCheckboxForMulti($del_url, $is_display, $row_no, $where_clause_html, $del_query, $id_suffix='_left', '', '', ''); $ret .= PMA_generateCheckboxForMulti($del_url, $is_display, $row_no, $where_clause_html, $del_query, $id_suffix='_left', '', '', '');
$ret .= PMA_generateEditLink($edit_url, $class, $edit_str, $where_clause, $where_clause_html, ''); $ret .= PMA_generateEditLink($edit_url, $copy_url, $class, $edit_str, $where_clause, $where_clause_html, '');
$ret .= PMA_generateDeleteLink($del_url, $del_str, $js_conf, '', ''); $ret .= PMA_generateDeleteLink($del_url, $del_str, $js_conf, '', '');
} elseif ($position == 'right') { } elseif ($position == 'right') {
$ret .= PMA_generateDeleteLink($del_url, $del_str, $js_conf, '', ''); $ret .= PMA_generateDeleteLink($del_url, $del_str, $js_conf, '', '');
$ret .= PMA_generateEditLink($edit_url, $class, $edit_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', '', '', ''); $ret .= PMA_generateCheckboxForMulti($del_url, $is_display, $row_no, $where_clause_html, $del_query, $id_suffix='_right', '', '', '');
} }

View File

@@ -43,6 +43,9 @@ if (isset($_REQUEST['ShowFunctionFields'])) {
if (isset($_REQUEST['ShowFieldTypesInDataEditView'])) { if (isset($_REQUEST['ShowFieldTypesInDataEditView'])) {
$cfg['ShowFieldTypesInDataEditView'] = $_REQUEST['ShowFieldTypesInDataEditView']; $cfg['ShowFieldTypesInDataEditView'] = $_REQUEST['ShowFieldTypesInDataEditView'];
} }
if (isset($_REQUEST['default_action'])) {
$default_action = $_REQUEST['default_action'];
}
/** /**
* file listing * file listing
@@ -184,6 +187,7 @@ if (isset($where_clause)) {
} }
unset($unique_condition, $tmp_clause_is_unique); unset($unique_condition, $tmp_clause_is_unique);
} }
} }
} else { } else {
// no primary key given, just load first row - but what happens if table is empty? // 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); $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 // retrieve keys into foreign fields, if any
$foreigners = PMA_getForeigners($db, $table); $foreigners = PMA_getForeigners($db, $table);
@@ -488,6 +497,13 @@ foreach ($rows as $row_id => $vrow) {
$data = $vrow[$field['Field']]; $data = $vrow[$field['Field']];
} // end if... else... } // 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 // If a timestamp field value is not included in an update
// statement MySQL auto-update it to the current timestamp; // statement MySQL auto-update it to the current timestamp;
// however, things have changed since MySQL 4.1, so // however, things have changed since MySQL 4.1, so