From 0ac7e8f0f6719e2a474e8fa086ad9d90ea20b4aa Mon Sep 17 00:00:00 2001 From: Tapan Halani Date: Wed, 11 Mar 2015 23:57:46 +0530 Subject: [PATCH] Fix feature#1609: Lock page navigation when entering data. Signed-off-by: Tapan Halani --- js/ajax.js | 41 +++++++++++++++++++++----- libraries/DBQbe.class.php | 4 +-- libraries/DbSearch.class.php | 2 +- libraries/TableSearch.class.php | 2 +- libraries/display_create_table.lib.php | 2 +- test/classes/PMA_DbSearch_test.php | 2 +- 6 files changed, 40 insertions(+), 13 deletions(-) diff --git a/js/ajax.js b/js/ajax.js index 93f9bee761..f1fc9cbd4d 100644 --- a/js/ajax.js +++ b/js/ajax.js @@ -153,7 +153,11 @@ var AJAX = { * @todo Fix Code mirror does not give correct full value (query) * in textarea, it returns only the change in content. */ - var newHash = AJAX.hash($(this).val()); + if (event.data.value == 1) { + var newHash = AJAX.hash($(this).val()); + } else { + var newHash = AJAX.hash($(this).is(":checked")); + } var oldHash = $(this).data('val-hash'); // Set lock if old value != new value // otherwise release lock @@ -432,16 +436,25 @@ var AJAX = { } AJAX._callback = function () {}; }); - // initializes all lock-page elements lock-id and - // val-hash data property + // initializes lock-page elements (textarea, input types text and number, + // and select) lock-id and val-hash data property $('#page_content form.lock-page textarea, ' + - '#page_content form.lock-page input[type="text"]').each(function(i){ + '#page_content form.lock-page input[type="text"], '+ + '#page_content form.lock-page input[type="number"], '+ + '#page_content form.lock-page select').each(function(i){ $(this).data('lock-id', i); // val-hash is the hash of default value of the field // so that it can be compared with new value hash // to check whether field was modified or not. $(this).data('val-hash', AJAX.hash($(this).val())); }); + // initializes lock-page elements (input types checkbox and radio buttons) + // lock-id and val-hash data property + $('#page_content form.lock-page input[type="checkbox"], ' + + '#page_content form.lock-page input[type="radio"]').each(function(i){ + $(this).data('lock-id', i); + $(this).data('val-hash', AJAX.hash($(this).is(":checked"))); + }); } else { PMA_ajaxShowMessage(data.error, false); AJAX.active = false; @@ -606,12 +619,22 @@ AJAX.registerOnload('functions.js', function () { }); /** * Attach event listener to events when user modify visible - * Input or Textarea fields to make changes in forms + * Input,Textarea and select fields to make changes in forms */ $('#page_content').on( 'keyup change', 'form.lock-page textarea, ' + - 'form.lock-page input[type="text"]', + 'form.lock-page input[type="text"], ' + + 'form.lock-page input[type="number"], ' + + 'form.lock-page select', + {value:1}, + AJAX.lockPageHandler + ); + $('#page_content').on( + 'change', + 'form.lock-page input[type="checkbox"], ' + + 'form.lock-page input[type="radio"]', + {value:2}, AJAX.lockPageHandler ); /** @@ -630,7 +653,11 @@ AJAX.registerOnload('functions.js', function () { AJAX.registerTeardown('functions.js', function () { $('#page_content').off('keyup change', 'form.lock-page textarea, ' + - 'form.lock-page input[type="text"]' + 'form.lock-page input[type="text"], ' + + 'form.lock-page input[type="number"], ' + + 'form.lock-page select, ' + + 'form.lock-page input[type="checkbox"], ' + + 'form.lock-page input[type="radio"]' ); $('form.lock-page').off('reset'); }); diff --git a/libraries/DBQbe.class.php b/libraries/DBQbe.class.php index 0832579e6a..5412615aeb 100644 --- a/libraries/DBQbe.class.php +++ b/libraries/DBQbe.class.php @@ -1429,7 +1429,7 @@ class PMA_DbQbe */ public function getSelectionForm($cfgRelation) { - $html_output = '
'; + $html_output = ''; $html_output .= '
'; if ($GLOBALS['cfgRelation']['savedsearcheswork']) { @@ -1457,7 +1457,7 @@ class PMA_DbQbe // get tables select list $html_output .= $this->_getTablesList(); $html_output .= ''; - $html_output .= '
'; + $html_output .= ''; $html_output .= PMA_URL_getHiddenInputs(array('db' => $this->_db)); // get SQL query $html_output .= '
'; diff --git a/libraries/DbSearch.class.php b/libraries/DbSearch.class.php index 30e30d2a66..ab62901426 100644 --- a/libraries/DbSearch.class.php +++ b/libraries/DbSearch.class.php @@ -380,7 +380,7 @@ class PMA_DbSearch { $html_output = ''; $html_output .= ''; $html_output .= PMA_URL_getHiddenInputs($GLOBALS['db']); $html_output .= '
'; diff --git a/libraries/TableSearch.class.php b/libraries/TableSearch.class.php index ca5f13dba4..578008c605 100644 --- a/libraries/TableSearch.class.php +++ b/libraries/TableSearch.class.php @@ -1152,7 +1152,7 @@ class PMA_TableSearch $html_output .= ''; + . 'class="ajax lock-page"' . '>'; $html_output .= PMA_URL_getHiddenInputs($this->_db, $this->_table); $html_output .= ''; diff --git a/libraries/display_create_table.lib.php b/libraries/display_create_table.lib.php index ad5e3c69a4..39bbfe19c5 100644 --- a/libraries/display_create_table.lib.php +++ b/libraries/display_create_table.lib.php @@ -45,7 +45,7 @@ $is_create_table_priv = true; function PMA_getHtmlForCreateTable($db) { $html = ''; + . 'action="tbl_create.php" class="lock-page">'; $html .= '
'; $html .= ''; diff --git a/test/classes/PMA_DbSearch_test.php b/test/classes/PMA_DbSearch_test.php index d9cd47ff6c..fa4f42f673 100644 --- a/test/classes/PMA_DbSearch_test.php +++ b/test/classes/PMA_DbSearch_test.php @@ -201,7 +201,7 @@ class PMA_DbSearch_Test extends PHPUnit_Framework_TestCase $_SESSION['PMA_Theme'] = new PMA_Theme(); $GLOBALS['pmaThemeImage'] = 'themes/dot.gif'; $this->assertEquals( - '' . '' . ''