Merge branch 'grid' into aris
This commit is contained in:
commit
cf8f188a9e
@ -2981,6 +2981,8 @@ function PMA_createqTip($elements, content, options) {
|
||||
function PMA_getCellValue(td) {
|
||||
if ($(td).is('.null')) {
|
||||
return '';
|
||||
} else if ($(td).data('original_data')) {
|
||||
return $(td).data('original_data');
|
||||
} else if ($(td).is(':not(.transformed, .relation, .enum, .set, .null)')) {
|
||||
return unescape($(td).find('span').html()).replace(/<br>/g, "\n");
|
||||
} else {
|
||||
|
||||
189
js/makegrid.js
189
js/makegrid.js
@ -515,63 +515,45 @@
|
||||
g.isCellEditActive = false;
|
||||
|
||||
if (data) {
|
||||
$this_field = field == undefined ? $(g.currentEditCell) : $(field);
|
||||
$this_field_span = $this_field.children('span');
|
||||
|
||||
var is_null = $this_field.data('value') == null;
|
||||
if (is_null) {
|
||||
$this_field_span.html('NULL');
|
||||
$this_field.addClass('null');
|
||||
} else {
|
||||
$this_field.removeClass('null');
|
||||
/**
|
||||
* @var new_html String containing value of the data field after edit
|
||||
*/
|
||||
if (data === true) {
|
||||
// replace current edited field with the new value
|
||||
var $this_field = $(g.currentEditCell);
|
||||
var new_html = $this_field.data('value');
|
||||
|
||||
if($this_field.is(':not(.relation, .enum, .set)')) {
|
||||
if($this_field.is('.transformed')) {
|
||||
var field_name = getFieldName($this_field);
|
||||
if (typeof data.transformations != 'undefined') {
|
||||
$.each(data.transformations, function(key, value) {
|
||||
if(key == field_name) {
|
||||
if($this_field.is('.text_plain, .application_octetstream')) {
|
||||
new_html = value;
|
||||
return false;
|
||||
} else {
|
||||
var new_value = $this_field.data('value');
|
||||
new_html = $(value).append(new_value);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
} else if ($this_field.is('.truncated')) {
|
||||
var is_null = $this_field.data('value') == null;
|
||||
if (is_null) {
|
||||
$this_field_span.html('NULL');
|
||||
$this_field.addClass('null');
|
||||
} else {
|
||||
$this_field.removeClass('null');
|
||||
if ($this_field.is('.truncated')) {
|
||||
if (new_html.length > g.maxTruncatedLen) {
|
||||
new_html = new_html.substring(0, g.maxTruncatedLen) + '...';
|
||||
}
|
||||
}
|
||||
// replace '\n' with <br>
|
||||
new_html = new_html.replace(/\n/g, '<br />');
|
||||
} else {
|
||||
if($this_field.is('.relation')) {
|
||||
var field_name = getFieldName($this_field);
|
||||
if (typeof data.relations != 'undefined') {
|
||||
$.each(data.relations, function(key, value) {
|
||||
if(key == field_name) {
|
||||
new_html = $(value);
|
||||
return false;
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
$this_field_span.html(new_html);
|
||||
$this_field.find('span').html(new_html);
|
||||
} else {
|
||||
// update edited fields with new value from "data"
|
||||
if (data.transformations != undefined) {
|
||||
$.each(data.transformations, function(cell_index, value) {
|
||||
var $this_field = $(g.t).find('.to_be_saved:eq(' + cell_index + ')');
|
||||
$this_field.find('span').html(value);
|
||||
});
|
||||
}
|
||||
if (data.relations != undefined) {
|
||||
$.each(data.relations, function(cell_index, value) {
|
||||
var $this_field = $(g.t).find('.to_be_saved:eq(' + cell_index + ')');
|
||||
$this_field.find('span').html(value);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
// refresh the grid
|
||||
this.reposRsz();
|
||||
this.reposDrop();
|
||||
} // end of if "data" is defined, i.e. post successful
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
@ -756,43 +738,62 @@
|
||||
})
|
||||
}
|
||||
else if($td.is('.truncated, .transformed')) {
|
||||
/** @lends jQuery */
|
||||
//handle truncated/transformed values values
|
||||
$editArea.addClass('edit_area_loading');
|
||||
if ($td.is('.to_be_saved')) { // cell has been edited
|
||||
var value = $td.data('value');
|
||||
$(g.cEdit).find('input[type=text]').val(value);
|
||||
$editArea.append('<textarea>'+value+'</textarea>');
|
||||
$editArea.find('textarea').live('keyup', function(e) {
|
||||
$(g.cEdit).find('input[type=text]').val($(this).val());
|
||||
});
|
||||
$(g.cEdit).find('input[type=text]').live('keyup', function(e) {
|
||||
$editArea.find('textarea').val($(this).val());
|
||||
});
|
||||
$editArea.append('<div class="cell_edit_hint">' + g.cellEditHint + '</div>');
|
||||
} else {
|
||||
/** @lends jQuery */
|
||||
//handle truncated/transformed values values
|
||||
$editArea.addClass('edit_area_loading');
|
||||
|
||||
/**
|
||||
* @var sql_query String containing the SQL query used to retrieve value of truncated/transformed data
|
||||
*/
|
||||
var sql_query = 'SELECT `' + field_name + '` FROM `' + window.parent.table + '` WHERE ' + PMA_urldecode(where_clause);
|
||||
// initialize the original data
|
||||
$td.data('original_data', null);
|
||||
|
||||
// Make the Ajax call and get the data, wrap it and insert it
|
||||
$.post('sql.php', {
|
||||
'token' : window.parent.token,
|
||||
'server' : window.parent.server,
|
||||
'db' : window.parent.db,
|
||||
'ajax_request' : true,
|
||||
'sql_query' : sql_query,
|
||||
'inline_edit' : true
|
||||
}, function(data) {
|
||||
$editArea.removeClass('edit_area_loading');
|
||||
if(data.success == true) {
|
||||
// get the truncated data length
|
||||
g.maxTruncatedLen = PMA_getCellValue(g.currentEditCell).length - 3;
|
||||
|
||||
$(g.cEdit).find('input[type=text]').val(data.value);
|
||||
$editArea.append('<textarea>'+data.value+'</textarea>');
|
||||
$editArea.find('textarea').live('keyup', function(e) {
|
||||
$(g.cEdit).find('input[type=text]').val($(this).val());
|
||||
});
|
||||
$(g.cEdit).find('input[type=text]').live('keyup', function(e) {
|
||||
$editArea.find('textarea').val($(this).val());
|
||||
});
|
||||
$editArea.append('<div class="cell_edit_hint">' + g.cellEditHint + '</div>');
|
||||
}
|
||||
else {
|
||||
PMA_ajaxShowMessage(data.error);
|
||||
}
|
||||
}) // end $.post()
|
||||
/**
|
||||
* @var sql_query String containing the SQL query used to retrieve value of truncated/transformed data
|
||||
*/
|
||||
var sql_query = 'SELECT `' + field_name + '` FROM `' + window.parent.table + '` WHERE ' + PMA_urldecode(where_clause);
|
||||
|
||||
// Make the Ajax call and get the data, wrap it and insert it
|
||||
$.post('sql.php', {
|
||||
'token' : window.parent.token,
|
||||
'server' : window.parent.server,
|
||||
'db' : window.parent.db,
|
||||
'ajax_request' : true,
|
||||
'sql_query' : sql_query,
|
||||
'inline_edit' : true
|
||||
}, function(data) {
|
||||
$editArea.removeClass('edit_area_loading');
|
||||
if(data.success == true) {
|
||||
if ($td.is('.truncated')) {
|
||||
// get the truncated data length
|
||||
g.maxTruncatedLen = $(g.currentEditCell).text().length - 3;
|
||||
}
|
||||
|
||||
$td.data('original_data', data.value);
|
||||
$(g.cEdit).find('input[type=text]').val(data.value);
|
||||
$editArea.append('<textarea>'+data.value+'</textarea>');
|
||||
$editArea.find('textarea').live('keyup', function(e) {
|
||||
$(g.cEdit).find('input[type=text]').val($(this).val());
|
||||
});
|
||||
$(g.cEdit).find('input[type=text]').live('keyup', function(e) {
|
||||
$editArea.find('textarea').val($(this).val());
|
||||
});
|
||||
$editArea.append('<div class="cell_edit_hint">' + g.cellEditHint + '</div>');
|
||||
}
|
||||
else {
|
||||
PMA_ajaxShowMessage(data.error);
|
||||
}
|
||||
}) // end $.post()
|
||||
}
|
||||
g.isEditCellTextEditable = true;
|
||||
} else {
|
||||
$editArea.append('<textarea>' + PMA_getCellValue(g.currentEditCell) + '</textarea>');
|
||||
@ -896,22 +897,22 @@
|
||||
* @var is_null String capturing whether 'checkbox_null_<field_name>_<row_index>' is checked.
|
||||
*/
|
||||
var is_null = $this_field.data('value') == null;
|
||||
var value;
|
||||
var addQuotes = true;
|
||||
|
||||
fields_name.push(field_name);
|
||||
fields.push($this_field.data('value'));
|
||||
|
||||
|
||||
if (!is_null) {
|
||||
this_field_params[field_name] = $this_field.data('value');
|
||||
|
||||
var cell_index = $this_field.index('.to_be_saved');
|
||||
if($this_field.is(":not(.relation, .enum, .set, .bit)")) {
|
||||
if($this_field.is('.transformed')) {
|
||||
$.extend(transform_fields, this_field_params);
|
||||
transform_fields[cell_index] = {};
|
||||
$.extend(transform_fields[cell_index], this_field_params);
|
||||
}
|
||||
} else if ($this_field.is('.bit')) {
|
||||
addQuotes = false;
|
||||
} else if($this_field.is('.relation')) {
|
||||
$.extend(relation_fields, this_field_params);
|
||||
relation_fields[cell_index] = {};
|
||||
$.extend(relation_fields[cell_index], this_field_params);
|
||||
}
|
||||
if (where_clause.indexOf(field_name) > -1) {
|
||||
new_clause += '`' + window.parent.table + '`.' + '`' + field_name + "` = '" + this_field_params[field_name].replace(/'/g,"''") + "'" + ' AND ';
|
||||
@ -926,10 +927,6 @@
|
||||
new_clause = new_clause.substring(0, new_clause.length-5);
|
||||
new_clause = PMA_urlencode(new_clause);
|
||||
$this_field.parent('tr').data('new_clause', new_clause);
|
||||
|
||||
rel_fields_list += $.param(relation_fields) + '&';
|
||||
transform_fields_list += $.param(transform_fields) + '&';
|
||||
|
||||
}); // end of loop for every edited cells in a row
|
||||
|
||||
me_fields_name.push(fields_name);
|
||||
@ -937,6 +934,9 @@
|
||||
|
||||
}); // end of loop for every edited rows
|
||||
|
||||
rel_fields_list = $.param(relation_fields);
|
||||
transform_fields_list = $.param(transform_fields);
|
||||
|
||||
// Make the Ajax post after setting all parameters
|
||||
/**
|
||||
* @var post_params Object containing parameters for the POST request
|
||||
@ -988,8 +988,11 @@
|
||||
|
||||
// remove the "Save edited cells" button
|
||||
$('.save_edited').hide();
|
||||
// remove the to_be_saved class
|
||||
$('.to_be_saved').removeClass('to_be_saved');
|
||||
// update saved fields
|
||||
$(g.t).find('.to_be_saved')
|
||||
.removeClass('to_be_saved')
|
||||
.data('value', null)
|
||||
.data('original_data', null);
|
||||
|
||||
g.isCellEdited = false;
|
||||
} else {
|
||||
|
||||
121
tbl_replace.php
121
tbl_replace.php
@ -405,6 +405,127 @@ if (! empty($error_messages)) {
|
||||
unset($error_messages, $warning_messages, $total_affected_rows, $last_messages, $last_message);
|
||||
|
||||
if ($GLOBALS['is_ajax_request'] == true) {
|
||||
/**
|
||||
* If we are in grid editing, we need to process the relational and
|
||||
* transformed fields, if they were edited. After that, output the correct
|
||||
* link/transformed value and exit
|
||||
*
|
||||
* Logic taken from libraries/display_tbl.lib.php
|
||||
*/
|
||||
|
||||
if (isset($_REQUEST['rel_fields_list']) && $_REQUEST['rel_fields_list'] != '') {
|
||||
//handle relations work here for updated row.
|
||||
require_once './libraries/relation.lib.php';
|
||||
|
||||
$map = PMA_getForeigners($db, $table, '', 'both');
|
||||
|
||||
$rel_fields = array();
|
||||
parse_str($_REQUEST['rel_fields_list'], $rel_fields);
|
||||
|
||||
// loop for each relation cell
|
||||
foreach ( $rel_fields as $cell_index => $curr_cell_rel_field) {
|
||||
|
||||
foreach ( $curr_cell_rel_field as $rel_field => $rel_field_value) {
|
||||
|
||||
$where_comparison = "='" . $rel_field_value . "'";
|
||||
$display_field = PMA_getDisplayField($map[$rel_field]['foreign_db'], $map[$rel_field]['foreign_table']);
|
||||
|
||||
// Field to display from the foreign table?
|
||||
if (isset($display_field) && strlen($display_field)) {
|
||||
$dispsql = 'SELECT ' . PMA_backquote($display_field)
|
||||
. ' FROM ' . PMA_backquote($map[$rel_field]['foreign_db'])
|
||||
. '.' . PMA_backquote($map[$rel_field]['foreign_table'])
|
||||
. ' WHERE ' . PMA_backquote($map[$rel_field]['foreign_field'])
|
||||
. $where_comparison;
|
||||
$dispresult = PMA_DBI_try_query($dispsql, null, PMA_DBI_QUERY_STORE);
|
||||
if ($dispresult && PMA_DBI_num_rows($dispresult) > 0) {
|
||||
list($dispval) = PMA_DBI_fetch_row($dispresult, 0);
|
||||
} else {
|
||||
//$dispval = __('Link not found');
|
||||
}
|
||||
@PMA_DBI_free_result($dispresult);
|
||||
} else {
|
||||
$dispval = '';
|
||||
} // end if... else...
|
||||
|
||||
if ('K' == $_SESSION['tmp_user_values']['relational_display']) {
|
||||
// user chose "relational key" in the display options, so
|
||||
// the title contains the display field
|
||||
$title = (! empty($dispval))? ' title="' . htmlspecialchars($dispval) . '"' : '';
|
||||
} else {
|
||||
$title = ' title="' . htmlspecialchars($rel_field_value) . '"';
|
||||
}
|
||||
|
||||
$_url_params = array(
|
||||
'db' => $map[$rel_field]['foreign_db'],
|
||||
'table' => $map[$rel_field]['foreign_table'],
|
||||
'pos' => '0',
|
||||
'sql_query' => 'SELECT * FROM '
|
||||
. PMA_backquote($map[$rel_field]['foreign_db']) . '.' . PMA_backquote($map[$rel_field]['foreign_table'])
|
||||
. ' WHERE ' . PMA_backquote($map[$rel_field]['foreign_field'])
|
||||
. $where_comparison
|
||||
);
|
||||
$output = '<a href="sql.php' . PMA_generate_common_url($_url_params) . '"' . $title . '>';
|
||||
|
||||
if ('D' == $_SESSION['tmp_user_values']['relational_display']) {
|
||||
// user chose "relational display field" in the
|
||||
// display options, so show display field in the cell
|
||||
$output .= (!empty($dispval)) ? htmlspecialchars($dispval) : '';
|
||||
} else {
|
||||
// otherwise display data in the cell
|
||||
$output .= htmlspecialchars($rel_field_value);
|
||||
}
|
||||
$output .= '</a>';
|
||||
$extra_data['relations'][$cell_index] = $output;
|
||||
}
|
||||
} // end of loop for each relation cell
|
||||
}
|
||||
|
||||
if (isset($_REQUEST['do_transformations']) && $_REQUEST['do_transformations'] == true ) {
|
||||
require_once './libraries/transformations.lib.php';
|
||||
//if some posted fields need to be transformed, generate them here.
|
||||
$mime_map = PMA_getMIME($db, $table);
|
||||
|
||||
if ($mime_map === false) {
|
||||
$mime_map = array();
|
||||
}
|
||||
|
||||
$edited_values = array();
|
||||
parse_str($_REQUEST['transform_fields_list'], $edited_values);
|
||||
|
||||
foreach($mime_map as $transformation) {
|
||||
$include_file = PMA_securePath($transformation['transformation']);
|
||||
$column_name = $transformation['column_name'];
|
||||
|
||||
foreach ($edited_values as $cell_index => $curr_cell_edited_values) {
|
||||
if (isset($curr_cell_edited_values[$column_name])) {
|
||||
$column_data = $curr_cell_edited_values[$column_name];
|
||||
|
||||
$_url_params = array(
|
||||
'db' => $db,
|
||||
'table' => $table,
|
||||
'where_clause' => $_REQUEST['where_clause'],
|
||||
'transform_key' => $column_name,
|
||||
);
|
||||
|
||||
if (file_exists('./libraries/transformations/' . $include_file)) {
|
||||
$transformfunction_name = str_replace('.inc.php', '', $transformation['transformation']);
|
||||
|
||||
require_once './libraries/transformations/' . $include_file;
|
||||
|
||||
if (function_exists('PMA_transformation_' . $transformfunction_name)) {
|
||||
$transform_function = 'PMA_transformation_' . $transformfunction_name;
|
||||
$transform_options = PMA_transformation_getOptions((isset($transformation['transformation_options']) ? $transformation['transformation_options'] : ''));
|
||||
$transform_options['wrapper_link'] = PMA_generate_common_url($_url_params);
|
||||
}
|
||||
}
|
||||
|
||||
$extra_data['transformations'][$cell_index] = $transform_function($column_data, $transform_options);
|
||||
}
|
||||
} // end of loop for each transformation cell
|
||||
} // end of loop for each $mime_map
|
||||
}
|
||||
|
||||
/**Get the total row count of the table*/
|
||||
$extra_data['row_count'] = PMA_Table::countRecords($_REQUEST['db'],$_REQUEST['table']);
|
||||
$extra_data['sql_query'] = PMA_showMessage(NULL, $GLOBALS['display_query']);
|
||||
|
||||
Loading…
Reference in New Issue
Block a user