Inline edit extended to fields of type set.
This commit is contained in:
60
js/sql.js
60
js/sql.js
@@ -458,9 +458,9 @@ $(document).ready(function() {
|
|||||||
*/
|
*/
|
||||||
var relation_curr_value = $this_field.find('a').text();
|
var relation_curr_value = $this_field.find('a').text();
|
||||||
/**
|
/**
|
||||||
* @var enum_curr_value String current value of the field (for fields that are of type enum).
|
* @var curr_value String current value of the field (for fields that are of type enum or set).
|
||||||
*/
|
*/
|
||||||
var enum_curr_value = $this_field.text();
|
var curr_value = $this_field.text();
|
||||||
|
|
||||||
if($this_field.is(':not(.not_null)')){
|
if($this_field.is(':not(.not_null)')){
|
||||||
// add a checkbox to mark null for all the field that are nullable.
|
// add a checkbox to mark null for all the field that are nullable.
|
||||||
@@ -490,8 +490,13 @@ $(document).ready(function() {
|
|||||||
|
|
||||||
// if 'chechbox_null_<field_name>_<row_index>' is clicked empty the corresponding select/editor.
|
// if 'chechbox_null_<field_name>_<row_index>' is clicked empty the corresponding select/editor.
|
||||||
$('.checkbox_null_' + field_name + '_' + this_row_index).bind('click', function(e) {
|
$('.checkbox_null_' + field_name + '_' + this_row_index).bind('click', function(e) {
|
||||||
if ($this_field.is('.enum, .set')) {
|
if ($this_field.is('.enum')) {
|
||||||
$this_field.find('select').attr('value', '');
|
$this_field.find('select').attr('value', '');
|
||||||
|
} else if ($this_field.is('.set')) {
|
||||||
|
$this_field.find('select').find('option').each(function() {
|
||||||
|
var $option = $(this);
|
||||||
|
$option.attr('selected', false);
|
||||||
|
})
|
||||||
} else if ($this_field.is('.relation')) {
|
} else if ($this_field.is('.relation')) {
|
||||||
// if the dropdown is there to select the foreign value
|
// if the dropdown is there to select the foreign value
|
||||||
if ($this_field.find('select').length > 0) {
|
if ($this_field.find('select').length > 0) {
|
||||||
@@ -511,7 +516,7 @@ $(document).ready(function() {
|
|||||||
|
|
||||||
// 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_field.is(':not(.truncated, .transformed, .relation, .enum, .null)')) {
|
if($this_field.is(':not(.truncated, .transformed, .relation, .enum, .set, .null)')) {
|
||||||
// handle non-truncated, non-transformed, non-relation values
|
// handle non-truncated, non-transformed, non-relation values
|
||||||
// We don't need to get any more data, just wrap the value
|
// We don't need to get any more data, just wrap the value
|
||||||
$this_field.append('<textarea>'+data_value+'</textarea>');
|
$this_field.append('<textarea>'+data_value+'</textarea>');
|
||||||
@@ -582,7 +587,7 @@ $(document).ready(function() {
|
|||||||
'table' : window.parent.table,
|
'table' : window.parent.table,
|
||||||
'column' : field_name,
|
'column' : field_name,
|
||||||
'token' : window.parent.token,
|
'token' : window.parent.token,
|
||||||
'curr_value' : enum_curr_value
|
'curr_value' : curr_value
|
||||||
}
|
}
|
||||||
|
|
||||||
$.post('sql.php', post_params, function(data) {
|
$.post('sql.php', post_params, function(data) {
|
||||||
@@ -591,6 +596,29 @@ $(document).ready(function() {
|
|||||||
$(".original_data").hide();
|
$(".original_data").hide();
|
||||||
}) // end $.post()
|
}) // end $.post()
|
||||||
}
|
}
|
||||||
|
else if($this_field.is('.set')) {
|
||||||
|
/** @lends jQuery */
|
||||||
|
//handle set fields
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var post_params Object containing parameters for the POST request
|
||||||
|
*/
|
||||||
|
var post_params = {
|
||||||
|
'ajax_request' : true,
|
||||||
|
'get_set_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.append(data.select);
|
||||||
|
$this_field.append('<span class="original_data">'+data_value+'</span>');
|
||||||
|
$(".original_data").hide();
|
||||||
|
}) // end $.post()
|
||||||
|
}
|
||||||
else if($this_field.is('.null')) {
|
else if($this_field.is('.null')) {
|
||||||
//handle null fields
|
//handle null fields
|
||||||
$this_field.append('<textarea></textarea>');
|
$this_field.append('<textarea></textarea>');
|
||||||
@@ -701,13 +729,17 @@ $(document).ready(function() {
|
|||||||
if (is_null) {
|
if (is_null) {
|
||||||
sql_query += ' ' + field_name + "=NULL , ";
|
sql_query += ' ' + field_name + "=NULL , ";
|
||||||
} else {
|
} else {
|
||||||
if($this_field.is(":not(.relation, .enum)")) {
|
if($this_field.is(":not(.relation, .enum, .set)")) {
|
||||||
this_field_params[field_name] = $this_field.find('textarea').val();
|
this_field_params[field_name] = $this_field.find('textarea').val();
|
||||||
if($this_field.is('.transformed')) {
|
if($this_field.is('.transformed')) {
|
||||||
$.extend(transform_fields, this_field_params);
|
$.extend(transform_fields, this_field_params);
|
||||||
}
|
}
|
||||||
}
|
} else if ($this_field.is('.set')) {
|
||||||
else {
|
$test_element = $this_field.find('select');
|
||||||
|
this_field_params[field_name] = $test_element.map(function(){
|
||||||
|
return $(this).val();
|
||||||
|
}).get().join(",");
|
||||||
|
} else {
|
||||||
// results from a drop-down
|
// results from a drop-down
|
||||||
$test_element = $this_field.find('select');
|
$test_element = $this_field.find('select');
|
||||||
if ($test_element.length != 0) {
|
if ($test_element.length != 0) {
|
||||||
@@ -777,7 +809,7 @@ $(document).ready(function() {
|
|||||||
$this_sibling.addClass('null');
|
$this_sibling.addClass('null');
|
||||||
} else {
|
} else {
|
||||||
$this_sibling.removeClass('null');
|
$this_sibling.removeClass('null');
|
||||||
if($this_sibling.is(':not(.relation, .enum)')) {
|
if($this_sibling.is(':not(.relation, .enum, .set)')) {
|
||||||
/**
|
/**
|
||||||
* @var new_html String containing value of the data field after edit
|
* @var new_html String containing value of the data field after edit
|
||||||
*/
|
*/
|
||||||
@@ -821,9 +853,15 @@ $(document).ready(function() {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
} else if ($this_sibling.is('.enum')) {
|
||||||
if($this_sibling.is('.enum')) {
|
|
||||||
new_html = new_value;
|
new_html = new_value;
|
||||||
|
} else if ($this_sibling.is('.set')) {
|
||||||
|
if (new_value != null) {
|
||||||
|
$.each(new_value, function(key, value) {
|
||||||
|
new_html = new_html + value + ',';
|
||||||
|
})
|
||||||
|
new_html = new_html.substring(0, new_html.length-1);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$this_sibling.html(new_html);
|
$this_sibling.html(new_html);
|
||||||
|
@@ -2419,6 +2419,11 @@ function PMA_prepare_row_data($class, $condition_field, $analyzed_sql, $meta, $m
|
|||||||
$enum_class = ' enum';
|
$enum_class = ' enum';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$set_class = '';
|
||||||
|
if(strpos($meta->flags, 'set') !== false) {
|
||||||
|
$set_class = ' set';
|
||||||
|
}
|
||||||
|
|
||||||
$mime_type_class = '';
|
$mime_type_class = '';
|
||||||
if(isset($meta->mimetype)) {
|
if(isset($meta->mimetype)) {
|
||||||
$mime_type_class = ' ' . preg_replace('/\//', '_', $meta->mimetype);
|
$mime_type_class = ' ' . preg_replace('/\//', '_', $meta->mimetype);
|
||||||
@@ -2428,7 +2433,7 @@ function PMA_prepare_row_data($class, $condition_field, $analyzed_sql, $meta, $m
|
|||||||
$result = ' class="' . $class . ($condition_field ? ' condition' : '') . $nowrap
|
$result = ' class="' . $class . ($condition_field ? ' condition' : '') . $nowrap
|
||||||
. ' ' . ($is_field_truncated ? ' truncated' : '')
|
. ' ' . ($is_field_truncated ? ' truncated' : '')
|
||||||
. ($transform_function != $default_function ? ' transformed' : '')
|
. ($transform_function != $default_function ? ' transformed' : '')
|
||||||
. $enum_class . $mime_type_class . '">';
|
. $enum_class . $set_class . $mime_type_class . '">';
|
||||||
|
|
||||||
if (isset($analyzed_sql[0]['select_expr']) && is_array($analyzed_sql[0]['select_expr'])) {
|
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) {
|
foreach ($analyzed_sql[0]['select_expr'] AS $select_expr_position => $select_expr) {
|
||||||
|
28
sql.php
28
sql.php
@@ -115,6 +115,34 @@ if(isset($_REQUEST['get_enum_values']) && $_REQUEST['get_enum_values'] == true)
|
|||||||
PMA_ajaxResponse(NULL, true, $extra_data);
|
PMA_ajaxResponse(NULL, true, $extra_data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Find possible values for set fields during inline edit.
|
||||||
|
*/
|
||||||
|
if(isset($_REQUEST['get_set_values']) && $_REQUEST['get_set_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);
|
||||||
|
|
||||||
|
$selected_values = explode(',', $_REQUEST['curr_value']);
|
||||||
|
|
||||||
|
$search = array('set', '(', ')', "'");
|
||||||
|
$values = explode(',', str_replace($search, '', $field_info_result[0]['Type']));
|
||||||
|
|
||||||
|
$select = '';
|
||||||
|
foreach($values as $value) {
|
||||||
|
$select .= '<option value="' . htmlspecialchars($value) . '"';
|
||||||
|
if(in_array($value, $selected_values, true)) {
|
||||||
|
$select .= ' selected="selected"';
|
||||||
|
}
|
||||||
|
$select .= '>' . $value . '</option>';
|
||||||
|
}
|
||||||
|
|
||||||
|
$select_size = (sizeof($values) > 10) ? 10 : sizeof($values);
|
||||||
|
$select = '<select multiple="multiple" size="' . $select_size . '">' . $select . '</select>';
|
||||||
|
|
||||||
|
$extra_data['select'] = $select;
|
||||||
|
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)) {
|
||||||
|
Reference in New Issue
Block a user