Improved handling of relational fields after saving inline edits. Still need to fix the anchor that is being generated, where clause is missing

This commit is contained in:
ninadsp
2010-07-28 02:58:38 +05:30
parent fd4b33de85
commit 4190a5883a
3 changed files with 77 additions and 33 deletions

View File

@@ -5,6 +5,27 @@
* @version $Id$ * @version $Id$
*/ */
function getFieldName(this_field_obj, disp_mode) {
if(disp_mode == 'vertical') {
var field_name = $(this_field_obj).siblings('th').text();
}
else {
var this_field_index = $(this_field_obj).index();
if(window.parent.text_dir == 'ltr') {
// 3 columns to account for the checkbox, edit and delete anchors
var field_name = $(this_field_obj).parents('table').find('thead').find('th:nth('+ (this_field_index-3 )+')').text();
}
else {
var field_name = $(this_field_obj).parents('table').find('thead').find('th:nth('+ this_field_index+')').text();
}
}
field_name = $.trim(field_name);
return field_name;
}
$(document).ready(function() { $(document).ready(function() {
/** /**
@@ -117,23 +138,8 @@ $(document).ready(function() {
// We need to retrieve the value from the server for truncated/relation fields // We need to retrieve the value from the server for truncated/relation fields
// Find the field name // Find the field name
if(disp_mode == 'vertical') {
var this_field = $(this); var this_field = $(this);
var field_name = $(this).siblings('th').text(); var field_name = getFieldName($(this), disp_mode);
}
else {
var this_field = $(this);
var this_field_index = $(this).index();
if(window.parent.text_dir == 'ltr') {
// 3 columns to account for the checkbox, edit and delete anchors
var field_name = $(this).parents('table').find('thead').find('th:nth('+ (this_field_index-3 )+')').text();
}
else {
var field_name = $(this).parents('table').find('thead').find('th:nth('+ this_field_index+')').text();
}
}
field_name = $.trim(field_name);
// In each input sibling, wrap the current value in a textarea // In each input sibling, wrap the current value in a textarea
// and store the current value in a hidden span // and store the current value in a hidden span
@@ -237,24 +243,12 @@ $(document).ready(function() {
// Collect values of all fields to submit, we don't know which changed // Collect values of all fields to submit, we don't know which changed
var params_to_submit = {}; var params_to_submit = {};
var relation_fields = new Array();
$(input_siblings).each(function() { $(input_siblings).each(function() {
if(disp_mode == 'vertical') {
var this_field = $(this); var this_field = $(this);
var field_name = $(this).siblings('th').text(); var field_name = getFieldName($(this), disp_mode);
}
else {
var this_field = $(this);
var this_field_index = $(this).index();
if(window.parent.text_dir == 'ltr') {
var field_name = $(this).parents('table').find('thead').find('th:nth('+ (this_field_index-3 )+')').text();
}
else {
var field_name = $(this).parents('table').find('thead').find('th:nth('+ this_field_index+')').text();
}
}
field_name = $.trim(field_name);
var this_field_params = {}; var this_field_params = {};
if($(this).is(":not(.relation, .enum)")) { if($(this).is(":not(.relation, .enum)")) {
@@ -262,6 +256,9 @@ $(document).ready(function() {
} }
else { else {
this_field_params[field_name] = $(this).find('select').val(); this_field_params[field_name] = $(this).find('select').val();
if($(this).is('.relation')) {
relation_fields.push(field_name);
}
} }
$.extend(params_to_submit, this_field_params); $.extend(params_to_submit, this_field_params);
@@ -276,6 +273,11 @@ $(document).ready(function() {
sql_query = sql_query.replace(/,\s$/, ''); sql_query = sql_query.replace(/,\s$/, '');
sql_query += ' WHERE ' + where_clause; sql_query += ' WHERE ' + where_clause;
var rel_fields_list = '';
if(relation_fields.length > 0) {
rel_fields_list = relation_fields.join();
}
// Make the Ajax post after setting all parameters // Make the Ajax post after setting all parameters
var post_params = {'ajax_request' : true, var post_params = {'ajax_request' : true,
'sql_query' : sql_query, 'sql_query' : sql_query,
@@ -285,6 +287,7 @@ $(document).ready(function() {
'table' : window.parent.table, 'table' : window.parent.table,
'clause_is_unique' : nonunique, 'clause_is_unique' : nonunique,
'where_clause' : where_clause, 'where_clause' : where_clause,
'rel_fields_list' : rel_fields_list,
'goto' : 'sql.php' 'goto' : 'sql.php'
}; };
@@ -300,6 +303,18 @@ $(document).ready(function() {
} }
else { else {
var new_html = $(this).find('select').val(); var new_html = $(this).find('select').val();
if($(this).is('.relation')) {
var field_name = getFieldName($(this), disp_mode);
var this_field = $(this);
$.each(data.relations, function(key, value) {
if(key == field_name) {
alert(value);
var new_value = $(this_field).find('select').val();
new_html = $(value).append(new_value);
}
})
}
} }
$(this).html(new_html); $(this).html(new_html);
}) })

30
sql.php
View File

@@ -585,7 +585,35 @@ if (0 == $num_rows || $is_affected) {
} }
if( $GLOBALS['is_ajax_request'] == true) { if( $GLOBALS['is_ajax_request'] == true) {
PMA_ajaxResponse($message, $message->isSuccess());
if(isset($_REQUEST['rel_fields_list']) && $_REQUEST['rel_fields_list'] != '') {
//handle relations work here for updated row.
// @todo : $where_comparison
require_once './libraries/relation.lib.php';
$map = PMA_getForeigners($db, $table, '', 'both');
$rel_fields = explode(',', $rel_fields_list);
foreach( $rel_fields as $rel_field) {
$_url_params = array(
'db' => $map[$rel_field]['foreign_db'],
'table' => $map[$rel_field]['foreign_table'],
'pos' => '0',
'sql_query' => 'SELECT * FROM '
. PMA_backquote($map[$rel_field]['foreign_db']) . '.' . PMA_backquote($map[$rel_field]['foreign_table'])
. ' WHERE ' . PMA_backquote($map[$rel_field]['foreign_field'])
. $where_comparison
);
$extra_data['relations'][$rel_field] = '<a href="sql.php' . PMA_generate_common_url($_url_params) . '">';
$extra_data['relations'][$rel_field] .= '</a>';
}
}
$extra_data['sql_query'] = PMA_showMessage(NULL, $GLOBALS['display_query']);
PMA_ajaxResponse($message, $message->isSuccess(), $extra_data);
} }
if ($is_gotofile) { if ($is_gotofile) {

View File

@@ -421,6 +421,7 @@ if (! empty($error_messages)) {
unset($error_messages, $warning_messages, $total_affected_rows, $last_messages, $last_message); unset($error_messages, $warning_messages, $total_affected_rows, $last_messages, $last_message);
if($GLOBALS['is_ajax_request'] == true) { if($GLOBALS['is_ajax_request'] == true) {
$extra_data['sql_query'] = PMA_showMessage(NULL, $GLOBALS['display_query']); $extra_data['sql_query'] = PMA_showMessage(NULL, $GLOBALS['display_query']);
PMA_ajaxResponse($message, $message->isSuccess(), $extra_data); PMA_ajaxResponse($message, $message->isSuccess(), $extra_data);
} }