From 5b1ed4c32605247f6ee94c194f1065490b5f5ca1 Mon Sep 17 00:00:00 2001 From: Jakub Stanecki Date: Mon, 11 Sep 2017 03:17:45 +0200 Subject: [PATCH] Added remember table sorting when browsing table Signed-off-by: Jakub Stanecki --- js/sql.js | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/js/sql.js b/js/sql.js index d136c2c290..283a5654eb 100644 --- a/js/sql.js +++ b/js/sql.js @@ -37,7 +37,7 @@ function PMA_urlencode(str) } /** - * Saves SQL query in local storage or cooie + * Saves SQL query in local storage or cookie * * @param string SQL query * @return void @@ -53,6 +53,23 @@ function PMA_autosaveSQL(query) } } +/** + * Saves SQL query with sort in local storage or cookie + * + * @param string SQL query + * @return void + */ +function PMA_autosaveSQLSort(query) +{ + if (query) { + if (isStorageSupported('localStorage')) { + window.localStorage.auto_saved_sql_sort = query; + } else { + Cookies.set('auto_saved_sql_sort', query); + } + } +} + /** * Get the field name for the current field. Required to construct the query * for grid editing @@ -158,6 +175,15 @@ AJAX.registerOnload('sql.js', function () { $('#sqlquery').on('input propertychange', function () { PMA_autosaveSQL($('#sqlquery').val()); }); + //Save sql query with sort + $('select[name="sql_query"]').on('change', function () { + PMA_autosaveSQLSort($('select[name="sql_query"]').val()); + }); + //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'); + 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(); + } } });