diff --git a/ChangeLog b/ChangeLog index 340602b1ab..806b98a0f9 100644 --- a/ChangeLog +++ b/ChangeLog @@ -24,6 +24,8 @@ phpMyAdmin - ChangeLog + rfe #1488 User privilege tab not shown in all relevant cases + rfe #781 Privileges for non superuser + rfe #908 Improvements for the table editor (index creation) ++ rfe #1426 Navigation state lost on reload +- bug #4439 Table list in left panel doesn't expand 4.2.7.0 (not yet released) - bug Broken links on home page diff --git a/js/functions.js b/js/functions.js index a2cdae11cb..7b8afbad59 100644 --- a/js/functions.js +++ b/js/functions.js @@ -4482,3 +4482,26 @@ function PMA_ignorePhpErrors(clearPrevErrors){ $('#pma_errors').fadeOut( "slow"); $('#pma_errors').remove(); } + +/** + * checks whether browser supports web storage + * + * @param type the type of storage i.e. localStorage or sessionStorage + * + * @returns bool + */ +function isStorageSupported(type) +{ + try { + window[type].setItem('PMATest', 'test'); + // Check whether key-value pair was set successfully + if (window[type].getItem('PMATest') === 'test') { + // Supported, remove test variable from storage + window[type].removeItem('PMATest'); + return true; + } + } catch(error) { + // Not supported + } + return false; +} diff --git a/js/navigation.js b/js/navigation.js index 6b46f2222e..477753ec85 100644 --- a/js/navigation.js +++ b/js/navigation.js @@ -277,9 +277,54 @@ $(function () { }); }); - PMA_showCurrentNavigation(); + // Check if session storage is supported + if (isStorageSupported('sessionStorage')) { + var storage = window.sessionStorage; + // remove tree from storage if Navi_panel config form is submitted + $(document).on('submit', 'form.config-form', function(event) { + if ($(this).attr('action').indexOf('form=Navi_panel') >= 0) { + storage.removeItem('navTree'); + } + }); + // Initialize if no previous state is defined + if (typeof storage.navTree === 'undefined') { + PMA_showCurrentNavigation(); + navTreeStateUpdate(); + } else if (PMA_commonParams.get('server') === storage.server) { + // Restore the tree from storage + $('#pma_navigation_tree_content').html(storage.navTree); + $('div.pageselector.dbselector').html(storage.page); + } + } else { + PMA_showCurrentNavigation(); + } }); +/** + * updates the tree state in sessionStorage + * + * @returns void + */ +function navTreeStateUpdate() { + // update if session storage is supported + if (isStorageSupported('sessionStorage')) { + var storage = window.sessionStorage; + // try catch necessary here to detect whether + // content to be stored exceeds storage capacity + try { + storage.setItem('navTree', $('#pma_navigation_tree_content').html()); + storage.setItem('server', PMA_commonParams.get('server')); + storage.setItem('page', $('div.pageselector.dbselector').html()); + } catch(error) { + // storage capacity exceeded & old navigation tree + // state is no more valid, so remove it + storage.removeItem('navTree'); + storage.removeItem('server'); + storage.removeItem('page'); + } + } +} + /** * Expands a node in navigation tree. * @@ -299,6 +344,7 @@ function expandTreeNode($expandElem, callback) { if (callback && typeof callback == 'function') { callback.call(); } + $children.promise().done(navTreeStateUpdate); } else { var $throbber = $('#pma_navigation .throbber') .first() @@ -312,9 +358,8 @@ function expandTreeNode($expandElem, callback) { if (data.success === true) { var $destination = $expandElem.closest('li'); $icon.removeClass('ic_b_plus').addClass('ic_b_minus'); - $destination - .children('div.list_container') - .slideDown('fast'); + $children = $destination.children('div.list_container'); + $children.slideDown('fast'); if ($destination.find('ul > li').length == 1) { $destination.find('ul > li') .find('a.expander.container') @@ -329,6 +374,7 @@ function expandTreeNode($expandElem, callback) { } $icon.show(); $throbber.remove(); + $children.promise().done(navTreeStateUpdate); }); } $expandElem.blur(); @@ -374,6 +420,7 @@ function collapseTreeNode($expandElem) { } } $expandElem.blur(); + $children.promise().done(navTreeStateUpdate); } /** @@ -644,6 +691,7 @@ function PMA_reloadNavigation(callback) { if (typeof callback === 'function') { callback.call(); } + navTreeStateUpdate(); } else { PMA_ajaxShowMessage(data.error); } @@ -716,6 +764,7 @@ function PMA_navigationTreePagination($this) { } else { PMA_ajaxShowMessage(data.error); } + navTreeStateUpdate(); }); } diff --git a/libraries/navigation/Nodes/Node.class.php b/libraries/navigation/Nodes/Node.class.php index d30b6111bc..56631f0dd0 100644 --- a/libraries/navigation/Nodes/Node.class.php +++ b/libraries/navigation/Nodes/Node.class.php @@ -494,6 +494,7 @@ class Node if ($GLOBALS['cfg']['NavigationTreeDisableDatabaseExpansion']) { return ''; } elseif ($match && ! $this->is_group) { + $this->visible = true; return PMA_Util::getImage('b_minus.png'); } else { return PMA_Util::getImage('b_plus.png', __('Expand/Collapse'));