From c0613bd7e99fb0c58aad5e533df6f5994aa550df Mon Sep 17 00:00:00 2001 From: Aris Feryanto Date: Mon, 25 Jul 2011 12:29:05 +0800 Subject: [PATCH 1/7] Grid edit: remove 'edit mode' --- js/makegrid.js | 36 ++++++++++-------------------------- 1 file changed, 10 insertions(+), 26 deletions(-) diff --git a/js/makegrid.js b/js/makegrid.js index 7af6ea465c..a385681250 100644 --- a/js/makegrid.js +++ b/js/makegrid.js @@ -39,7 +39,7 @@ }; $('body').css('cursor', 'col-resize'); $('body').noSelect(); - if (g.isInEditMode) { + if (g.isCellEditActive) { g.hideEditCell(); } }, @@ -73,7 +73,7 @@ this.qtip.hide(); $('body').css('cursor', 'move'); $('body').noSelect(); - if (g.isInEditMode) { + if (g.isCellEditActive) { g.hideEditCell(); } }, @@ -455,8 +455,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) { @@ -1151,16 +1150,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 +1218,14 @@ }); // 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); + $(g.cEdit).find('input[type=text]').focus(); + e.stopPropagation(); } }); $(g.cEdit).find('input[type=text]').focus(function(e) { From 59cbf2a3f1deab9a30e5304ec929ea2a4efdad4b Mon Sep 17 00:00:00 2001 From: Aris Feryanto Date: Mon, 25 Jul 2011 14:38:57 +0800 Subject: [PATCH 2/7] Grid edit: handle clicking on a link --- js/makegrid.js | 16 +++++++++++++++- themes/original/css/theme_right.css.php | 8 +++++++- themes/pmahomme/css/theme_right.css.php | 8 +++++++- 3 files changed, 29 insertions(+), 3 deletions(-) diff --git a/js/makegrid.js b/js/makegrid.js index a385681250..ad73ba416c 100644 --- a/js/makegrid.js +++ b/js/makegrid.js @@ -25,7 +25,8 @@ 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 // functions dragStartRsz: function(e, obj) { // start column resize @@ -608,6 +609,15 @@ // 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); + } + if ($td.is(':not(.not_null)')) { // append a null checkbox $editArea.append('
Null :
'); @@ -1227,6 +1237,10 @@ $(g.cEdit).find('input[type=text]').focus(); 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) { g.showEditArea(); diff --git a/themes/original/css/theme_right.css.php b/themes/original/css/theme_right.css.php index 2a64ba84a8..b881bd421c 100644 --- a/themes/original/css/theme_right.css.php +++ b/themes/original/css/theme_right.css.php @@ -2473,7 +2473,7 @@ span.mysql-number { .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 8988d10da5..061090a01c 100644 --- a/themes/pmahomme/css/theme_right.css.php +++ b/themes/pmahomme/css/theme_right.css.php @@ -2884,7 +2884,7 @@ span.mysql-number { .cEdit .edit_area { background: #FFF; - border: 1px solid #CCC; + border: 1px solid #999; min-width: 10em; padding: 0.3em 0.5em; } @@ -2909,3 +2909,9 @@ span.mysql-number { padding-top: 1.5em; } +.cEdit .goto_link { + background: #EEE; + color: #555; + padding: 0.2em 0.3em; +} + From 37027fdce3afebc6bc4a2f21f76c04acc33f7712 Mon Sep 17 00:00:00 2001 From: Aris Feryanto Date: Mon, 25 Jul 2011 14:51:56 +0800 Subject: [PATCH 3/7] Grid edit: fix for transformed relational field --- js/makegrid.js | 76 +++++++++++++++++++++++++------------------------- 1 file changed, 38 insertions(+), 38 deletions(-) diff --git a/js/makegrid.js b/js/makegrid.js index ad73ba416c..3279070465 100644 --- a/js/makegrid.js +++ b/js/makegrid.js @@ -669,44 +669,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'); @@ -792,6 +755,43 @@ $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) { + $(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) { From 4bfa0b7e5b32a5d3a31d9162748f9bd1cc076521 Mon Sep 17 00:00:00 2001 From: Aris Feryanto Date: Mon, 25 Jul 2011 14:52:57 +0800 Subject: [PATCH 4/7] Grid edit: remove drop down arrow in text input box --- js/makegrid.js | 2 +- themes/original/css/theme_right.css.php | 4 ++-- themes/pmahomme/css/theme_right.css.php | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/js/makegrid.js b/js/makegrid.js index 3279070465..c2c994585b 100644 --- a/js/makegrid.js +++ b/js/makegrid.js @@ -471,7 +471,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 diff --git a/themes/original/css/theme_right.css.php b/themes/original/css/theme_right.css.php index b881bd421c..bf3b2b8429 100644 --- a/themes/original/css/theme_right.css.php +++ b/themes/original/css/theme_right.css.php @@ -2465,10 +2465,10 @@ 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 { diff --git a/themes/pmahomme/css/theme_right.css.php b/themes/pmahomme/css/theme_right.css.php index 061090a01c..5454f53c30 100644 --- a/themes/pmahomme/css/theme_right.css.php +++ b/themes/pmahomme/css/theme_right.css.php @@ -2876,10 +2876,10 @@ 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 { From b25ce5afa9891c0b28996b61c068477e9c9d2d3e Mon Sep 17 00:00:00 2001 From: Aris Feryanto Date: Mon, 25 Jul 2011 16:47:59 +0800 Subject: [PATCH 5/7] Grid edit: fix bug - support for SET and ENUM data type --- js/makegrid.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/js/makegrid.js b/js/makegrid.js index c2c994585b..be08354237 100644 --- a/js/makegrid.js +++ b/js/makegrid.js @@ -605,6 +605,10 @@ * 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(); From 5faaa14bd72c0a4f4db1080e3de768cccff72b6a Mon Sep 17 00:00:00 2001 From: Aris Feryanto Date: Mon, 25 Jul 2011 16:58:25 +0800 Subject: [PATCH 6/7] Grid edit: fix bug - differentiating NULL and empty string --- js/makegrid.js | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/js/makegrid.js b/js/makegrid.js index be08354237..f5bb9012fa 100644 --- a/js/makegrid.js +++ b/js/makegrid.js @@ -27,6 +27,7 @@ inEditMode: false, // true if grid is in edit mode 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 // functions dragStartRsz: function(e, obj) { // start column resize @@ -622,6 +623,7 @@ $editArea.append(gotoLink); } + g.wasEditedCellNull = false; if ($td.is(':not(.not_null)')) { // append a null checkbox $editArea.append('
Null :
'); @@ -629,6 +631,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__'. @@ -877,8 +880,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(); @@ -913,7 +918,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 { From 4c30640024e9ff159a8e24eb2ef5cd14811d3be9 Mon Sep 17 00:00:00 2001 From: Aris Feryanto Date: Mon, 25 Jul 2011 18:09:11 +0800 Subject: [PATCH 7/7] Grid edit: add truncated support for TEXT data type --- js/functions.js | 4 ++-- js/makegrid.js | 10 +++++++++- libraries/display_tbl.lib.php | 12 ++++++++---- 3 files changed, 19 insertions(+), 7 deletions(-) diff --git a/js/functions.js b/js/functions.js index 0401f5d195..9fe93d15c1 100644 --- a/js/functions.js +++ b/js/functions.js @@ -2953,8 +2953,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 f5bb9012fa..5c0af4897c 100644 --- a/js/makegrid.js +++ b/js/makegrid.js @@ -28,6 +28,7 @@ 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 @@ -482,6 +483,7 @@ g.isCellEditActive = false; g.currentEditCell = cell; + $(g.cEdit).find('input[type=text]').focus(); } } else { g.hideEditCell(); @@ -538,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, '
'); @@ -784,6 +790,9 @@ }, 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) { @@ -1244,7 +1253,6 @@ e.stopPropagation(); } else { g.showEditCell(this); - $(g.cEdit).find('input[type=text]').focus(); e.stopPropagation(); } // prevent default action when clicking on "link" in a table diff --git a/libraries/display_tbl.lib.php b/libraries/display_tbl.lib.php index 3f402ed0a6..3ed305b2cb 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); }