diff options
author | William Desportes <williamdes@wdes.fr> | 2019-10-31 01:23:07 +0300 |
---|---|---|
committer | William Desportes <williamdes@wdes.fr> | 2019-10-31 01:27:17 +0300 |
commit | 3ad6f48ad37aa410326f2ccc8b726cf51aab20ca (patch) | |
tree | 82bd693fbc77025f370d78893d02d0c6574db9df /js | |
parent | 1a67c192df7ed86d27e91e657b6ee995a63622fc (diff) |
Fix Sort By Key issue #15475
Fixes: #15475
Co-authored-by: Vitalii Medvediev <vitaliim@onehourtranslation.com>
Signed-off-by: William Desportes <williamdes@wdes.fr>
Signed-off-by: Vitalii Medvediev <vitaliim@onehourtranslation.com>
Diffstat (limited to 'js')
-rw-r--r-- | js/sql.js | 27 |
1 files changed, 20 insertions, 7 deletions
@@ -67,6 +67,19 @@ function PMA_autosaveSQLSort (query) { } /** + * Clear saved SQL query with sort in local storage or cookie + * + * @return void + */ +function PMA_clearAutoSavedSQLSort () { + if (isStorageSupported('localStorage')) { + window.localStorage.removeItem('auto_saved_sql_sort'); + } else { + Cookies.set('auto_saved_sql_sort', ''); + } +} + +/** * Get the field name for the current field. Required to construct the query * for grid editing * @@ -168,20 +181,20 @@ AJAX.registerOnload('sql.js', function () { $('#sqlquery').on('input propertychange', function () { PMA_autosaveSQL($('#sqlquery').val()); }); + var useLocalStorageValue = isStorageSupported('localStorage') && typeof window.localStorage.auto_saved_sql_sort !== 'undefined'; // Save sql query with sort if ($('#RememberSorting') !== undefined && $('#RememberSorting').is(':checked')) { $('select[name="sql_query"]').on('change', function () { - PMA_autosaveSQLSort($('select[name="sql_query"]').val()); + PMA_autosaveSQLSort($(this).val()); + }); + $('.sortlink').on('click', function () { + PMA_clearAutoSavedSQLSort(); }); } else { - if (isStorageSupported('localStorage') && window.localStorage.auto_saved_sql_sort !== undefined) { - window.localStorage.removeItem('auto_saved_sql_sort'); - } else { - Cookies.set('auto_saved_sql_sort', ''); - } + PMA_clearAutoSavedSQLSort(); } // If sql query with sort for current table is stored, change sort by key select value - var sortStoredQuery = (isStorageSupported('localStorage') && typeof window.localStorage.auto_saved_sql_sort !== 'undefined') ? window.localStorage.auto_saved_sql_sort : Cookies.get('auto_saved_sql_sort'); + var sortStoredQuery = useLocalStorageValue ? window.localStorage.auto_saved_sql_sort : Cookies.get('auto_saved_sql_sort'); if (typeof sortStoredQuery !== 'undefined' && sortStoredQuery !== $('select[name="sql_query"]').val() && $('select[name="sql_query"] option[value="' + sortStoredQuery + '"]').length !== 0) { $('select[name="sql_query"]').val(sortStoredQuery).change(); } |