From fd4b33de85c7b67a2565e5b5db1ee098205dfb9e Mon Sep 17 00:00:00 2001 From: ninadsp Date: Mon, 26 Jul 2010 01:21:52 +0530 Subject: [PATCH] Added handling of enum values to inline editing --- js/sql.js | 26 +++++++++++++++++++++++--- libraries/display_tbl.lib.php | 8 +++++++- sql.php | 26 ++++++++++++++++++++++++++ 3 files changed, 56 insertions(+), 4 deletions(-) diff --git a/js/sql.js b/js/sql.js index 04f2930be..e5082d35f 100644 --- a/js/sql.js +++ b/js/sql.js @@ -137,7 +137,7 @@ $(document).ready(function() { // 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)')) { + if($(this).is(':not(.truncated, .transformed, .relation, .enum)')) { // handle non-truncated, non-transformed, non-relation values // We don't need to get any more data, just wrap the value $(this).html('') @@ -182,6 +182,26 @@ $(document).ready(function() { 'curr_value' : curr_value } + $.post('sql.php', post_params, function(data) { + $(this_field).html(data.dropdown) + .append(''+data_value+''); + $(".original_data").hide(); + }) + } + else if($(this).is('.enum')) { + //handle enum fields + var curr_value = $(this).text(); + + var post_params = { + 'ajax_request' : true, + 'get_enum_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+''); @@ -237,7 +257,7 @@ $(document).ready(function() { field_name = $.trim(field_name); var this_field_params = {}; - if($(this).is(":not(.relation)")) { + if($(this).is(":not(.relation, .enum)")) { this_field_params[field_name] = $(this).find('textarea').val(); } else { @@ -275,7 +295,7 @@ $(document).ready(function() { $(input_siblings).each(function() { // Inline edit post has been successful. - if($(this).is(':not(.relation)')) { + if($(this).is(':not(.relation, .enum)')) { var new_html = $(this).find('textarea').val(); } else { diff --git a/libraries/display_tbl.lib.php b/libraries/display_tbl.lib.php index 8ad90df08..e9bb22c6e 100755 --- a/libraries/display_tbl.lib.php +++ b/libraries/display_tbl.lib.php @@ -2360,11 +2360,17 @@ function PMA_handle_non_printable_contents($category, $content, $transform_funct function PMA_prepare_row_data($mouse_events, $class, $condition_field, $analyzed_sql, $meta, $map, $data, $transform_function, $default_function, $nowrap, $where_comparison, $transform_options, $is_field_truncated ) { $data_inline_edit_class = 'data_inline_edit'; + $enum_class = ''; + if(strpos($meta->flags, 'enum') !== false) { + $enum_class = ' enum'; + } + // continue the tag started before calling this function: $result = $mouse_events . ' class="' . $class . ($condition_field ? ' condition' : '') . $nowrap . ' ' . $data_inline_edit_class . ($is_field_truncated ? ' truncated' : '') . ($transform_function != $default_function ? ' transformed' : '') - . (isset($map[$meta->name]) ? ' relation' : '') . '">'; + . (isset($map[$meta->name]) ? ' relation' : '') + . $enum_class . '">'; if (isset($analyzed_sql[0]['select_expr']) && is_array($analyzed_sql[0]['select_expr'])) { foreach ($analyzed_sql[0]['select_expr'] AS $select_expr_position => $select_expr) { diff --git a/sql.php b/sql.php index f80c23983..5297cb8a7 100755 --- a/sql.php +++ b/sql.php @@ -70,6 +70,32 @@ if(isset($_REQUEST['get_relational_values']) && $_REQUEST['get_relational_values PMA_ajaxResponse(NULL, true, $extra_data); } +/** + * Just like above, find possible values for enum fields during inline edit. + */ +if(isset($_REQUEST['get_enum_values']) && $_REQUEST['get_enum_values'] == true) { + $field_info_query = 'SHOW FIELDS FROM `' . $db . '`.`' . $table . '` LIKE \'' . $_REQUEST['column'] . '\' ;'; + + $field_info_result = PMA_DBI_fetch_result($field_info_query, null, null, null, PMA_DBI_QUERY_STORE); + + $search = array('enum', '(', ')', "'"); + + $values = explode(',', str_replace($search, '', $field_info_result[0]['Type'])); + + $dropdown = ''; + foreach($values as $value) { + $dropdown .= '