diff --git a/js/functions.js b/js/functions.js index 8e844cb65c..8c858882c3 100644 --- a/js/functions.js +++ b/js/functions.js @@ -2981,8 +2981,8 @@ function PMA_createqTip($elements, content, options) { function PMA_getCellValue(td) { if ($(td).is('.null')) { return ''; - } else if ($(td).is(':not(.truncated, .transformed, .relation, .enum, .set, .null)')) { - return $(td).find('span').html().replace(/
/g, "\n"); + } else if ($(td).is(':not(.transformed, .relation, .enum, .set, .null)')) { + return unescape($(td).find('span').html()).replace(/
/g, "\n"); } else { return $(td).text(); } diff --git a/js/makegrid.js b/js/makegrid.js index 7af6ea465c..5c0af4897c 100644 --- a/js/makegrid.js +++ b/js/makegrid.js @@ -25,7 +25,10 @@ isEditCellTextEditable: false, // true if current edit cell is editable in the text input box (not textarea) currentEditCell: null, // reference to that currently being edited inEditMode: false, // true if grid is in edit mode - cellEditHint: '', // text hint when doing grid edit + cellEditHint: '', // hint shown when doing grid edit + gotoLinkText: 'Go to link', // "Go to link" text + wasEditedCellNull: false, // true if last value of the edited cell was NULL + maxTruncatedLen: 0, // number of characters that can be displayed in a cell // functions dragStartRsz: function(e, obj) { // start column resize @@ -39,7 +42,7 @@ }; $('body').css('cursor', 'col-resize'); $('body').noSelect(); - if (g.isInEditMode) { + if (g.isCellEditActive) { g.hideEditCell(); } }, @@ -73,7 +76,7 @@ this.qtip.hide(); $('body').css('cursor', 'move'); $('body').noSelect(); - if (g.isInEditMode) { + if (g.isCellEditActive) { g.hideEditCell(); } }, @@ -455,8 +458,7 @@ * Show edit cell, if it can be shown or it is forced. */ showEditCell: function(cell, force) { - if (g.isInEditMode && - $(cell).is('.inline_edit') && + if ($(cell).is('.inline_edit') && !g.colRsz && !g.colMov) { if (!g.isCellEditActive || force) { @@ -471,7 +473,7 @@ .show() .find('input') .css({ - width: $cell.outerWidth() - 16, + width: $cell.outerWidth(), height: $cell.outerHeight() }); // fill the cell edit with text from , if it is not null @@ -481,6 +483,7 @@ g.isCellEditActive = false; g.currentEditCell = cell; + $(g.cEdit).find('input[type=text]').focus(); } } else { g.hideEditCell(); @@ -537,6 +540,10 @@ } }) } + } else if ($this_field.is('.truncated')) { + if (new_html.length > g.maxTruncatedLen) { + new_html = new_html.substring(0, g.maxTruncatedLen) + '...'; + } } // replace '\n' with
new_html = new_html.replace(/\n/g, '
'); @@ -605,10 +612,24 @@ * relational display column if in 'Relational key' mode (for fields that are foreign keyed). */ var relation_key_or_display_column = $td.find('a').attr('title'); + /** + * @var curr_value String current value of the field (for fields that are of type enum or set). + */ + var curr_value = $td.find('span').text(); // empty all edit area, then rebuild it based on $td classes $editArea.empty(); + // add goto link, if this cell contains a link + if ($td.find('a').length > 0) { + var gotoLink = document.createElement('div'); + gotoLink.className = 'goto_link'; + $(gotoLink).append(g.gotoLinkText + ': ') + .append($td.find('a').clone()); + $editArea.append(gotoLink); + } + + g.wasEditedCellNull = false; if ($td.is(':not(.not_null)')) { // append a null checkbox $editArea.append('
Null :
'); @@ -616,6 +637,7 @@ // check if current is NULL if ($td.is('.null')) { $checkbox.attr('checked', true); + g.wasEditedCellNull = true; } // if the select/editor is changed un-check the 'checkbox_null__'. @@ -660,44 +682,7 @@ }) } - if($td.is('.truncated, .transformed')) { - /** @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); - - // 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) { - $(g.cEdit).find('input[type=text]').val(data.value); - $editArea.append(''); - $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('
' + g.cellEditHint + '
'); - } - else { - PMA_ajaxShowMessage(data.error); - } - }) // end $.post() - g.isEditCellTextEditable = true; - } - else if($td.is('.relation')) { + if($td.is('.relation')) { /** @lends jQuery */ //handle relations $editArea.addClass('edit_area_loading'); @@ -783,6 +768,46 @@ $editArea.find('select').live('change', function(e) { $(g.cEdit).find('input[type=text]').val($(this).val()); }) + } + else if($td.is('.truncated, .transformed')) { + /** @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); + + // 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(''); + $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('
' + g.cellEditHint + '
'); + } + else { + PMA_ajaxShowMessage(data.error); + } + }) // end $.post() + g.isEditCellTextEditable = true; } else { $editArea.append(''); $editArea.find('textarea').live('keyup', function(e) { @@ -864,8 +889,10 @@ var addQuotes = true; if (is_null) { - sql_query += ' `' + field_name + "`=NULL , "; - need_to_post = true; + if (!g.wasEditedCellNull) { + sql_query += ' `' + field_name + "`=NULL , "; + need_to_post = true; + } } else { if($this_field.is(":not(.relation, .enum, .set, .bit)")) { this_field_params[field_name] = $(g.cEdit).find('textarea').val(); @@ -900,7 +927,8 @@ if (where_clause.indexOf(field_name) > -1) { new_clause += '`' + window.parent.table + '`.' + '`' + field_name + "` = '" + this_field_params[field_name].replace(/'/g,"''") + "'" + ' AND '; } - if (this_field_params[field_name] != PMA_getCellValue(g.currentEditCell)) { + if (g.wasEditedCellNull || this_field_params[field_name] != PMA_getCellValue(g.currentEditCell)) + { if (addQuotes == true) { sql_query += ' `' + field_name + "`='" + this_field_params[field_name].replace(/'/g, "''") + "', "; } else { @@ -1151,16 +1179,6 @@ // create qtip for each with draggable class PMA_createqTip($(t).find('th.draggable')); - // enable "Edit table" button - $('.edit_mode').removeClass('hide') - .click(function(e) { - g.isInEditMode = !g.isInEditMode; - $('.edit_mode input').toggleClass('edit_mode_active', g.isInEditMode); - if (!g.isInEditMode) { - g.hideEditCell(); - } - }); - // register events if (g.reorderHint) { // make sure columns is reorderable $(t).find('th.draggable') @@ -1229,19 +1247,17 @@ }); // edit cell event $(t).find('td.data') - .mouseenter(function() { - g.showEditCell(this); - }) .click(function(e) { - if (g.isInEditMode) { - if (g.isCellEditActive) { - g.postEditedCell(); - e.stopPropagation(); - } else { - g.showEditCell(this); - $(g.cEdit).find('input[type=text]').focus(); - e.stopPropagation(); - } + if (g.isCellEditActive) { + g.postEditedCell(); + e.stopPropagation(); + } else { + g.showEditCell(this); + e.stopPropagation(); + } + // prevent default action when clicking on "link" in a table + if ($(e.target).is('a')) { + e.preventDefault(); } }); $(g.cEdit).find('input[type=text]').focus(function(e) { diff --git a/libraries/display_tbl.lib.php b/libraries/display_tbl.lib.php index 8c94c63173..70e9060780 100644 --- a/libraries/display_tbl.lib.php +++ b/libraries/display_tbl.lib.php @@ -1480,10 +1480,10 @@ function PMA_displayTableBody(&$dt_result, &$is_display, $map, $analyzed_sql) { // TEXT fields type so we have to ensure it's really a BLOB $field_flags = PMA_DBI_field_flags($dt_result, $i); - // remove 'inline_edit' from $class as we can't edit binary data. - $class = str_replace('inline_edit', '', $class); - if (stristr($field_flags, 'BINARY')) { + // remove 'inline_edit' from $class as we can't edit binary data. + $class = str_replace('inline_edit', '', $class); + if (! isset($row[$i]) || is_null($row[$i])) { $vertical_display['data'][$row_no][$i] = PMA_buildNullDisplay($class, $condition_field); } else { @@ -1512,7 +1512,11 @@ function PMA_displayTableBody(&$dt_result, &$is_display, $map, $analyzed_sql) { // characters for tabulations and / $row[$i] = ($default_function != $transform_function ? $transform_function($row[$i], $transform_options, $meta) : $default_function($row[$i], array(), $meta)); - $vertical_display['data'][$row_no][$i] = PMA_buildValueDisplay($class, $condition_field, $row[$i]); + if ($is_field_truncated) { + $class .= ' truncated'; + } + + $vertical_display['data'][$row_no][$i] = PMA_buildValueDisplay($class, $condition_field, $row[$i]); } else { $vertical_display['data'][$row_no][$i] = PMA_buildEmptyDisplay($class, $condition_field, $meta); } diff --git a/themes/original/css/theme_right.css.php b/themes/original/css/theme_right.css.php index 2a64ba84a8..bf3b2b8429 100644 --- a/themes/original/css/theme_right.css.php +++ b/themes/original/css/theme_right.css.php @@ -2465,15 +2465,15 @@ span.mysql-number { } .cEdit input[type=text] { - background: #FFF url(getImgPath(); ?>b_more.png) no-repeat right; + background: #FFF; height: 100%; margin: 0; - padding: 0 16px 0 0; + padding: 0; } .cEdit .edit_area { background: #FFF; - border: 1px solid #CCC; + border: 1px solid #999; min-width: 10em; padding: 0.3em 0.5em; } @@ -2499,3 +2499,9 @@ span.mysql-number { padding-top: 1.5em; } +.cEdit .goto_link { + background: #EEE; + color: #555; + padding: 0.2em 0.3em; +} + diff --git a/themes/pmahomme/css/theme_right.css.php b/themes/pmahomme/css/theme_right.css.php index f414034f2f..4e51172ad7 100644 --- a/themes/pmahomme/css/theme_right.css.php +++ b/themes/pmahomme/css/theme_right.css.php @@ -2905,15 +2905,15 @@ span.mysql-number { } .cEdit input[type=text] { - background: #FFF url(./themes/pmahomme/img/b_more.png) no-repeat right; + background: #FFF; height: 100%; margin: 0; - padding: 0 16px 0 0; + padding: 0; } .cEdit .edit_area { background: #FFF; - border: 1px solid #CCC; + border: 1px solid #999; min-width: 10em; padding: 0.3em 0.5em; } @@ -2938,3 +2938,9 @@ span.mysql-number { padding-top: 1.5em; } +.cEdit .goto_link { + background: #EEE; + color: #555; + padding: 0.2em 0.3em; +} +