diff options
Diffstat (limited to 'srcs/phpmyadmin/js/navigation.js')
| -rw-r--r-- | srcs/phpmyadmin/js/navigation.js | 1719 |
1 files changed, 1719 insertions, 0 deletions
diff --git a/srcs/phpmyadmin/js/navigation.js b/srcs/phpmyadmin/js/navigation.js new file mode 100644 index 0000000..169d4e4 --- /dev/null +++ b/srcs/phpmyadmin/js/navigation.js @@ -0,0 +1,1719 @@ +/* vim: set expandtab sw=4 ts=4 sts=4: */ +/** + * function used in or for navigation panel + * + * @package phpMyAdmin-Navigation + */ + +/* global isStorageSupported, setupConfigTabs, setupRestoreField, setupValidation */ // js/config.js +/* global RTE */ // js/rte.js + +var Navigation = {}; + +/** + * updates the tree state in sessionStorage + * + * @returns void + */ +Navigation.treeStateUpdate = function () { + // 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('navTreePaths', JSON.stringify(Navigation.traverseForPaths())); + storage.setItem('server', CommonParams.get('server')); + storage.setItem('token', CommonParams.get('token')); + } catch (error) { + // storage capacity exceeded & old navigation tree + // state is no more valid, so remove it + storage.removeItem('navTreePaths'); + storage.removeItem('server'); + storage.removeItem('token'); + } + } +}; + +/** + * updates the filter state in sessionStorage + * + * @returns void + */ +Navigation.filterStateUpdate = function (filterName, filterValue) { + if (isStorageSupported('sessionStorage')) { + var storage = window.sessionStorage; + try { + var currentFilter = $.extend({}, JSON.parse(storage.getItem('navTreeSearchFilters'))); + var filter = {}; + filter[filterName] = filterValue; + currentFilter = $.extend(currentFilter, filter); + storage.setItem('navTreeSearchFilters', JSON.stringify(currentFilter)); + } catch (error) { + storage.removeItem('navTreeSearchFilters'); + } + } +}; + +/** + * restores the filter state on navigation reload + * + * @returns void + */ +Navigation.filterStateRestore = function () { + if (isStorageSupported('sessionStorage') + && typeof window.sessionStorage.navTreeSearchFilters !== 'undefined' + ) { + var searchClauses = JSON.parse(window.sessionStorage.navTreeSearchFilters); + if (Object.keys(searchClauses).length < 1) { + return; + } + // restore database filter if present and not empty + if (searchClauses.hasOwnProperty('dbFilter') + && searchClauses.dbFilter.length + ) { + var $obj = $('#pma_navigation_tree'); + if (! $obj.data('fastFilter')) { + $obj.data( + 'fastFilter', + new Navigation.FastFilter.Filter($obj, '') + ); + } + $obj.find('li.fast_filter.db_fast_filter input.searchClause') + .val(searchClauses.dbFilter) + .trigger('keyup'); + } + // find all table filters present in the tree + var $tableFilters = $('#pma_navigation_tree li.database') + .children('div.list_container') + .find('li.fast_filter input.searchClause'); + // restore table filters + $tableFilters.each(function () { + $obj = $(this).closest('div.list_container'); + // aPath associated with this filter + var filterName = $(this).siblings('input[name=aPath]').val(); + // if this table's filter has a state stored in storage + if (searchClauses.hasOwnProperty(filterName) + && searchClauses[filterName].length + ) { + // clear state if item is not visible, + // happens when table filter becomes invisible + // as db filter has already been applied + if (! $obj.is(':visible')) { + Navigation.filterStateUpdate(filterName, ''); + return true; + } + if (! $obj.data('fastFilter')) { + $obj.data( + 'fastFilter', + new Navigation.FastFilter.Filter($obj, '') + ); + } + $(this).val(searchClauses[filterName]) + .trigger('keyup'); + } + }); + } +}; + +/** + * Loads child items of a node and executes a given callback + * + * @param isNode + * @param $expandElem expander + * @param callback callback function + * + * @returns void + */ +Navigation.loadChildNodes = function (isNode, $expandElem, callback) { + var $destination = null; + var params = null; + + if (isNode) { + if (!$expandElem.hasClass('expander')) { + return; + } + $destination = $expandElem.closest('li'); + params = { + 'aPath': $expandElem.find('span.aPath').text(), + 'vPath': $expandElem.find('span.vPath').text(), + 'pos': $expandElem.find('span.pos').text(), + 'pos2_name': $expandElem.find('span.pos2_name').text(), + 'pos2_value': $expandElem.find('span.pos2_value').text(), + 'searchClause': '', + 'searchClause2': '' + }; + if ($expandElem.closest('ul').hasClass('search_results')) { + params.searchClause = Navigation.FastFilter.getSearchClause(); + params.searchClause2 = Navigation.FastFilter.getSearchClause2($expandElem); + } + } else { + $destination = $('#pma_navigation_tree_content'); + params = { + 'aPath': $expandElem.attr('aPath'), + 'vPath': $expandElem.attr('vPath'), + 'pos': $expandElem.attr('pos'), + 'pos2_name': '', + 'pos2_value': '', + 'searchClause': '', + 'searchClause2': '' + }; + } + + var url = $('#pma_navigation').find('a.navigation_url').attr('href'); + $.get(url, params, function (data) { + if (typeof data !== 'undefined' && data.success === true) { + $destination.find('div.list_container').remove(); // FIXME: Hack, there shouldn't be a list container there + if (isNode) { + $destination.append(data.message); + $expandElem.addClass('loaded'); + } else { + $destination.html(data.message); + $destination.children() + .first() + .css({ + border: '0px', + margin: '0em', + padding : '0em' + }) + .slideDown('slow'); + } + if (data.errors) { + var $errors = $(data.errors); + if ($errors.children().length > 0) { + $('#pma_errors').replaceWith(data.errors); + } + } + if (callback && typeof callback === 'function') { + callback(data); + } + } else if (data.redirect_flag === '1') { + if (window.location.href.indexOf('?') === -1) { + window.location.href += '?session_expired=1'; + } else { + window.location.href += CommonParams.get('arg_separator') + 'session_expired=1'; + } + window.location.reload(); + } else { + var $throbber = $expandElem.find('img.throbber'); + $throbber.hide(); + var $icon = $expandElem.find('img.ic_b_plus'); + $icon.show(); + Functions.ajaxShowMessage(data.error, false); + } + }); +}; + +/** + * Collapses a node in navigation tree. + * + * @param $expandElem expander + * + * @returns void + */ +Navigation.collapseTreeNode = function ($expandElem) { + var $children = $expandElem.closest('li').children('div.list_container'); + var $icon = $expandElem.find('img'); + if ($expandElem.hasClass('loaded')) { + if ($icon.is('.ic_b_minus')) { + $icon.removeClass('ic_b_minus').addClass('ic_b_plus'); + $children.slideUp('fast'); + } + } + $expandElem.trigger('blur'); + $children.promise().done(Navigation.treeStateUpdate); +}; + +/** + * Traverse the navigation tree backwards to generate all the actual + * and virtual paths, as well as the positions in the pagination at + * various levels, if necessary. + * + * @return Object + */ +Navigation.traverseForPaths = function () { + var params = { + pos: $('#pma_navigation_tree').find('div.dbselector select').val() + }; + if ($('#navi_db_select').length) { + return params; + } + var count = 0; + $('#pma_navigation_tree').find('a.expander:visible').each(function () { + if ($(this).find('img').is('.ic_b_minus') && + $(this).closest('li').find('div.list_container .ic_b_minus').length === 0 + ) { + params['n' + count + '_aPath'] = $(this).find('span.aPath').text(); + params['n' + count + '_vPath'] = $(this).find('span.vPath').text(); + + var pos2Name = $(this).find('span.pos2_name').text(); + if (! pos2Name) { + pos2Name = $(this) + .parent() + .parent() + .find('span.pos2_name:last') + .text(); + } + var pos2Value = $(this).find('span.pos2_value').text(); + if (! pos2Value) { + pos2Value = $(this) + .parent() + .parent() + .find('span.pos2_value:last') + .text(); + } + + params['n' + count + '_pos2_name'] = pos2Name; + params['n' + count + '_pos2_value'] = pos2Value; + + params['n' + count + '_pos3_name'] = $(this).find('span.pos3_name').text(); + params['n' + count + '_pos3_value'] = $(this).find('span.pos3_value').text(); + count++; + } + }); + return params; +}; + +/** + * Executed on page load + */ +$(function () { + if (! $('#pma_navigation').length) { + // Don't bother running any code if the navigation is not even on the page + return; + } + + // Do not let the page reload on submitting the fast filter + $(document).on('submit', '.fast_filter', function (event) { + event.preventDefault(); + }); + + // Fire up the resize handlers + new Navigation.ResizeHandler(); + + /** + * opens/closes (hides/shows) tree elements + * loads data via ajax + */ + $(document).on('click', '#pma_navigation_tree a.expander', function (event) { + event.preventDefault(); + event.stopImmediatePropagation(); + var $icon = $(this).find('img'); + if ($icon.is('.ic_b_plus')) { + Navigation.expandTreeNode($(this)); + } else { + Navigation.collapseTreeNode($(this)); + } + }); + + /** + * Register event handler for click on the reload + * navigation icon at the top of the panel + */ + $(document).on('click', '#pma_navigation_reload', function (event) { + event.preventDefault(); + + // Find the loading symbol and show it + var $iconThrobberSrc = $('#pma_navigation').find('.throbber'); + $iconThrobberSrc.show(); + // TODO Why is a loading symbol both hidden, and invisible? + $iconThrobberSrc.css('visibility', ''); + + // Callback to be used to hide the loading symbol when done reloading + function hideNav () { + $iconThrobberSrc.hide(); + } + + // Reload the navigation + Navigation.reload(hideNav); + }); + + $(document).on('change', '#navi_db_select', function () { + if (! $(this).val()) { + CommonParams.set('db', ''); + Navigation.reload(); + } + $(this).closest('form').trigger('submit'); + }); + + /** + * Register event handler for click on the collapse all + * navigation icon at the top of the navigation tree + */ + $(document).on('click', '#pma_navigation_collapse', function (event) { + event.preventDefault(); + $('#pma_navigation_tree').find('a.expander').each(function () { + var $icon = $(this).find('img'); + if ($icon.is('.ic_b_minus')) { + $(this).trigger('click'); + } + }); + }); + + /** + * Register event handler to toggle + * the 'link with main panel' icon on mouseenter. + */ + $(document).on('mouseenter', '#pma_navigation_sync', function (event) { + event.preventDefault(); + var synced = $('#pma_navigation_tree').hasClass('synced'); + var $img = $('#pma_navigation_sync').children('img'); + if (synced) { + $img.removeClass('ic_s_link').addClass('ic_s_unlink'); + } else { + $img.removeClass('ic_s_unlink').addClass('ic_s_link'); + } + }); + + /** + * Register event handler to toggle + * the 'link with main panel' icon on mouseout. + */ + $(document).on('mouseout', '#pma_navigation_sync', function (event) { + event.preventDefault(); + var synced = $('#pma_navigation_tree').hasClass('synced'); + var $img = $('#pma_navigation_sync').children('img'); + if (synced) { + $img.removeClass('ic_s_unlink').addClass('ic_s_link'); + } else { + $img.removeClass('ic_s_link').addClass('ic_s_unlink'); + } + }); + + /** + * Register event handler to toggle + * the linking with main panel behavior + */ + $(document).on('click', '#pma_navigation_sync', function (event) { + event.preventDefault(); + var synced = $('#pma_navigation_tree').hasClass('synced'); + var $img = $('#pma_navigation_sync').children('img'); + if (synced) { + $img + .removeClass('ic_s_unlink') + .addClass('ic_s_link') + .attr('alt', Messages.linkWithMain) + .attr('title', Messages.linkWithMain); + $('#pma_navigation_tree') + .removeClass('synced') + .find('li.selected') + .removeClass('selected'); + } else { + $img + .removeClass('ic_s_link') + .addClass('ic_s_unlink') + .attr('alt', Messages.unlinkWithMain) + .attr('title', Messages.unlinkWithMain); + $('#pma_navigation_tree').addClass('synced'); + Navigation.showCurrent(); + } + }); + + /** + * Bind all "fast filter" events + */ + $(document).on('click', '#pma_navigation_tree li.fast_filter span', Navigation.FastFilter.events.clear); + $(document).on('focus', '#pma_navigation_tree li.fast_filter input.searchClause', Navigation.FastFilter.events.focus); + $(document).on('blur', '#pma_navigation_tree li.fast_filter input.searchClause', Navigation.FastFilter.events.blur); + $(document).on('keyup', '#pma_navigation_tree li.fast_filter input.searchClause', Navigation.FastFilter.events.keyup); + + /** + * Ajax handler for pagination + */ + $(document).on('click', '#pma_navigation_tree div.pageselector a.ajax', function (event) { + event.preventDefault(); + Navigation.treePagination($(this)); + }); + + /** + * Node highlighting + */ + $(document).on( + 'mouseover', + '#pma_navigation_tree.highlight li:not(.fast_filter)', + function () { + if ($('li:visible', this).length === 0) { + $(this).addClass('activePointer'); + } + } + ); + $(document).on( + 'mouseout', + '#pma_navigation_tree.highlight li:not(.fast_filter)', + function () { + $(this).removeClass('activePointer'); + } + ); + + /** Create a Routine, Trigger or Event */ + $(document).on('click', 'li.new_procedure a.ajax, li.new_function a.ajax', function (event) { + event.preventDefault(); + var dialog = new RTE.Object('routine'); + dialog.editorDialog(1, $(this)); + }); + $(document).on('click', 'li.new_trigger a.ajax', function (event) { + event.preventDefault(); + var dialog = new RTE.Object('trigger'); + dialog.editorDialog(1, $(this)); + }); + $(document).on('click', 'li.new_event a.ajax', function (event) { + event.preventDefault(); + var dialog = new RTE.Object('event'); + dialog.editorDialog(1, $(this)); + }); + + /** Edit Routines, Triggers or Events */ + $(document).on('click', 'li.procedure > a.ajax, li.function > a.ajax', function (event) { + event.preventDefault(); + var dialog = new RTE.Object('routine'); + dialog.editorDialog(0, $(this)); + }); + $(document).on('click', 'li.trigger > a.ajax', function (event) { + event.preventDefault(); + var dialog = new RTE.Object('trigger'); + dialog.editorDialog(0, $(this)); + }); + $(document).on('click', 'li.event > a.ajax', function (event) { + event.preventDefault(); + var dialog = new RTE.Object('event'); + dialog.editorDialog(0, $(this)); + }); + + /** Execute Routines */ + $(document).on('click', 'li.procedure div a.ajax img,' + + ' li.function div a.ajax img', function (event) { + event.preventDefault(); + var dialog = new RTE.Object('routine'); + dialog.executeDialog($(this).parent()); + }); + /** Export Triggers and Events */ + $(document).on('click', 'li.trigger div:eq(1) a.ajax img,' + + ' li.event div:eq(1) a.ajax img', function (event) { + event.preventDefault(); + var dialog = new RTE.Object(); + dialog.exportDialog($(this).parent()); + }); + + /** New index */ + $(document).on('click', '#pma_navigation_tree li.new_index a.ajax', function (event) { + event.preventDefault(); + var url = $(this).attr('href').substr( + $(this).attr('href').indexOf('?') + 1 + ) + CommonParams.get('arg_separator') + 'ajax_request=true'; + var title = Messages.strAddIndex; + Functions.indexEditorDialog(url, title); + }); + + /** Edit index */ + $(document).on('click', 'li.index a.ajax', function (event) { + event.preventDefault(); + var url = $(this).attr('href').substr( + $(this).attr('href').indexOf('?') + 1 + ) + CommonParams.get('arg_separator') + 'ajax_request=true'; + var title = Messages.strEditIndex; + Functions.indexEditorDialog(url, title); + }); + + /** New view */ + $(document).on('click', 'li.new_view a.ajax', function (event) { + event.preventDefault(); + Functions.createViewDialog($(this)); + }); + + /** Hide navigation tree item */ + $(document).on('click', 'a.hideNavItem.ajax', function (event) { + event.preventDefault(); + var argSep = CommonParams.get('arg_separator'); + var params = $(this).getPostData(); + params += argSep + 'ajax_request=true' + argSep + 'server=' + CommonParams.get('server'); + $.ajax({ + type: 'POST', + data: params, + url: $(this).attr('href'), + success: function (data) { + if (typeof data !== 'undefined' && data.success === true) { + Navigation.reload(); + } else { + Functions.ajaxShowMessage(data.error); + } + } + }); + }); + + /** Display a dialog to choose hidden navigation items to show */ + $(document).on('click', 'a.showUnhide.ajax', function (event) { + event.preventDefault(); + var $msg = Functions.ajaxShowMessage(); + var argSep = CommonParams.get('arg_separator'); + var params = $(this).getPostData(); + params += argSep + 'ajax_request=true'; + $.post($(this).attr('href'), params, function (data) { + if (typeof data !== 'undefined' && data.success === true) { + Functions.ajaxRemoveMessage($msg); + var buttonOptions = {}; + buttonOptions[Messages.strClose] = function () { + $(this).dialog('close'); + }; + $('<div></div>') + .attr('id', 'unhideNavItemDialog') + .append(data.message) + .dialog({ + width: 400, + minWidth: 200, + modal: true, + buttons: buttonOptions, + title: Messages.strUnhideNavItem, + close: function () { + $(this).remove(); + } + }); + } else { + Functions.ajaxShowMessage(data.error); + } + }); + }); + + /** Show a hidden navigation tree item */ + $(document).on('click', 'a.unhideNavItem.ajax', function (event) { + event.preventDefault(); + var $tr = $(this).parents('tr'); + var $hiddenTableCount = $tr.parents('tbody').children().length; + var $hideDialogBox = $tr.closest('div.ui-dialog'); + var $msg = Functions.ajaxShowMessage(); + var argSep = CommonParams.get('arg_separator'); + var params = $(this).getPostData(); + params += argSep + 'ajax_request=true' + argSep + 'server=' + CommonParams.get('server'); + $.ajax({ + type: 'POST', + data: params, + url: $(this).attr('href'), + success: function (data) { + Functions.ajaxRemoveMessage($msg); + if (typeof data !== 'undefined' && data.success === true) { + $tr.remove(); + if ($hiddenTableCount === 1) { + $hideDialogBox.remove(); + } + Navigation.reload(); + } else { + Functions.ajaxShowMessage(data.error); + } + } + }); + }); + + // Add/Remove favorite table using Ajax. + $(document).on('click', '.favorite_table_anchor', function (event) { + event.preventDefault(); + var $self = $(this); + var anchorId = $self.attr('id'); + if ($self.data('favtargetn') !== null) { + if ($('a[data-favtargets="' + $self.data('favtargetn') + '"]').length > 0) { + $('a[data-favtargets="' + $self.data('favtargetn') + '"]').trigger('click'); + return; + } + } + + $.ajax({ + url: $self.attr('href'), + cache: false, + type: 'POST', + data: { + 'favoriteTables': (isStorageSupported('localStorage') && typeof window.localStorage.favoriteTables !== 'undefined') + ? window.localStorage.favoriteTables + : '', + 'server': CommonParams.get('server'), + }, + success: function (data) { + if (data.changes) { + $('#pma_favorite_list').html(data.list); + $('#' + anchorId).parent().html(data.anchor); + Functions.tooltip( + $('#' + anchorId), + 'a', + $('#' + anchorId).attr('title') + ); + // Update localStorage. + if (isStorageSupported('localStorage')) { + window.localStorage.favoriteTables = data.favoriteTables; + } + } else { + Functions.ajaxShowMessage(data.message); + } + } + }); + }); + // 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 () { + storage.removeItem('navTreePaths'); + }); + // Initialize if no previous state is defined + if ($('#pma_navigation_tree_content').length && + typeof storage.navTreePaths === 'undefined' + ) { + Navigation.reload(); + } else if (CommonParams.get('server') === storage.server && + CommonParams.get('token') === storage.token + ) { + // Reload the tree to the state before page refresh + Navigation.reload(Navigation.filterStateRestore, JSON.parse(storage.navTreePaths)); + } else { + // If the user is different + Navigation.treeStateUpdate(); + Navigation.reload(); + } + } +}); + +/** + * Expands a node in navigation tree. + * + * @param $expandElem expander + * @param callback callback function + * + * @returns void + */ +Navigation.expandTreeNode = function ($expandElem, callback) { + var $children = $expandElem.closest('li').children('div.list_container'); + var $icon = $expandElem.find('img'); + if ($expandElem.hasClass('loaded')) { + if ($icon.is('.ic_b_plus')) { + $icon.removeClass('ic_b_plus').addClass('ic_b_minus'); + $children.slideDown('fast'); + } + if (callback && typeof callback === 'function') { + callback.call(); + } + $children.promise().done(Navigation.treeStateUpdate); + } else { + var $throbber = $('#pma_navigation').find('.throbber') + .first() + .clone() + .css({ visibility: 'visible', display: 'block' }) + .on('click', false); + $icon.hide(); + $throbber.insertBefore($icon); + + Navigation.loadChildNodes(true, $expandElem, function (data) { + if (typeof data !== 'undefined' && data.success === true) { + var $destination = $expandElem.closest('li'); + $icon.removeClass('ic_b_plus').addClass('ic_b_minus'); + $children = $destination.children('div.list_container'); + $children.slideDown('fast'); + if ($destination.find('ul > li').length === 1) { + $destination.find('ul > li') + .find('a.expander.container') + .trigger('click'); + } + if (callback && typeof callback === 'function') { + callback.call(); + } + Navigation.showFullName($destination); + } else { + Functions.ajaxShowMessage(data.error, false); + } + $icon.show(); + $throbber.remove(); + $children.promise().done(Navigation.treeStateUpdate); + }); + } + $expandElem.trigger('blur'); +}; + +/** + * Auto-scrolls the newly chosen database + * + * @param object $element The element to set to view + * @param boolean $forceToTop Whether to force scroll to top + * + */ +Navigation.scrollToView = function ($element, $forceToTop) { + Navigation.filterStateRestore(); + var $container = $('#pma_navigation_tree_content'); + var elemTop = $element.offset().top - $container.offset().top; + var textHeight = 20; + var scrollPadding = 20; // extra padding from top of bottom when scrolling to view + if (elemTop < 0 || $forceToTop) { + $container.stop().animate({ + scrollTop: elemTop + $container.scrollTop() - scrollPadding + }); + } else if (elemTop + textHeight > $container.height()) { + $container.stop().animate({ + scrollTop: elemTop + textHeight - $container.height() + $container.scrollTop() + scrollPadding + }); + } +}; + +/** + * Expand the navigation and highlight the current database or table/view + * + * @returns void + */ +Navigation.showCurrent = function () { + var db = CommonParams.get('db'); + var table = CommonParams.get('table'); + + var autoexpand = $('#pma_navigation_tree').hasClass('autoexpand'); + + $('#pma_navigation_tree') + .find('li.selected') + .removeClass('selected'); + var $dbItem; + if (db) { + $dbItem = findLoadedItem( + $('#pma_navigation_tree').find('> div'), db, 'database', !table + ); + if ($('#navi_db_select').length && + $('option:selected', $('#navi_db_select')).length + ) { + if (! Navigation.selectCurrentDatabase()) { + return; + } + // If loaded database in navigation is not same as current one + if ($('#pma_navigation_tree_content').find('span.loaded_db:first').text() + !== $('#navi_db_select').val() + ) { + Navigation.loadChildNodes(false, $('option:selected', $('#navi_db_select')), function () { + handleTableOrDb(table, $('#pma_navigation_tree_content')); + var $children = $('#pma_navigation_tree_content').children('div.list_container'); + $children.promise().done(Navigation.treeStateUpdate); + }); + } else { + handleTableOrDb(table, $('#pma_navigation_tree_content')); + } + } else if ($dbItem) { + fullExpand(table, $dbItem); + } + } else if ($('#navi_db_select').length && $('#navi_db_select').val()) { + $('#navi_db_select').val('').hide().trigger('change'); + } else if (autoexpand && $('#pma_navigation_tree_content > ul > li.database').length === 1) { + // automatically expand the list if there is only single database + + // find the name of the database + var dbItemName = ''; + + $('#pma_navigation_tree_content > ul > li.database').children('a').each(function () { + var name = $(this).text(); + if (!dbItemName && name.trim()) { // if the name is not empty, it is the desired element + dbItemName = name; + } + }); + + $dbItem = findLoadedItem( + $('#pma_navigation_tree').find('> div'), dbItemName, 'database', !table + ); + + fullExpand(table, $dbItem); + } + Navigation.showFullName($('#pma_navigation_tree')); + + function fullExpand (table, $dbItem) { + var $expander = $dbItem.children('div:first').children('a.expander'); + // if not loaded or loaded but collapsed + if (! $expander.hasClass('loaded') || + $expander.find('img').is('.ic_b_plus') + ) { + Navigation.expandTreeNode($expander, function () { + handleTableOrDb(table, $dbItem); + }); + } else { + handleTableOrDb(table, $dbItem); + } + } + + function handleTableOrDb (table, $dbItem) { + if (table) { + loadAndHighlightTableOrView($dbItem, table); + } else { + var $container = $dbItem.children('div.list_container'); + var $tableContainer = $container.children('ul').children('li.tableContainer'); + if ($tableContainer.length > 0) { + var $expander = $tableContainer.children('div:first').children('a.expander'); + $tableContainer.addClass('selected'); + Navigation.expandTreeNode($expander, function () { + Navigation.scrollToView($dbItem, true); + }); + } else { + Navigation.scrollToView($dbItem, true); + } + } + } + + function findLoadedItem ($container, name, clazz, doSelect) { + var ret = false; + $container.children('ul').children('li').each(function () { + var $li = $(this); + // this is a navigation group, recurse + if ($li.is('.navGroup')) { + var $container = $li.children('div.list_container'); + var $childRet = findLoadedItem( + $container, name, clazz, doSelect + ); + if ($childRet) { + ret = $childRet; + return false; + } + } else { // this is a real navigation item + // name and class matches + if (((clazz && $li.is('.' + clazz)) || ! clazz) && + $li.children('a').text() === name) { + if (doSelect) { + $li.addClass('selected'); + } + // taverse up and expand and parent navigation groups + $li.parents('.navGroup').each(function () { + var $cont = $(this).children('div.list_container'); + if (! $cont.is(':visible')) { + $(this) + .children('div:first') + .children('a.expander') + .trigger('click'); + } + }); + ret = $li; + return false; + } + } + }); + return ret; + } + + function loadAndHighlightTableOrView ($dbItem, itemName) { + var $container = $dbItem.children('div.list_container'); + var $expander; + var $whichItem = isItemInContainer($container, itemName, 'li.table, li.view'); + // If item already there in some container + if ($whichItem) { + // get the relevant container while may also be a subcontainer + var $relatedContainer = $whichItem.closest('li.subContainer').length + ? $whichItem.closest('li.subContainer') + : $dbItem; + $whichItem = findLoadedItem( + $relatedContainer.children('div.list_container'), + itemName, null, true + ); + // Show directly + showTableOrView($whichItem, $relatedContainer.children('div:first').children('a.expander')); + // else if item not there, try loading once + } else { + var $subContainers = $dbItem.find('.subContainer'); + // If there are subContainers i.e. tableContainer or viewContainer + if ($subContainers.length > 0) { + var $containers = []; + $subContainers.each(function (index) { + $containers[index] = $(this); + $expander = $containers[index] + .children('div:first') + .children('a.expander'); + if (! $expander.hasClass('loaded')) { + loadAndShowTableOrView($expander, $containers[index], itemName); + } + }); + // else if no subContainers + } else { + $expander = $dbItem + .children('div:first') + .children('a.expander'); + if (! $expander.hasClass('loaded')) { + loadAndShowTableOrView($expander, $dbItem, itemName); + } + } + } + } + + function loadAndShowTableOrView ($expander, $relatedContainer, itemName) { + Navigation.loadChildNodes(true, $expander, function () { + var $whichItem = findLoadedItem( + $relatedContainer.children('div.list_container'), + itemName, null, true + ); + if ($whichItem) { + showTableOrView($whichItem, $expander); + } + }); + } + + function showTableOrView ($whichItem, $expander) { + Navigation.expandTreeNode($expander, function () { + if ($whichItem) { + Navigation.scrollToView($whichItem, false); + } + }); + } + + function isItemInContainer ($container, name, clazz) { + var $whichItem = null; + var $items = $container.find(clazz); + $items.each(function () { + if ($(this).children('a').text() === name) { + $whichItem = $(this); + return false; + } + }); + return $whichItem; + } +}; + +/** + * Disable navigation panel settings + * + * @return void + */ +Navigation.disableSettings = function () { + $('#pma_navigation_settings_icon').addClass('hide'); + $('#pma_navigation_settings').remove(); +}; + +/** + * Ensure that navigation panel settings is properly setup. + * If not, set it up + * + * @return void + */ +Navigation.ensureSettings = function (selflink) { + $('#pma_navigation_settings_icon').removeClass('hide'); + + if (!$('#pma_navigation_settings').length) { + var params = { + getNaviSettings: true, + server: CommonParams.get('server'), + }; + var url = $('#pma_navigation').find('a.navigation_url').attr('href'); + $.post(url, params, function (data) { + if (typeof data !== 'undefined' && data.success) { + $('#pma_navi_settings_container').html(data.mes |
