Bug #3185756 [AJAX] Inline edit and NULL columns
This commit is contained in:
254
js/sql.js
254
js/sql.js
@@ -425,14 +425,45 @@ $(document).ready(function() {
|
|||||||
* @see getFieldName()
|
* @see getFieldName()
|
||||||
*/
|
*/
|
||||||
var field_name = getFieldName($this_field, disp_mode);
|
var field_name = getFieldName($this_field, disp_mode);
|
||||||
|
/**
|
||||||
|
* @var relation_curr_value String current value of the field (for fields that are foreign keyed).
|
||||||
|
*/
|
||||||
|
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 enum_curr_value = $this_field.text();
|
||||||
|
|
||||||
|
if($this_field.is(':not(.not_null)')){
|
||||||
|
// add a checkbox to mark null for all the field that are nullable.
|
||||||
|
$this_field.html('<div>Null :<input type="checkbox" class="checkbox_null_'+ field_name +'"></div>');
|
||||||
|
// check the 'checkbox_null_<field_name>' if the value is null
|
||||||
|
if($this_field.is('.null')) {
|
||||||
|
$('.checkbox_null_' + field_name).attr('checked', true);
|
||||||
|
}
|
||||||
|
|
||||||
|
// if 'chechbox_null_<field_name>' is clicked empty the select/editor.
|
||||||
|
$('.checkbox_null_' + field_name).bind('click', function(e) {
|
||||||
|
if ($this_field.is('.enum, .set')) {
|
||||||
|
$this_field.find('select').selectedIndex = -1;
|
||||||
|
} else if ($this_field.is('.relation')) {
|
||||||
|
$this_field.find('select').attr('value', '');
|
||||||
|
} else {
|
||||||
|
$this_field.find('textarea').empty();
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
} else {
|
||||||
|
$this_field.html('');
|
||||||
|
}
|
||||||
|
|
||||||
// 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, .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.html('<textarea>'+data_value+'</textarea>')
|
$this_field.append('<textarea>'+data_value+'</textarea>');
|
||||||
.append('<span class="original_data">'+data_value+'</span>');
|
$this_field.append('<span class="original_data">'+data_value+'</span>');
|
||||||
$(".original_data").hide();
|
$(".original_data").hide();
|
||||||
}
|
}
|
||||||
else if($this_field.is('.truncated, .transformed')) {
|
else if($this_field.is('.truncated, .transformed')) {
|
||||||
@@ -453,8 +484,8 @@ $(document).ready(function() {
|
|||||||
'inline_edit' : true
|
'inline_edit' : true
|
||||||
}, function(data) {
|
}, function(data) {
|
||||||
if(data.success == true) {
|
if(data.success == true) {
|
||||||
$this_field.html('<textarea>'+data.value+'</textarea>')
|
$this_field.append('<textarea>'+data.value+'</textarea>');
|
||||||
.append('<span class="original_data">'+data_value+'</span>');
|
$this_field.append('<span class="original_data">'+data_value+'</span>');
|
||||||
$(".original_data").hide();
|
$(".original_data").hide();
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
@@ -466,11 +497,6 @@ $(document).ready(function() {
|
|||||||
/** @lends jQuery */
|
/** @lends jQuery */
|
||||||
//handle relations
|
//handle relations
|
||||||
|
|
||||||
/**
|
|
||||||
* @var curr_value String containing the current value of this relational field
|
|
||||||
*/
|
|
||||||
var curr_value = $this_field.find('a').text();
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var post_params Object containing parameters for the POST request
|
* @var post_params Object containing parameters for the POST request
|
||||||
*/
|
*/
|
||||||
@@ -481,22 +507,18 @@ $(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' : curr_value
|
'curr_value' : relation_curr_value
|
||||||
}
|
}
|
||||||
|
|
||||||
$.post('sql.php', post_params, function(data) {
|
$.post('sql.php', post_params, function(data) {
|
||||||
$this_field.html(data.dropdown)
|
$this_field.append(data.dropdown);
|
||||||
.append('<span class="original_data">'+data_value+'</span>');
|
$this_field.append('<span class="original_data">'+data_value+'</span>');
|
||||||
$(".original_data").hide();
|
$(".original_data").hide();
|
||||||
}) // end $.post()
|
}) // end $.post()
|
||||||
}
|
}
|
||||||
else if($this_field.is('.enum')) {
|
else if($this_field.is('.enum')) {
|
||||||
/** @lends jQuery */
|
/** @lends jQuery */
|
||||||
//handle enum fields
|
//handle enum fields
|
||||||
/**
|
|
||||||
* @var curr_value String containing the current value of this relational field
|
|
||||||
*/
|
|
||||||
var curr_value = $this_field.text();
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var post_params Object containing parameters for the POST request
|
* @var post_params Object containing parameters for the POST request
|
||||||
@@ -508,19 +530,19 @@ $(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' : curr_value
|
'curr_value' : enum_curr_value
|
||||||
}
|
}
|
||||||
|
|
||||||
$.post('sql.php', post_params, function(data) {
|
$.post('sql.php', post_params, function(data) {
|
||||||
$this_field.html(data.dropdown)
|
$this_field.append(data.dropdown);
|
||||||
.append('<span class="original_data">'+data_value+'</span>');
|
$this_field.append('<span class="original_data">'+data_value+'</span>');
|
||||||
$(".original_data").hide();
|
$(".original_data").hide();
|
||||||
}) // end $.post()
|
}) // end $.post()
|
||||||
}
|
}
|
||||||
else if($this_field.is('.null')) {
|
else if($this_field.is('.null')) {
|
||||||
//handle null fields
|
//handle null fields
|
||||||
$this_field.html('<textarea></textarea>')
|
$this_field.append('<textarea></textarea>');
|
||||||
.append('<span class="original_data">NULL</span>');
|
$this_field.append('<span class="original_data">NULL</span>');
|
||||||
$(".original_data").hide();
|
$(".original_data").hide();
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
@@ -580,10 +602,6 @@ $(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 Array containing the name/value pairs of all fields
|
|
||||||
*/
|
|
||||||
var params_to_submit = {};
|
|
||||||
/**
|
/**
|
||||||
* @var relation_fields Array containing the name/value pairs of relational fields
|
* @var relation_fields Array containing the name/value pairs of relational fields
|
||||||
*/
|
*/
|
||||||
@@ -597,6 +615,11 @@ $(document).ready(function() {
|
|||||||
*/
|
*/
|
||||||
var transformation_fields = false;
|
var transformation_fields = false;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var sql_query String containing the SQL query to update this row
|
||||||
|
*/
|
||||||
|
var sql_query = 'UPDATE ' + window.parent.table + ' SET ';
|
||||||
|
|
||||||
$input_siblings.each(function() {
|
$input_siblings.each(function() {
|
||||||
/** @lends jQuery */
|
/** @lends jQuery */
|
||||||
/**
|
/**
|
||||||
@@ -617,50 +640,43 @@ $(document).ready(function() {
|
|||||||
if($this_field.is('.transformed')) {
|
if($this_field.is('.transformed')) {
|
||||||
transformation_fields = true;
|
transformation_fields = true;
|
||||||
}
|
}
|
||||||
|
/**
|
||||||
|
* @var is_null String capturing whether 'checkbox_null_<field_name>' is checked.
|
||||||
|
*/
|
||||||
|
var is_null = $this_field.find('input:checkbox').is(':checked');
|
||||||
|
var value;
|
||||||
|
|
||||||
if($this_field.is(":not(.relation, .enum)")) {
|
if (is_null) {
|
||||||
this_field_params[field_name] = $this_field.find('textarea').val();
|
sql_query += ' ' + field_name + "=NULL , ";
|
||||||
if($this_field.is('.transformed')) {
|
} else {
|
||||||
$.extend(transform_fields, this_field_params);
|
if($this_field.is(":not(.relation, .enum)")) {
|
||||||
}
|
this_field_params[field_name] = $this_field.find('textarea').val();
|
||||||
|
if($this_field.is('.transformed')) {
|
||||||
|
$.extend(transform_fields, this_field_params);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
// results from a drop-down
|
||||||
|
$test_element = $this_field.find('select');
|
||||||
|
if ($test_element.length != 0) {
|
||||||
|
this_field_params[field_name] = $test_element.val();
|
||||||
|
}
|
||||||
|
|
||||||
|
// results from Browse foreign value
|
||||||
|
$test_element = $this_field.find('span.curr_value');
|
||||||
|
if ($test_element.length != 0) {
|
||||||
|
this_field_params[field_name] = $test_element.text();
|
||||||
|
}
|
||||||
|
|
||||||
|
if($this_field.is('.relation')) {
|
||||||
|
$.extend(relation_fields, this_field_params);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
sql_query += ' ' + field_name + "='" + this_field_params[field_name].replace(/'/g, "''") + "' , ";
|
||||||
}
|
}
|
||||||
else {
|
|
||||||
// results from a drop-down
|
|
||||||
$test_element = $this_field.find('select');
|
|
||||||
if ($test_element.length != 0) {
|
|
||||||
this_field_params[field_name] = $test_element.val();
|
|
||||||
}
|
|
||||||
|
|
||||||
// results from Browse foreign value
|
|
||||||
$test_element = $this_field.find('span.curr_value');
|
|
||||||
if ($test_element.length != 0) {
|
|
||||||
this_field_params[field_name] = $test_element.text();
|
|
||||||
}
|
|
||||||
|
|
||||||
if($this_field.is('.relation')) {
|
|
||||||
$.extend(relation_fields, this_field_params);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
$.extend(params_to_submit, this_field_params);
|
|
||||||
})
|
})
|
||||||
|
|
||||||
/**
|
|
||||||
* @var sql_query String containing the SQL query to update this row
|
|
||||||
*/
|
|
||||||
var sql_query = 'UPDATE ' + window.parent.table + ' SET ';
|
|
||||||
|
|
||||||
// $.each() not used here since it cause problems when there is a column
|
|
||||||
// in the table with the name 'length'. See bug #3184827
|
|
||||||
var value;
|
|
||||||
for (var key in params_to_submit) {
|
|
||||||
value = params_to_submit[key];
|
|
||||||
if (value.length == 0) {
|
|
||||||
sql_query += ' ' + key + "=NULL, ";
|
|
||||||
} else {
|
|
||||||
sql_query += ' ' + key + "='" + value.replace(/'/g, "''") + "' , ";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
//Remove the last ',' appended in the above loop
|
//Remove the last ',' appended in the above loop
|
||||||
sql_query = sql_query.replace(/,\s$/, '');
|
sql_query = sql_query.replace(/,\s$/, '');
|
||||||
sql_query += ' WHERE ' + PMA_urldecode(where_clause);
|
sql_query += ' WHERE ' + PMA_urldecode(where_clause);
|
||||||
@@ -702,57 +718,65 @@ $(document).ready(function() {
|
|||||||
$input_siblings.each(function() {
|
$input_siblings.each(function() {
|
||||||
// Inline edit post has been successful.
|
// Inline edit post has been successful.
|
||||||
$this_sibling = $(this);
|
$this_sibling = $(this);
|
||||||
if($this_sibling.is(':not(.relation, .enum)')) {
|
|
||||||
/**
|
var is_null = $this_sibling.find('input:checkbox').is(':checked');
|
||||||
* @var new_html String containing value of the data field after edit
|
if (is_null) {
|
||||||
*/
|
$this_sibling.html('NULL');
|
||||||
var new_html = $this_sibling.find('textarea').val();
|
$this_sibling.addClass('null');
|
||||||
|
} else {
|
||||||
if($this_sibling.is('.transformed')) {
|
$this_sibling.removeClass('null');
|
||||||
var field_name = getFieldName($this_sibling, disp_mode);
|
if($this_sibling.is(':not(.relation, .enum)')) {
|
||||||
$.each(data.transformations, function(key, value) {
|
/**
|
||||||
if(key == field_name) {
|
* @var new_html String containing value of the data field after edit
|
||||||
if($this_sibling.is('.text_plain, .application_octetstream')) {
|
*/
|
||||||
new_html = value;
|
var new_html = $this_sibling.find('textarea').val();
|
||||||
return false;
|
|
||||||
}
|
if($this_sibling.is('.transformed')) {
|
||||||
else {
|
var field_name = getFieldName($this_sibling, disp_mode);
|
||||||
var new_value = $this_sibling.find('textarea').val();
|
$.each(data.transformations, function(key, value) {
|
||||||
new_html = $(value).append(new_value);
|
if(key == field_name) {
|
||||||
return false;
|
if($this_sibling.is('.text_plain, .application_octetstream')) {
|
||||||
}
|
new_html = value;
|
||||||
}
|
return false;
|
||||||
})
|
}
|
||||||
}
|
else {
|
||||||
|
var new_value = $this_sibling.find('textarea').val();
|
||||||
|
new_html = $(value).append(new_value);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
var new_html = '';
|
||||||
|
var new_value = '';
|
||||||
|
$test_element = $this_sibling.find('select');
|
||||||
|
if ($test_element.length != 0) {
|
||||||
|
new_value = $test_element.val();
|
||||||
|
}
|
||||||
|
|
||||||
|
$test_element = $this_sibling.find('span.curr_value');
|
||||||
|
if ($test_element.length != 0) {
|
||||||
|
new_value = $test_element.text();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
if($this_sibling.is('.relation')) {
|
||||||
|
var field_name = getFieldName($this_sibling, disp_mode);
|
||||||
|
$.each(data.relations, function(key, value) {
|
||||||
|
if(key == field_name) {
|
||||||
|
new_html = $(value).append(new_value);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
if($this_sibling.is('.enum')) {
|
||||||
|
new_html = new_value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$this_sibling.html(new_html);
|
||||||
}
|
}
|
||||||
else {
|
|
||||||
var new_html = '';
|
|
||||||
var new_value = '';
|
|
||||||
$test_element = $this_sibling.find('select');
|
|
||||||
if ($test_element.length != 0) {
|
|
||||||
new_value = $test_element.val();
|
|
||||||
}
|
|
||||||
|
|
||||||
$test_element = $this_sibling.find('span.curr_value');
|
|
||||||
if ($test_element.length != 0) {
|
|
||||||
new_value = $test_element.text();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
if($this_sibling.is('.relation')) {
|
|
||||||
var field_name = getFieldName($this_sibling, disp_mode);
|
|
||||||
$.each(data.relations, function(key, value) {
|
|
||||||
if(key == field_name) {
|
|
||||||
new_html = $(value).append(new_value);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
if($this_sibling.is('.enum')) {
|
|
||||||
new_html = new_value;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
$this_sibling.html(new_html);
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
@@ -1234,11 +1234,12 @@ function PMA_displayTableBody(&$dt_result, &$is_display, $map, $analyzed_sql) {
|
|||||||
// 2. Displays the rows' values
|
// 2. Displays the rows' values
|
||||||
for ($i = 0; $i < $fields_cnt; ++$i) {
|
for ($i = 0; $i < $fields_cnt; ++$i) {
|
||||||
$meta = $fields_meta[$i];
|
$meta = $fields_meta[$i];
|
||||||
|
$not_null_class = $meta->not_null ? 'not_null' : '';
|
||||||
$pointer = $i;
|
$pointer = $i;
|
||||||
$is_field_truncated = false;
|
$is_field_truncated = false;
|
||||||
//If the previous column had blob data, we need to reset the class
|
//If the previous column had blob data, we need to reset the class
|
||||||
// to $inline_edit_class
|
// to $inline_edit_class
|
||||||
$class = 'data ' . $inline_edit_class . ' ' . $alternating_color_class;
|
$class = 'data ' . $inline_edit_class . ' ' . $not_null_class . ' ' . $alternating_color_class;
|
||||||
|
|
||||||
// See if this column should get highlight because it's used in the
|
// See if this column should get highlight because it's used in the
|
||||||
// where-query.
|
// where-query.
|
||||||
|
Reference in New Issue
Block a user