Lock page when changes are done in the SQL editor

The CodeMirror does not update underlying textarea in all cases, so we
need to handle it directly.

Fixes #13821

Signed-off-by: Michal Čihař <michal@cihar.com>
This commit is contained in:
Michal Čihař 2017-11-28 10:19:23 +01:00
parent ca7441de6c
commit 784fbcd38f
3 changed files with 38 additions and 19 deletions

View File

@ -7,6 +7,7 @@ phpMyAdmin - ChangeLog
- issue #13436 Improve detection that MySQL server needs SSL connection
- issue #13038 Support JSON datatype on MariaDB 10.2.7 and newer
- issue #13824 Fixed constructing ALTER query with AFTER
- issue #13821 Lock page when changes are done in the SQL editor
4.7.5 (2017-10-23)
- issue #13615 Avoid problems with browsing unknown query types

View File

@ -139,28 +139,37 @@ var AJAX = {
*
* @return void
*/
lockPageHandler: function(event) {
//Don't lock on enter.
if (0 === event.charCode) {
return;
}
var lockId = $(this).data('lock-id');
if (typeof lockId === 'undefined') {
return;
}
/*
* @todo Fix Code mirror does not give correct full value (query)
* in textarea, it returns only the change in content.
*/
lockPageHandler: function (event) {
var newHash = null;
if (event.data.value == 1) {
newHash = AJAX.hash($(this).val());
var oldHash = null;
var lockId;
// CodeMirror lock
if (event.data.value === 3) {
newHash = event.data.content;
oldHash = true;
lockId = 'cm';
} else {
newHash = AJAX.hash($(this).is(":checked"));
// Don't lock on enter.
if (0 === event.charCode) {
return;
}
lockId = $(this).data('lock-id');
if (typeof lockId === 'undefined') {
return;
}
/*
* @todo Fix Code mirror does not give correct full value (query)
* in textarea, it returns only the change in content.
*/
if (event.data.value === 1) {
newHash = AJAX.hash($(this).val());
} else {
newHash = AJAX.hash($(this).is(':checked'));
}
oldHash = $(this).data('val-hash');
}
var oldHash = $(this).data('val-hash');
// Set lock if old value != new value
// Set lock if old value !== new value
// otherwise release lock
if (oldHash !== newHash) {
AJAX.lockedTargets[lockId] = true;

View File

@ -294,6 +294,15 @@ function PMA_getSQLEditor($textarea, options, resize, lintOptions) {
// enable autocomplete
codemirrorEditor.on("inputRead", codemirrorAutocompleteOnInputRead);
// page locking
codemirrorEditor.on('change', function (e) {
e.data = {
value: 3,
content: codemirrorEditor.isClean(),
};
AJAX.lockPageHandler(e);
});
return codemirrorEditor;
}
return null;