diff --git a/js/sql.js b/js/sql.js index a6ad96e92..04f2930be 100644 --- a/js/sql.js +++ b/js/sql.js @@ -115,6 +115,26 @@ $(document).ready(function() { $(input_siblings).each(function() { 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 // and store the current value in a hidden span if($(this).is(':not(.truncated, .transformed, .relation)')) { @@ -127,25 +147,6 @@ $(document).ready(function() { else if($(this).is('.truncated, .transformed')) { //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; // 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')) { //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(''+data_value+''); + $(".original_data").hide(); + }) } }) }) // End On click, replace the current field with an input/textarea @@ -218,7 +237,12 @@ $(document).ready(function() { field_name = $.trim(field_name); 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); }) @@ -253,8 +277,11 @@ $(document).ready(function() { // Inline edit post has been successful. if($(this).is(':not(.relation)')) { var new_html = $(this).find('textarea').val(); - $(this).html(new_html); } + else { + var new_html = $(this).find('select').val(); + } + $(this).html(new_html); }) } else { diff --git a/sql.php b/sql.php index 9e080de7f..f80c23983 100755 --- a/sql.php +++ b/sql.php @@ -48,6 +48,29 @@ if (isset($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 = ''; + + $extra_data['dropdown'] = $dropdown; + PMA_ajaxResponse(NULL, true, $extra_data); +} + + // Default to browse if no query set and we have table // (needed for browsing from DefaultTabTable) if (empty($sql_query) && strlen($table) && strlen($db)) {