other fixes for inline edit links in vertical mode

This commit is contained in:
Marc Delisle
2010-10-17 09:40:15 -04:00
parent 634db1c81d
commit 0f156b19dd
3 changed files with 71 additions and 76 deletions

View File

@@ -32,8 +32,8 @@ function getFieldName(this_field_obj, disp_mode) {
else { else {
var this_field_index = $(this_field_obj).index(); var this_field_index = $(this_field_obj).index();
if(window.parent.text_dir == 'ltr') { if(window.parent.text_dir == 'ltr') {
// 4 columns to account for the checkbox, edit, delete and appended inline edit anchors // 4 columns to account for the checkbox, edit, delete and appended inline edit anchors but index is zero-based so substract 3
var field_name = $(this_field_obj).parents('table').find('thead').find('th:nth('+ (this_field_index-4 )+') a').text(); var field_name = $(this_field_obj).parents('table').find('thead').find('th:nth('+ (this_field_index-3 )+') a').text();
} }
else { else {
var field_name = $(this_field_obj).parents('table').find('thead').find('th:nth('+ this_field_index+') a').text(); var field_name = $(this_field_obj).parents('table').find('thead').find('th:nth('+ this_field_index+') a').text();
@@ -53,27 +53,33 @@ function getFieldName(this_field_obj, disp_mode) {
*/ */
function appendInlineAnchor(disp_mode) { function appendInlineAnchor(disp_mode) {
if(disp_mode == 'vertical') { if(disp_mode == 'vertical') {
var $cloned_row = $('.edit_row_anchor').removeClass('edit_row_anchor').parent('tr').clone(); // there can be one or two tr containing this class, depending
// on the ModifyDeleteAtLeft and ModifyDeleteAtRight cfg parameters
$('#table_results tr').find('.edit_row_anchor').parent().each(function() {
var $this_tr = $(this);
var $cloned_tr = $this_tr.clone();
var $img_object = $cloned_row.find('img:first').attr('title', PMA_messages['strInlineEdit']); var $img_object = $cloned_tr.find('img:first').attr('title', PMA_messages['strInlineEdit']);
$cloned_row.find('td').addClass('edit_row_anchor') $cloned_tr.find('td')
.find('a').attr('href', '#') .find('a').attr('href', '#')
.find('span') .find('span')
.text(PMA_messages['strInlineEdit']) .text(PMA_messages['strInlineEdit'])
.prepend($img_object); .prepend($img_object);
$cloned_row.insertBefore($('.where_clause').parent('tr')); $cloned_tr.insertAfter($this_tr);
});
$("#table_results").find('tr:first').find('th') $("#table_results").find('tr').find(':checkbox').closest('tr').find('th')
.attr('rowspan', '4'); .attr('rowspan', '4');
} }
else { else {
$('.edit_row_anchor').each(function() { $('.edit_row_anchor').each(function() {
$(this).removeClass('edit_row_anchor'); $this_td = $(this)
$this_td.removeClass('edit_row_anchor');
var $cloned_anchor = $(this).clone(); var $cloned_anchor = $this_td.clone();
var $img_object = $cloned_anchor.find('img').attr('title', PMA_messages['strInlineEdit']); var $img_object = $cloned_anchor.find('img').attr('title', PMA_messages['strInlineEdit']);
@@ -83,8 +89,7 @@ function appendInlineAnchor(disp_mode) {
.text(PMA_messages['strInlineEdit']) .text(PMA_messages['strInlineEdit'])
.prepend($img_object); .prepend($img_object);
$(this).nextAll('.where_clause:eq(0)') $this_td.after($cloned_anchor);
.before($cloned_anchor);
}); });
$('#rowsDeleteForm').find('thead').find('th').each(function() { $('#rowsDeleteForm').find('thead').find('th').each(function() {
@@ -316,7 +321,7 @@ $(document).ready(function() {
*/ */
/** /**
* On click, replace the current field with an input/textarea * On click, replace the fields of current row with an input/textarea
* @memberOf jQuery * @memberOf jQuery
* @name inline_edit_start * @name inline_edit_start
* @see PMA_ajaxShowMessage() * @see PMA_ajaxShowMessage()
@@ -482,35 +487,38 @@ $(document).ready(function() {
event.preventDefault(); event.preventDefault();
/** /**
* @var this_row Object referring to current row that is being edited * @var $this_td Object referring to the td containing the
* "Inline Edit" link that was clicked to save the row that is
* being edited
*
*/ */
var this_row = $(this); var $this_td = $(this);
// Initialize variables // Initialize variables
if(disp_mode == 'vertical') { if(disp_mode == 'vertical') {
/** /**
* @var this_row_index Index of the current <td> in the parent <tr> * @var this_td_index Index of the current <td> in the parent <tr>
* Current <td> is the inline edit anchor. * Current <td> is the inline edit anchor.
*/ */
var this_row_index = $(this).index(); var this_td_index = $this_td.index();
/** /**
* @var input_siblings Object referring to all inline editable events from same row * @var input_siblings Object referring to all inline editable events from same row
*/ */
var input_siblings = $(this).parents('tbody').find('tr').find('.data_inline_edit:nth('+this_row_index+')'); var input_siblings = $this_td.parents('tbody').find('tr').find('.data_inline_edit:nth('+this_td_index+')');
/** /**
* @var where_clause String containing the WHERE clause to select this row * @var where_clause String containing the WHERE clause to select this row
*/ */
var where_clause = $(this).parents('tbody').find('tr').find('.where_clause:nth('+this_row_index+')').val(); var where_clause = $this_td.parents('tbody').find('tr').find('.where_clause:nth('+this_td_index+')').val();
} }
else { else {
var input_siblings = $(this).parent('tr').find('.data_inline_edit'); var input_siblings = $this_td.parent('tr').find('.data_inline_edit');
var where_clause = $(this).parent('tr').find('.where_clause').val(); var where_clause = $this_td.parent('tr').find('.where_clause').val();
} }
/** /**
* @var nonunique Boolean, whether this row is unique or not * @var nonunique Boolean, whether this row is unique or not
*/ */
if($(this).is('.nonunique')) { if($this_td.is('.nonunique')) {
var nonunique = 0; var nonunique = 0;
} }
else { else {
@@ -540,32 +548,32 @@ $(document).ready(function() {
/** /**
* @var this_field Object referring to this field (<td>) * @var this_field Object referring to this field (<td>)
*/ */
var this_field = $(this); var $this_field = $(this);
/** /**
* @var field_name String containing the name of this field. * @var field_name String containing the name of this field.
* @see getFieldName() * @see getFieldName()
*/ */
var field_name = getFieldName($(this), disp_mode); var field_name = getFieldName($this_field, disp_mode);
/** /**
* @var this_field_params Array temporary storage for the name/value of current field * @var this_field_params Array temporary storage for the name/value of current field
*/ */
var this_field_params = {}; var this_field_params = {};
if($(this).is('.transformed')) { if($this_field.is('.transformed')) {
transformation_fields = true; transformation_fields = true;
} }
if($(this).is(":not(.relation, .enum)")) { if($this_field.is(":not(.relation, .enum)")) {
this_field_params[field_name] = $(this).find('textarea').val(); this_field_params[field_name] = $this_field.find('textarea').val();
if($(this).is('.transformed')) { if($this_field.is('.transformed')) {
$.extend(transform_fields, this_field_params); $.extend(transform_fields, this_field_params);
} }
} }
else { else {
this_field_params[field_name] = $(this).find('select').val(); this_field_params[field_name] = $this_field.find('select').val();
if($(this).is('.relation')) { if($this_field.is('.relation')) {
$.extend(relation_fields, this_field_params); $.extend(relation_fields, this_field_params);
} }
} }
@@ -619,7 +627,7 @@ $(document).ready(function() {
$.post('tbl_replace.php', post_params, function(data) { $.post('tbl_replace.php', post_params, function(data) {
if(data.success == true) { if(data.success == true) {
PMA_ajaxShowMessage(data.message); PMA_ajaxShowMessage(data.message);
$(this_row).removeClass('edit_row_anchor_active').addClass('edit_row_anchor'); $this_td.removeClass('edit_row_anchor_active').addClass('edit_row_anchor');
$(input_siblings).each(function() { $(input_siblings).each(function() {
// Inline edit post has been successful. // Inline edit post has been successful.

View File

@@ -1442,7 +1442,6 @@ function PMA_displayTableBody(&$dt_result, &$is_display, $map, $analyzed_sql) {
$vertical_display['edit'][$row_no] = ''; $vertical_display['edit'][$row_no] = '';
$vertical_display['delete'][$row_no] = ''; $vertical_display['delete'][$row_no] = '';
$vertical_display['row_delete'][$row_no] = ''; $vertical_display['row_delete'][$row_no] = '';
$vertical_display['where_clause'][$row_no] = '';
} }
$column_style_vertical = ''; $column_style_vertical = '';
@@ -1467,8 +1466,13 @@ function PMA_displayTableBody(&$dt_result, &$is_display, $map, $analyzed_sql) {
if (isset($edit_url)) { if (isset($edit_url)) {
$vertical_display['edit'][$row_no] .= '<td align="center" class="' . $alternating_color_class . ' ' . $edit_anchor_class . '" ' . $column_style_vertical . '>' . "\n" $vertical_display['edit'][$row_no] .= '<td align="center" class="' . $alternating_color_class . ' ' . $edit_anchor_class . '" ' . $column_style_vertical . '>' . "\n"
. PMA_linkOrButton($edit_url, $edit_str, array(), false) . PMA_linkOrButton($edit_url, $edit_str, array(), false);
. ' </td>' . "\n"; // Generates the 'where_clause' hidden input field
// for inline ajax edit if required
if(! empty($where_clause) ) {
$vertical_display['edit'][$row_no] .= '<input type="hidden" class="where_clause" value ="' . $where_clause_html . '" />';
}
$vertical_display['edit'][$row_no] .= '</td>';
} else { } else {
unset($vertical_display['edit'][$row_no]); unset($vertical_display['edit'][$row_no]);
} }
@@ -1481,13 +1485,6 @@ function PMA_displayTableBody(&$dt_result, &$is_display, $map, $analyzed_sql) {
unset($vertical_display['delete'][$row_no]); unset($vertical_display['delete'][$row_no]);
} }
if( !empty($where_clause) ) {
$vertical_display['where_clause'][$row_no] = '<input type="hidden" class="where_clause" value ="' . $where_clause_html . '" />';
}
else {
unset($vertical_display['where_clause'][$row_no]);
}
echo (($_SESSION['tmp_user_values']['disp_direction'] == 'horizontal' || $_SESSION['tmp_user_values']['disp_direction'] == 'horizontalflipped') ? "\n" : ''); echo (($_SESSION['tmp_user_values']['disp_direction'] == 'horizontal' || $_SESSION['tmp_user_values']['disp_direction'] == 'horizontalflipped') ? "\n" : '');
$row_no++; $row_no++;
} // end while } // end while
@@ -1500,7 +1497,6 @@ function PMA_displayTableBody(&$dt_result, &$is_display, $map, $analyzed_sql) {
/** /**
* Do display the result table with the vertical direction mode. * Do display the result table with the vertical direction mode.
* Credits for this feature goes to Garvin Hicking <hicking@faktor-e.de>.
* *
* @return boolean always true * @return boolean always true
* *
@@ -1567,22 +1563,6 @@ function PMA_displayVerticalTable()
echo '</tr>' . "\n"; echo '</tr>' . "\n";
} // end if } // end if
// Generates the 'where_clause' hidden input field for inline ajax edit if required
if ( is_array($vertical_display['delete']) && (count($vertical_display['delete']) > 0 ) ) {
echo '<tr>' . "\n";
$foo_counter = 0;
foreach ($vertical_display['where_clause'] as $val) {
if (($foo_counter != 0) && ($_SESSION['tmp_user_values']['repeat_cells'] != 0) && !($foo_counter % $_SESSION['tmp_user_values']['repeat_cells'])) {
echo '<th></th>' . "\n";
}
echo $val;
$foo_counter++;
} // end while
echo '</tr>' . "\n";
} // end if
// Displays data // Displays data
foreach ($vertical_display['desc'] AS $key => $val) { foreach ($vertical_display['desc'] AS $key => $val) {

View File

@@ -26,9 +26,16 @@ if ($doWriteModifyAt == 'left') {
. ' </td>' . "\n"; . ' </td>' . "\n";
} }
if (!empty($edit_url)) { if (!empty($edit_url)) {
echo ' <td class="' . $edit_anchor_class . '" align="center">' . "\n" echo '<td class="' . $edit_anchor_class . '" align="center">'
. PMA_linkOrButton($edit_url, $edit_str, '', FALSE) . PMA_linkOrButton($edit_url, $edit_str, '', FALSE);
. ' </td>' . "\n"; /*
* 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)) {
echo '<input type="hidden" class="where_clause" value ="' . $where_clause_html . '" />';
}
echo '</td>';
} }
if (!empty($del_url)) { if (!empty($del_url)) {
echo ' <td align="center">' . "\n" echo ' <td align="center">' . "\n"
@@ -42,9 +49,16 @@ if ($doWriteModifyAt == 'left') {
. ' </td>' . "\n"; . ' </td>' . "\n";
} }
if (!empty($edit_url)) { if (!empty($edit_url)) {
echo ' <td class="' . $edit_anchor_class . '" align="center">' . "\n" echo '<td class="' . $edit_anchor_class . '" align="center">'
. PMA_linkOrButton($edit_url, $edit_str, '', FALSE) . PMA_linkOrButton($edit_url, $edit_str, '', FALSE);
. ' </td>' . "\n"; /*
* 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)) {
echo '<input type="hidden" class="where_clause" value ="' . $where_clause_html . '" />';
}
echo ' </td>';
} }
if (!empty($del_url) && $is_display['del_lnk'] != 'kp') { if (!empty($del_url) && $is_display['del_lnk'] != 'kp') {
echo ' <td align="center">' . "\n" echo ' <td align="center">' . "\n"
@@ -54,11 +68,4 @@ if ($doWriteModifyAt == 'left') {
. ' </td>' . "\n"; . ' </td>' . "\n";
} }
} }
/*
* 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)) {
echo '<input type="hidden" class="where_clause" value ="' . $where_clause_html . '" />';
}
?> ?>