Relational values are now retrieved from the server for inline editing. However, the displaying of relational values after a successful inline edit has to be handled better. The link to the sql query is lost, and we dont know how the relational display column setting will be handled

This commit is contained in:
ninadsp
2010-07-24 00:32:50 +05:30
parent 9391e869ac
commit 25dbe9b039
2 changed files with 71 additions and 21 deletions

View File

@@ -115,6 +115,26 @@ $(document).ready(function() {
$(input_siblings).each(function() { $(input_siblings).each(function() {
var data_value = $(this).html(); var data_value = $(this).html();
// We need to retrieve the value from the server for truncated/relation fields
// Find the field name
if(disp_mode == 'vertical') {
var this_field = $(this);
var field_name = $(this).siblings('th').text();
}
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
if($(this).is(':not(.truncated, .transformed, .relation)')) { if($(this).is(':not(.truncated, .transformed, .relation)')) {
@@ -127,25 +147,6 @@ $(document).ready(function() {
else if($(this).is('.truncated, .transformed')) { else if($(this).is('.truncated, .transformed')) {
//handle truncated/transformed values values //handle truncated/transformed values values
// We need to retrieve the value from the server
// Find the field name
if(disp_mode == 'vertical') {
var this_field = $(this);
var field_name = $(this).siblings('th').text();
}
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);
var sql_query = 'SELECT ' + field_name + ' FROM ' + window.parent.table + ' WHERE ' + where_clause; var sql_query = 'SELECT ' + field_name + ' FROM ' + window.parent.table + ' WHERE ' + where_clause;
// Make the Ajax call and get the data, wrap it and insert it // Make the Ajax call and get the data, wrap it and insert it
@@ -168,6 +169,24 @@ $(document).ready(function() {
} }
else if($(this).is('.relation')) { else if($(this).is('.relation')) {
//handle relations //handle relations
var curr_value = $(this).find('a').text();
var post_params = {
'ajax_request' : true,
'get_relational_values' : true,
'db' : window.parent.db,
'table' : window.parent.table,
'column' : field_name,
'token' : window.parent.token,
'curr_value' : curr_value
}
$.post('sql.php', post_params, function(data) {
$(this_field).html(data.dropdown)
.append('<span class="original_data">'+data_value+'</span>');
$(".original_data").hide();
})
} }
}) })
}) // End On click, replace the current field with an input/textarea }) // End On click, replace the current field with an input/textarea
@@ -218,7 +237,12 @@ $(document).ready(function() {
field_name = $.trim(field_name); field_name = $.trim(field_name);
var this_field_params = {}; var this_field_params = {};
this_field_params[field_name] = $(this).find('textarea').val(); if($(this).is(":not(.relation)")) {
this_field_params[field_name] = $(this).find('textarea').val();
}
else {
this_field_params[field_name] = $(this).find('select').val();
}
$.extend(params_to_submit, this_field_params); $.extend(params_to_submit, this_field_params);
}) })
@@ -253,8 +277,11 @@ $(document).ready(function() {
// Inline edit post has been successful. // Inline edit post has been successful.
if($(this).is(':not(.relation)')) { if($(this).is(':not(.relation)')) {
var new_html = $(this).find('textarea').val(); var new_html = $(this).find('textarea').val();
$(this).html(new_html);
} }
else {
var new_html = $(this).find('select').val();
}
$(this).html(new_html);
}) })
} }
else { else {

23
sql.php
View File

@@ -48,6 +48,29 @@ if (isset($fields['dbase'])) {
$db = $fields['dbase']; $db = $fields['dbase'];
} }
/**
* During inline edit, if we have a relational field, show the dropdown for it
*
* This doesn't seem to be the right place to do this, but I can't think of any
* better place either.
*/
if(isset($_REQUEST['get_relational_values']) && $_REQUEST['get_relational_values'] == true) {
require_once 'libraries/relation.lib.php';
$column = $_REQUEST['column'];
$foreigners = PMA_getForeigners($db, $table, $column);
$foreignData = PMA_getForeignData($foreigners, $column, false, '', '');
$dropdown = PMA_foreignDropdown($foreignData['disp_row'], $foreignData['foreign_field'], $foreignData['foreign_display'], $_REQUEST['curr_value'], $cfg['ForeignKeyMaxLimit']);
$dropdown = '<select>' . $dropdown . '</select>';
$extra_data['dropdown'] = $dropdown;
PMA_ajaxResponse(NULL, true, $extra_data);
}
// Default to browse if no query set and we have table // Default to browse if no query set and we have table
// (needed for browsing from DefaultTabTable) // (needed for browsing from DefaultTabTable)
if (empty($sql_query) && strlen($table) && strlen($db)) { if (empty($sql_query) && strlen($table) && strlen($db)) {