1 /* vim: set expandtab sw=4 ts=4 sts=4: */
3 * function used in or for navigation panel
5 * @package phpMyAdmin-Navigation
9 * updates the tree state in sessionStorage
13 function navTreeStateUpdate () {
14 // update if session storage is supported
15 if (isStorageSupported('sessionStorage')) {
16 var storage = window.sessionStorage;
17 // try catch necessary here to detect whether
18 // content to be stored exceeds storage capacity
20 storage.setItem('navTreePaths', JSON.stringify(traverseNavigationForPaths()));
21 storage.setItem('server', PMA_commonParams.get('server'));
22 storage.setItem('token', PMA_commonParams.get('token'));
24 // storage capacity exceeded & old navigation tree
25 // state is no more valid, so remove it
26 storage.removeItem('navTreePaths');
27 storage.removeItem('server');
28 storage.removeItem('token');
35 * updates the filter state in sessionStorage
39 function navFilterStateUpdate (filterName, filterValue) {
40 if (isStorageSupported('sessionStorage')) {
41 var storage = window.sessionStorage;
43 var currentFilter = $.extend({}, JSON.parse(storage.getItem('navTreeSearchFilters')));
45 filter[filterName] = filterValue;
46 currentFilter = $.extend(currentFilter, filter);
47 storage.setItem('navTreeSearchFilters', JSON.stringify(currentFilter));
49 storage.removeItem('navTreeSearchFilters');
56 * restores the filter state on navigation reload
60 function navFilterStateRestore () {
61 if (isStorageSupported('sessionStorage')
62 && typeof window.sessionStorage.navTreeSearchFilters !== 'undefined'
64 var searchClauses = JSON.parse(window.sessionStorage.navTreeSearchFilters);
65 if (Object.keys(searchClauses).length < 1) {
68 // restore database filter if present and not empty
69 if (searchClauses.hasOwnProperty('dbFilter')
70 && searchClauses.dbFilter.length
72 $obj = $('#pma_navigation_tree');
73 if (! $obj.data('fastFilter')) {
76 new PMA_fastFilter.filter($obj, '')
79 $obj.find('li.fast_filter.db_fast_filter input.searchClause')
80 .val(searchClauses.dbFilter)
83 // find all table filters present in the tree
84 $tableFilters = $('#pma_navigation_tree li.database')
85 .children('div.list_container')
86 .find('li.fast_filter input.searchClause');
87 // restore table filters
88 $tableFilters.each(function () {
89 $obj = $(this).closest('div.list_container');
90 // aPath associated with this filter
91 var filterName = $(this).siblings('input[name=aPath]').val();
92 // if this table's filter has a state stored in storage
93 if (searchClauses.hasOwnProperty(filterName)
94 && searchClauses[filterName].length
96 // clear state if item is not visible,
97 // happens when table filter becomes invisible
98 // as db filter has already been applied
99 if (! $obj.is(':visible')) {
100 navFilterStateUpdate(filterName, '');
103 if (! $obj.data('fastFilter')) {
106 new PMA_fastFilter.filter($obj, '')
109 $(this).val(searchClauses[filterName])
117 * Loads child items of a node and executes a given callback
120 * @param $expandElem expander
121 * @param callback callback function
125 function loadChildNodes (isNode, $expandElem, callback) {
126 var $destination = null;
130 if (!$expandElem.hasClass('expander')) {
133 $destination = $expandElem.closest('li');
135 aPath: $expandElem.find('span.aPath').text(),
136 vPath: $expandElem.find('span.vPath').text(),
137 pos: $expandElem.find('span.pos').text(),
138 pos2_name: $expandElem.find('span.pos2_name').text(),
139 pos2_value: $expandElem.find('span.pos2_value').text(),
143 if ($expandElem.closest('ul').hasClass('search_results')) {
144 params.searchClause = PMA_fastFilter.getSearchClause();
145 params.searchClause2 = PMA_fastFilter.getSearchClause2($expandElem);
148 $destination = $('#pma_navigation_tree_content');
150 aPath: $expandElem.attr('aPath'),
151 vPath: $expandElem.attr('vPath'),
152 pos: $expandElem.attr('pos'),
160 var url = $('#pma_navigation').find('a.navigation_url').attr('href');
161 $.get(url, params, function (data) {
162 if (typeof data !== 'undefined' && data.success === true) {
163 $destination.find('div.list_container').remove(); // FIXME: Hack, there shouldn't be a list container there
165 $destination.append(data.message);
166 $expandElem.addClass('loaded');
168 $destination.html(data.message);
169 $destination.children()
179 var $errors = $(data._errors);
180 if ($errors.children().length > 0) {
181 $('#pma_errors').replaceWith(data._errors);
184 if (callback && typeof callback === 'function') {
187 } else if (data.redirect_flag === '1') {
188 if (window.location.href.indexOf('?') === -1) {
189 window.location.href += '?session_expired=1';
191 window.location.href += '&session_expired=1';
193 window.location.reload();
195 var $throbber = $expandElem.find('img.throbber');
197 var $icon = $expandElem.find('img.ic_b_plus');
199 PMA_ajaxShowMessage(data.error, false);
205 * Collapses a node in navigation tree.
207 * @param $expandElem expander
211 function collapseTreeNode ($expandElem) {
212 var $children = $expandElem.closest('li').children('div.list_container');
213 var $icon = $expandElem.find('img');
214 if ($expandElem.hasClass('loaded')) {
215 if ($icon.is('.ic_b_minus')) {
216 $icon.removeClass('ic_b_minus').addClass('ic_b_plus');
217 $children.slideUp('fast');
221 $children.promise().done(navTreeStateUpdate);
225 * Traverse the navigation tree backwards to generate all the actual
226 * and virtual paths, as well as the positions in the pagination at
227 * various levels, if necessary.
231 function traverseNavigationForPaths () {
233 pos: $('#pma_navigation_tree').find('div.dbselector select').val()
235 if ($('#navi_db_select').length) {
239 $('#pma_navigation_tree').find('a.expander:visible').each(function () {
240 if ($(this).find('img').is('.ic_b_minus') &&
241 $(this).closest('li').find('div.list_container .ic_b_minus').length === 0
243 params['n' + count + '_aPath'] = $(this).find('span.aPath').text();
244 params['n' + count + '_vPath'] = $(this).find('span.vPath').text();
246 var pos2_name = $(this).find('span.pos2_name').text();
251 .find('span.pos2_name:last')
254 var pos2_value = $(this).find('span.pos2_value').text();
259 .find('span.pos2_value:last')
263 params['n' + count + '_pos2_name'] = pos2_name;
264 params['n' + count + '_pos2_value'] = pos2_value;
266 params['n' + count + '_pos3_name'] = $(this).find('span.pos3_name').text();
267 params['n' + count + '_pos3_value'] = $(this).find('span.pos3_value').text();
275 * Executed on page load
278 if (! $('#pma_navigation').length) {
279 // Don't bother running any code if the navigation is not even on the page
283 // Do not let the page reload on submitting the fast filter
284 $(document).on('submit', '.fast_filter', function (event) {
285 event.preventDefault();
288 // Fire up the resize handlers
292 * opens/closes (hides/shows) tree elements
293 * loads data via ajax
295 $(document).on('click', '#pma_navigation_tree a.expander', function (event) {
296 event.preventDefault();
297 event.stopImmediatePropagation();
298 var $icon = $(this).find('img');
299 if ($icon.is('.ic_b_plus')) {
300 expandTreeNode($(this));
302 collapseTreeNode($(this));
307 * Register event handler for click on the reload
308 * navigation icon at the top of the panel
310 $(document).on('click', '#pma_navigation_reload', function (event) {
311 event.preventDefault();
312 // reload icon object
313 var $icon = $(this).find('img');
314 // source of the hidden throbber icon
315 var icon_throbber_src = $('#pma_navigation').find('.throbber').attr('src');
316 // source of the reload icon
317 var icon_reload_src = $icon.attr('src');
318 // replace the source of the reload icon with the one for throbber
319 $icon.attr('src', icon_throbber_src);
320 PMA_reloadNavigation();
321 // after one second, put back the reload icon
322 setTimeout(function () {
323 $icon.attr('src', icon_reload_src);
327 $(document).on('change', '#navi_db_select', function (event) {
328 if (! $(this).val()) {
329 PMA_commonParams.set('db', '');
330 PMA_reloadNavigation();
332 $(this).closest('form').trigger('submit');
336 * Register event handler for click on the collapse all
337 * navigation icon at the top of the navigation tree
339 $(document).on('click', '#pma_navigation_collapse', function (event) {
340 event.preventDefault();
341 $('#pma_navigation_tree').find('a.expander').each(function () {
342 var $icon = $(this).find('img');
343 if ($icon.is('.ic_b_minus')) {
350 * Register event handler to toggle
351 * the 'link with main panel' icon on mouseenter.
353 $(document).on('mouseenter', '#pma_navigation_sync', function (event) {
354 event.preventDefault();
355 var synced = $('#pma_navigation_tree').hasClass('synced');
356 var $img = $('#pma_navigation_sync').children('img');
358 $img.removeClass('ic_s_link').addClass('ic_s_unlink');
360 $img.removeClass('ic_s_unlink').addClass('ic_s_link');
365 * Register event handler to toggle
366 * the 'link with main panel' icon on mouseout.
368 $(document).on('mouseout', '#pma_navigation_sync', function (event) {
369 event.preventDefault();
370 var synced = $('#pma_navigation_tree').hasClass('synced');
371 var $img = $('#pma_navigation_sync').children('img');
373 $img.removeClass('ic_s_unlink').addClass('ic_s_link');
375 $img.removeClass('ic_s_link').addClass('ic_s_unlink');
380 * Register event handler to toggle
381 * the linking with main panel behavior
383 $(document).on('click', '#pma_navigation_sync', function (event) {
384 event.preventDefault();
385 var synced = $('#pma_navigation_tree').hasClass('synced');
386 var $img = $('#pma_navigation_sync').children('img');
389 .removeClass('ic_s_unlink')
390 .addClass('ic_s_link')
391 .attr('alt', PMA_messages.linkWithMain)
392 .attr('title', PMA_messages.linkWithMain);
393 $('#pma_navigation_tree')
394 .removeClass('synced')
396 .removeClass('selected');
399 .removeClass('ic_s_link')
400 .addClass('ic_s_unlink')
401 .attr('alt', PMA_messages.unlinkWithMain)
402 .attr('title', PMA_messages.unlinkWithMain);
403 $('#pma_navigation_tree').addClass('synced');
404 PMA_showCurrentNavigation();
409 * Bind all "fast filter" events
411 $(document).on('click', '#pma_navigation_tree li.fast_filter span', PMA_fastFilter.events.clear);
412 $(document).on('focus', '#pma_navigation_tree li.fast_filter input.searchClause', PMA_fastFilter.events.focus);
413 $(document).on('blur', '#pma_navigation_tree li.fast_filter input.searchClause', PMA_fastFilter.events.blur);
414 $(document).on('keyup', '#pma_navigation_tree li.fast_filter input.searchClause', PMA_fastFilter.events.keyup);
417 * Ajax handler for pagination
419 $(document).on('click', '#pma_navigation_tree div.pageselector a.ajax', function (event) {
420 event.preventDefault();
421 PMA_navigationTreePagination($(this));
429 '#pma_navigation_tree.highlight li:not(.fast_filter)',
431 if ($('li:visible', this).length === 0) {
432 $(this).addClass('activePointer');
438 '#pma_navigation_tree.highlight li:not(.fast_filter)',
440 $(this).removeClass('activePointer');
444 /** Create a Routine, Trigger or Event */
445 $(document).on('click', 'li.new_procedure a.ajax, li.new_function a.ajax', function (event) {
446 event.preventDefault();
447 var dialog = new RTE.object('routine');
448 dialog.editorDialog(1, $(this));
450 $(document).on('click', 'li.new_trigger a.ajax', function (event) {
451 event.preventDefault();
452 var dialog = new RTE.object('trigger');
453 dialog.editorDialog(1, $(this));
455 $(document).on('click', 'li.new_event a.ajax', function (event) {
456 event.preventDefault();
457 var dialog = new RTE.object('event');
458 dialog.editorDialog(1, $(this));
461 /** Edit Routines, Triggers or Events */
462 $(document).on('click', 'li.procedure > a.ajax, li.function > a.ajax', function (event) {
463 event.preventDefault();
464 var dialog = new RTE.object('routine');
465 dialog.editorDialog(0, $(this));
467 $(document).on('click', 'li.trigger > a.ajax', function (event) {
468 event.preventDefault();
469 var dialog = new RTE.object('trigger');
470 dialog.editorDialog(0, $(this));
472 $(document).on('click', 'li.event > a.ajax', function (event) {
473 event.preventDefault();
474 var dialog = new RTE.object('event');
475 dialog.editorDialog(0, $(this));
478 /** Execute Routines */
479 $(document).on('click', 'li.procedure div a.ajax img,' +
480 ' li.function div a.ajax img', function (event) {
481 event.preventDefault();
482 var dialog = new RTE.object('routine');
483 dialog.executeDialog($(this).parent());
485 /** Export Triggers and Events */
486 $(document).on('click', 'li.trigger div:eq(1) a.ajax img,' +
487 ' li.event div:eq(1) a.ajax img', function (event) {
488 event.preventDefault();
489 var dialog = new RTE.object();
490 dialog.exportDialog($(this).parent());
494 $(document).on('click', '#pma_navigation_tree li.new_index a.ajax', function (event) {
495 event.preventDefault();
496 var url = $(this).attr('href').substr(
497 $(this).attr('href').indexOf('?') + 1
498 ) + '&ajax_request=true';
499 var title = PMA_messages.strAddIndex;
500 indexEditorDialog(url, title);
504 $(document).on('click', 'li.index a.ajax', function (event) {
505 event.preventDefault();
506 var url = $(this).attr('href').substr(
507 $(this).attr('href').indexOf('?') + 1
508 ) + '&ajax_request=true';
509 var title = PMA_messages.strEditIndex;
510 indexEditorDialog(url, title);
514 $(document).on('click', 'li.new_view a.ajax', function (event) {
515 event.preventDefault();
516 PMA_createViewDialog($(this));
519 /** Hide navigation tree item */
520 $(document).on('click', 'a.hideNavItem.ajax', function (event) {
521 event.preventDefault();
525 server: PMA_commonParams.get('server'),
527 url: $(this).attr('href') + '&ajax_request=true',
528 success: function (data) {
529 if (typeof data !== 'undefined' && data.success === true) {
530 PMA_reloadNavigation();
532 PMA_ajaxShowMessage(data.error);
538 /** Display a dialog to choose hidden navigation items to show */
539 $(document).on('click', 'a.showUnhide.ajax', function (event) {
540 event.preventDefault();
541 var $msg = PMA_ajaxShowMessage();
542 $.get($(this).attr('href') + '&ajax_request=1', function (data) {
543 if (typeof data !== 'undefined' && data.success === true) {
544 PMA_ajaxRemoveMessage($msg);
545 var buttonOptions = {};
546 buttonOptions[PMA_messages.strClose] = function () {
547 $(this).dialog('close');
550 .attr('id', 'unhideNavItemDialog')
551 .append(data.message)
556 buttons: buttonOptions,
557 title: PMA_messages.strUnhideNavItem,
563 PMA_ajaxShowMessage(data.error);
568 /** Show a hidden navigation tree item */
569 $(document).on('click', 'a.unhideNavItem.ajax', function (event) {
570 event.preventDefault();
571 var $tr = $(this).parents('tr');
572 var $msg = PMA_ajaxShowMessage();
576 server: PMA_commonParams.get('server'),
578 url: $(this).attr('href') + '&ajax_request=true',
579 success: function (data) {
580 PMA_ajaxRemoveMessage($msg);
581 if (typeof data !== 'undefined' && data.success === true) {
583 PMA_reloadNavigation();
585 PMA_ajaxShowMessage(data.error);
591 // Add/Remove favorite table using Ajax.
592 $(document).on('click', '.favorite_table_anchor', function (event) {
593 event.preventDefault();
595 var anchor_id = $self.attr('id');
596 if ($self.data('favtargetn') !== null) {
597 if ($('a[data-favtargets="' + $self.data('favtargetn') + '"]').length > 0) {
598 $('a[data-favtargets="' + $self.data('favtargetn') + '"]').trigger('click');
604 url: $self.attr('href'),
608 favorite_tables: (isStorageSupported('localStorage') && typeof window.localStorage.favorite_tables !== 'undefined')
609 ? window.localStorage.favorite_tables
611 server: PMA_commonParams.get('server'),
613 success: function (data) {
615 $('#pma_favorite_list').html(data.list);
616 $('#' + anchor_id).parent().html(data.anchor);
620 $('#' + anchor_id).attr('title')
622 // Update localStorage.
623 if (isStorageSupported('localStorage')) {
624 window.localStorage.favorite_tables = data.favorite_tables;
627 PMA_ajaxShowMessage(data.message);
632 // Check if session storage is supported
633 if (isStorageSupported('sessionStorage')) {
634 var storage = window.sessionStorage;
635 // remove tree from storage if Navi_panel config form is submitted
636 $(document).on('submit', 'form.config-form', function (event) {
637 storage.removeItem('navTreePaths');
639 // Initialize if no previous state is defined
640 if ($('#pma_navigation_tree_content').length &&
641 typeof storage.navTreePaths === 'undefined'
643 PMA_reloadNavigation();
644 } else if (PMA_commonParams.get('server') === storage.server &&
645 PMA_commonParams.get('token') === storage.token
647 // Reload the tree to the state before page refresh
648 PMA_reloadNavigation(navFilterStateRestore, JSON.parse(storage.navTreePaths));
650 // If the user is different
651 navTreeStateUpdate();
657 * Expands a node in navigation tree.
659 * @param $expandElem expander
660 * @param callback callback function
664 function expandTreeNode ($expandElem, callback) {
665 var $children = $expandElem.closest('li').children('div.list_container');
666 var $icon = $expandElem.find('img');
667 if ($expandElem.hasClass('loaded')) {
668 if ($icon.is('.ic_b_plus')) {
669 $icon.removeClass('ic_b_plus').addClass('ic_b_minus');
670 $children.slideDown('fast');
672 if (callback && typeof callback === 'function') {
675 $children.promise().done(navTreeStateUpdate);
677 var $throbber = $('#pma_navigation').find('.throbber')
680 .css({ visibility: 'visible', display: 'block' })
683 $throbber.insertBefore($icon);
685 loadChildNodes(true, $expandElem, function (data) {
686 if (typeof data !== 'undefined' && data.success === true) {
687 var $destination = $expandElem.closest('li');
688 $icon.removeClass('ic_b_plus').addClass('ic_b_minus');
689 $children = $destination.children('div.list_container');
690 $children.slideDown('fast');
691 if ($destination.find('ul > li').length === 1) {
692 $destination.find('ul > li')
693 .find('a.expander.container')
696 if (callback && typeof callback === 'function') {
699 PMA_showFullName($destination);
701 PMA_ajaxShowMessage(data.error, false);
705 $children.promise().done(navTreeStateUpdate);
712 * Auto-scrolls the newly chosen database
714 * @param object $element The element to set to view
715 * @param boolean $forceToTop Whether to force scroll to top
718 function scrollToView ($element, $forceToTop) {
719 navFilterStateRestore();
720 var $container = $('#pma_navigation_tree_content');
721 var elemTop = $element.offset().top - $container.offset().top;
723 var scrollPadding = 20; // extra padding from top of bottom when scrolling to view
724 if (elemTop < 0 || $forceToTop) {
725 $container.stop().animate({
726 scrollTop: elemTop + $container.scrollTop() - scrollPadding
728 } else if (elemTop + textHeight > $container.height()) {
729 $container.stop().animate({
730 scrollTop: elemTop + textHeight - $container.height() + $container.scrollTop() + scrollPadding
736 * Expand the navigation and highlight the current database or table/view
740 function PMA_showCurrentNavigation () {
741 var db = PMA_commonParams.get('db');
742 var table = PMA_commonParams.get('table');
743 $('#pma_navigation_tree')
745 .removeClass('selected');
747 var $dbItem = findLoadedItem(
748 $('#pma_navigation_tree').find('> div'), db, 'database', !table
750 if ($('#navi_db_select').length &&
751 $('option:selected', $('#navi_db_select')).length
753 if (! PMA_selectCurrentDb()) {
756 // If loaded database in navigation is not same as current one
757 if ($('#pma_navigation_tree_content').find('span.loaded_db:first').text()
758 !== $('#navi_db_select').val()
760 loadChildNodes(false, $('option:selected', $('#navi_db_select')), function (data) {
761 handleTableOrDb(table, $('#pma_navigation_tree_content'));
762 var $children = $('#pma_navigation_tree_content').children('div.list_container');
763 $children.promise().done(navTreeStateUpdate);
766 handleTableOrDb(table, $('#pma_navigation_tree_content'));
768 } else if ($dbItem) {
769 var $expander = $dbItem.children('div:first').children('a.expander');
770 // if not loaded or loaded but collapsed
771 if (! $expander.hasClass('loaded') ||
772 $expander.find('img').is('.ic_b_plus')
774 expandTreeNode($expander, function () {
775 handleTableOrDb(table, $dbItem);
778 handleTableOrDb(table, $dbItem);
781 } else if ($('#navi_db_select').length && $('#navi_db_select').val()) {
782 $('#navi_db_select').val('').hide().trigger('change');
784 PMA_showFullName($('#pma_navigation_tree'));
786 function handleTableOrDb (table, $dbItem) {
788 loadAndHighlightTableOrView($dbItem, table);
790 var $container = $dbItem.children('div.list_container');
791 var $tableContainer = $container.children('ul').children('li.tableContainer');
792 if ($tableContainer.length > 0) {
793 var $expander = $tableContainer.children('div:first').children('a.expander');
794 $tableContainer.addClass('selected');
795 expandTreeNode($expander, function () {
796 scrollToView($dbItem, true);
799 scrollToView($dbItem, true);
804 function findLoadedItem ($container, name, clazz, doSelect) {
806 $container.children('ul').children('li').each(function () {
808 // this is a navigation group, recurse
809 if ($li.is('.navGroup')) {
810 var $container = $li.children('div.list_container');
811 var $childRet = findLoadedItem(
812 $container, name, clazz, doSelect
818 } else { // this is a real navigation item
819 // name and class matches
820 if (((clazz && $li.is('.' + clazz)) || ! clazz) &&
821 $li.children('a').text() === name) {
823 $li.addClass('selected');
825 // taverse up and expand and parent navigation groups
826 $li.parents('.navGroup').each(function () {
827 var $cont = $(this).children('div.list_container');
828 if (! $cont.is(':visible')) {
830 .children('div:first')
831 .children('a.expander')
843 function loadAndHighlightTableOrView ($dbItem, itemName) {
844 var $container = $dbItem.children('div.list_container');
846 var $whichItem = isItemInContainer($container, itemName, 'li.table, li.view');
847 // If item already there in some container
849 // get the relevant container while may also be a subcontainer
850 var $relatedContainer = $whichItem.closest('li.subContainer').length
851 ? $whichItem.closest('li.subContainer')
853 $whichItem = findLoadedItem(
854 $relatedContainer.children('div.list_container'),
858 showTableOrView($whichItem, $relatedContainer.children('div:first').children('a.expander'));
859 // else if item not there, try loading once
861 var $sub_containers = $dbItem.find('.subContainer');
862 // If there are subContainers i.e. tableContainer or viewContainer
863 if ($sub_containers.length > 0) {
864 var $containers = [];
865 $sub_containers.each(function (index) {
866 $containers[index] = $(this);
867 $expander = $containers[index]
868 .children('div:first')
869 .children('a.expander');
870 if (! $expander.hasClass('loaded')) {
871 loadAndShowTableOrView($expander, $containers[index], itemName);
874 // else if no subContainers
877 .children('div:first')
878 .children('a.expander');
879 if (! $expander.hasClass('loaded')) {
880 loadAndShowTableOrView($expander, $dbItem, itemName);
886 function loadAndShowTableOrView ($expander, $relatedContainer, itemName) {
887 loadChildNodes(true, $expander, function (data) {
888 var $whichItem = findLoadedItem(
889 $relatedContainer.children('div.list_container'),
893 showTableOrView($whichItem, $expander);
898 function showTableOrView ($whichItem, $expander) {
899 expandTreeNode($expander, function (data) {
901 scrollToView($whichItem, false);
906 function isItemInContainer ($container, name, clazz) {
907 var $whichItem = null;
908 $items = $container.find(clazz);
910 $items.each(function () {
911 if ($(this).children('a').text() === name) {
912 $whichItem = $(this);
921 * Disable navigation panel settings
925 function PMA_disableNaviSettings () {
926 $('#pma_navigation_settings_icon').addClass('hide');
927 $('#pma_navigation_settings').remove();
931 * Ensure that navigation panel settings is properly setup.
936 function PMA_ensureNaviSettings (selflink) {
937 $('#pma_navigation_settings_icon').removeClass('hide');
939 if (!$('#pma_navigation_settings').length) {
941 getNaviSettings: true,
942 server: PMA_commonParams.get('server'),
944 var url = $('#pma_navigation').find('a.navigation_url').attr('href');
945 $.post(url, params, function (data) {
946 if (typeof data !== 'undefined' && data.success) {
947 $('#pma_navi_settings_container').html(data.message);
951 $('#pma_navigation_settings').find('form').attr('action', selflink);
953 PMA_ajaxShowMessage(data.error);
957 $('#pma_navigation_settings').find('form').attr('action', selflink);
962 * Reloads the whole navigation tree while preserving its state
964 * @param function the callback function
965 * @param Object stored navigation paths
969 function PMA_reloadNavigation (callback, paths) {
973 server: PMA_commonParams.get('server'),
975 paths = paths || traverseNavigationForPaths();
976 $.extend(params, paths);
977 if ($('#navi_db_select').length) {
978 params.db = PMA_commonParams.get('db');
979 requestNaviReload(params);
982 requestNaviReload(params);
984 function requestNaviReload (params) {
985 var url = $('#pma_navigation').find('a.navigation_url').attr('href');
986 $.post(url, params, function (data) {
987 if (typeof data !== 'undefined' && data.success) {
988 $('#pma_navigation_tree').html(data.message).children('div').show();
989 if ($('#pma_navigation_tree').hasClass('synced')) {
990 PMA_selectCurrentDb();
991 PMA_showCurrentNavigation();
993 // Fire the callback, if any
994 if (typeof callback === 'function') {
997 navTreeStateUpdate();
999 PMA_ajaxShowMessage(data.error);
1005 function PMA_selectCurrentDb () {
1006 var $naviDbSelect = $('#navi_db_select');
1008 if (!$naviDbSelect.length) {
1012 if (PMA_commonParams.get('db')) { // db selected
1013 $naviDbSelect.show();
1016 $naviDbSelect.val(PMA_commonParams.get('db'));
1017 return $naviDbSelect.val() === PMA_commonParams.get('db');
1021 * Handles any requests to change the page in a branch of a tree
1023 * This can be called from link click or select change event handlers
1025 * @param object $this A jQuery object that points to the element that
1026 * initiated the action of changing the page
1030 function PMA_navigationTreePagination ($this) {
1031 var $msgbox = PMA_ajaxShowMessage();
1032 var isDbSelector = $this.closest('div.pageselector').is('.dbselector');
1035 if ($this[0].tagName === 'A') {
1036 url = $this.attr('href');
1037 params = 'ajax_request=true';
1038 } else { // tagName === 'SELECT'
1039 url = 'navigation.php';
1040 params = $this.closest('form').serialize() + '&ajax_request=true';
1042 var searchClause = PMA_fastFilter.getSearchClause();
1044 params += '&searchClause=' + encodeURIComponent(searchClause);
1047 params += '&full=true';
1049 var searchClause2 = PMA_fastFilter.getSearchClause2($this);
1050 if (searchClause2) {
1051 params += '&searchClause2=' + encodeURIComponent(searchClause2);
1054 $.post(url, params, function (data) {
1055 if (typeof data !== 'undefined' && data.success) {
1056 PMA_ajaxRemoveMessage($msgbox);
1058 var val = PMA_fastFilter.getSearchClause();
1059 $('#pma_navigation_tree')
1064 $('#pma_navigation_tree')
1065 .find('li.fast_filter input.searchClause')
1069 var $parent = $this.closest('div.list_container').parent();
1070 var val = PMA_fastFilter.getSearchClause2($this);
1071 $this.closest('div.list_container').html(
1072 $(data.message).children().show()
1075 $parent.find('li.fast_filter input.searchClause').val(val);
1077 $parent.find('span.pos2_value:first').text(
1078 $parent.find('span.pos2_value:last').text()
1080 $parent.find('span.pos3_value:first').text(
1081 $parent.find('span.pos3_value:last').text()
1085 PMA_ajaxShowMessage(data.error);
1086 PMA_handleRedirectAndReload(data);
1088 navTreeStateUpdate();
1093 * @var ResizeHandler Custom object that manages the resizing of the navigation
1095 * XXX: Must only be ever instanciated once
1096 * XXX: Inside event handlers the 'this' object is accessed as 'event.data.resize_handler'
1098 var ResizeHandler = function () {
1100 * @var int panel_width Used by the collapser to know where to go
1101 * back to when uncollapsing the panel
1103 this.panel_width = 0;
1105 * @var string left Used to provide support for RTL languages
1107 this.left = $('html').attr('dir') === 'ltr' ? 'left' : 'right';
1109 * Adjusts the width of the navigation panel to the specified value
1111 * @param int pos Navigation width in pixels
1115 this.setWidth = function (pos) {
1116 if (typeof pos !== 'number') {
1119 var $resizer = $('#pma_navigation_resizer');
1120 var resizer_width = $resizer.width();
1121 var $collapser = $('#pma_navigation_collapser');
1122 var windowWidth = $(window).width();
1123 $('#pma_navigation').width(pos);
1124 $('body').css('margin-' + this.left, pos + 'px');
1125 $('#floating_menubar, #pma_console')
1126 .css('margin-' + this.left, (pos + resizer_width) + 'px');
1127 $resizer.css(this.left, pos + 'px');
1130 .css(this.left, pos + resizer_width)
1131 .html(this.getSymbol(pos))
1132 .prop('title', PMA_messages.strShowPanel);
1133 } else if (windowWidth > 768) {
1135 .css(this.left, pos)
1136 .html(this.getSymbol(pos))
1137 .prop('title', PMA_messages.strHidePanel);
1138 $('#pma_navigation_resizer').css({ 'width': '3px' });
1141 .css(this.left, windowWidth - 22)
1142 .html(this.getSymbol(100))
1143 .prop('title', PMA_messages.strHidePanel);
1144 $('#pma_navigation').width(windowWidth);
1145 $('body').css('margin-' + this.left, '0px');
1146 $('#pma_navigation_resizer').css({ 'width': '0px' });
1148 setTimeout(function () {
1149 $(window).trigger('resize');
1153 * Returns the horizontal position of the mouse,
1154 * relative to the outer side of the navigation panel
1156 * @param int pos Navigation width in pixels
1160 this.getPos = function (event) {
1161 var pos = event.pageX;
1162 var windowWidth = $(window).width();
1163 var windowScroll = $(window).scrollLeft();
1164 pos = pos - windowScroll;
1165 if (this.left !== 'left') {
1166 pos = windowWidth - event.pageX;
1170 } else if (pos + 100 >= windowWidth) {
1171 pos = windowWidth - 100;
1173 this.panel_width = 0;
1178 * Returns the HTML code for the arrow symbol used in the collapser
1180 * @param int width The width of the panel
1184 this.getSymbol = function (width) {
1185 if (this.left === 'left') {
1200 * Event handler for initiating a resize of the panel
1202 * @param object e Event data (contains a reference to resizeHandler)
1206 this.mousedown = function (event) {
1207 event.preventDefault();
1209 .on('mousemove', { 'resize_handler': event.data.resize_handler },
1210 $.throttle(event.data.resize_handler.mousemove, 4))
1211 .on('mouseup', { 'resize_handler': event.data.resize_handler },
1212 event.data.resize_handler.mouseup);
1213 $('body').css('cursor', 'col-resize');
1216 * Event handler for terminating a resize of the panel
1218 * @param object e Event data (contains a reference to resizeHandler)
1222 this.mouseup = function (event) {
1223 $('body').css('cursor', '');
1224 configSet('NavigationWidth', event.data.resize_handler.getPos(event));
1225 $('#topmenu').menuResizer('resize');
1231 * Event handler for updating the panel during a resize operation
1233 * @param object e Event data (contains a reference to resizeHandler)
1237 this.mousemove = function (event) {
1238 event.preventDefault();
1239 var pos = event.data.resize_handler.getPos(event);
1240 event.data.resize_handler.setWidth(pos);
1241 if ($('.sticky_columns').length !== 0) {
1242 handleAllStickyColumns();
1246 * Event handler for collapsing the panel
1248 * @param object e Event data (contains a reference to resizeHandler)
1252 this.collapse = function (event) {
1253 event.preventDefault();
1254 var panel_width = event.data.resize_handler.panel_width;
1255 var width = $('#pma_navigation').width();
1256 if (width === 0 && panel_width === 0) {
1259 configSet('NavigationWidth', panel_width);
1260 event.data.resize_handler.setWidth(panel_width);
1261 event.data.resize_handler.panel_width = width;
1264 * Event handler for resizing the navigation tree height on window resize
1268 this.treeResize = function (event) {
1269 var $nav = $('#pma_navigation');
1270 var $nav_tree = $('#pma_navigation_tree');
1271 var $nav_header = $('#pma_navigation_header');
1272 var $nav_tree_content = $('#pma_navigation_tree_content');
1273 $nav_tree.height($nav.height() - $nav_header.height());
1274 if ($nav_tree_content.length > 0) {
1275 $nav_tree_content.height($nav_tree.height() - $nav_tree_content.position().top);
1277 // TODO: in fast filter search response there is no #pma_navigation_tree_content, needs to be added in php
1279 'overflow-y': 'auto'
1282 // Set content bottom space beacuse of console
1283 $('body').css('margin-bottom', $('#pma_console').height() + 'px');
1285 // Hide the pma_navigation initially when loaded on mobile
1286 if ($(window).width() < 768) {
1289 this.setWidth(configGet('NavigationWidth', false));
1290 $('#topmenu').menuResizer('resize');
1292 // Register the events for the resizer and the collapser
1293 $(document).on('mousedown', '#pma_navigation_resizer', { 'resize_handler': this }, this.mousedown);
1294 $(document).on('click', '#pma_navigation_collapser', { 'resize_handler': this }, this.collapse);
1296 // Add the correct arrow symbol to the collapser
1297 $('#pma_navigation_collapser').html(this.getSymbol($('#pma_navigation').width()));
1298 // Fix navigation tree height
1299 $(window).on('resize', this.treeResize);
1300 // need to call this now and then, browser might decide
1301 // to show/hide horizontal scrollbars depending on page content width
1302 setInterval(this.treeResize, 2000);
1304 }; // End of ResizeHandler
1307 * @var object PMA_fastFilter Handles the functionality that allows filtering
1308 * of the items in a branch of the navigation tree
1310 var PMA_fastFilter = {
1312 * Construct for the asynchronous fast filter functionality
1314 * @param object $this A jQuery object pointing to the list container
1315 * which is the nearest parent of the fast filter
1316 * @param string searchClause The query string for the filter
1318 * @return new PMA_fastFilter.filter object
1320 filter: function ($this, searchClause) {
1322 * @var object $this A jQuery object pointing to the list container
1323 * which is the nearest parent of the fast filter
1327 * @var bool searchClause The query string for the filter
1329 this.searchClause = searchClause;
1331 * @var object $clone A clone of the original contents
1332 * of the navigation branch before
1333 * the fast filter was applied
1335 this.$clone = $this.clone();
1337 * @var object xhr A reference to the ajax request that is currently running
1341 * @var int timeout Used to delay the request for asynchronous search
1343 this.timeout = null;
1345 var $filterInput = $this.find('li.fast_filter input.searchClause');
1346 if ($filterInput.length !== 0 &&
1347 $filterInput.val() !== '' &&
1348 $filterInput.val() !== $filterInput[0].defaultValue
1354 * Gets the query string from the database fast filter form
1358 getSearchClause: function () {
1360 var $input = $('#pma_navigation_tree')
1361 .find('li.fast_filter.db_fast_filter input.searchClause');
1362 if ($input.length && $input.val() !== $input[0].defaultValue) {
1363 retval = $input.val();
1368 * Gets the query string from a second level item's fast filter form
1369 * The retrieval is done by trasversing the navigation tree backwards
1373 getSearchClause2: function ($this) {
1374 var $filterContainer = $this.closest('div.list_container');
1375 var $filterInput = $([]);
1376 if ($filterContainer
1377 .find('li.fast_filter:not(.db_fast_filter) input.searchClause')
1379 $filterInput = $filterContainer
1380 .find('li.fast_filter:not(.db_fast_filter) input.searchClause');
1382 var searchClause2 = '';
1383 if ($filterInput.length !== 0 &&
1384 $filterInput.first().val() !== $filterInput[0].defaultValue
1386 searchClause2 = $filterInput.val();
1388 return searchClause2;
1391 * @var hash events A list of functions that are bound to DOM events
1392 * at the top of this file
1395 focus: function (event) {
1396 var $obj = $(this).closest('div.list_container');
1397 if (! $obj.data('fastFilter')) {
1400 new PMA_fastFilter.filter($obj, $(this).val())
1403 if ($(this).val() === this.defaultValue) {
1409 blur: function (event) {
1410 if ($(this).val() === '') {
1411 $(this).val(this.defaultValue);
1413 var $obj = $(this).closest('div.list_container');
1414 if ($(this).val() === this.defaultValue && $obj.data('fastFilter')) {
1415 $obj.data('fastFilter').restore();
1418 keyup: function (event) {
1419 var $obj = $(this).closest('div.list_container');
1421 if ($(this).val() !== this.defaultValue && $(this).val() !== '') {
1422 $obj.find('div.pageselector').hide();
1423 str = $(this).val();
1427 * FIXME at the server level a value match is done while on
1428 * the client side it is a regex match. These two should be aligned
1431 // regex used for filtering.
1434 regex = new RegExp(str, 'i');
1439 // this is the div that houses the items to be filtered by this filter.
1441 if ($(this).closest('li.fast_filter').is('.db_fast_filter')) {
1442 outerContainer = $('#pma_navigation_tree_content');
1444 outerContainer = $obj;
1447 // filters items that are directly under the div as well as grouped in
1448 // groups. Does not filter child items (i.e. a database search does
1449 // not filter tables)
1450 var item_filter = function ($curr) {
1451 $curr.children('ul').children('li.navGroup').each(function () {
1452 $(this).children('div.list_container').each(function () {
1453 item_filter($(this)); // recursive
1456 $curr.children('ul').children('li').children('a').not('.container').each(function () {
1457 if (regex.test($(this).text())) {
1458 $(this).parent().show().removeClass('hidden');
1460 $(this).parent().hide().addClass('hidden');
1464 item_filter(outerContainer);
1466 // hides containers that does not have any visible children
1467 var container_filter = function ($curr) {
1468 $curr.children('ul').children('li.navGroup').each(function () {
1469 var $group = $(this);
1470 $group.children('div.list_container').each(function () {
1471 container_filter($(this)); // recursive
1473 $group.show().removeClass('hidden');
1474 if ($group.children('div.list_container').children('ul')
1475 .children('li').not('.hidden').length === 0) {
1476 $group.hide().addClass('hidden');
1480 container_filter(outerContainer);
1482 if ($(this).val() !== this.defaultValue && $(this).val() !== '') {
1483 if (! $obj.data('fastFilter')) {
1486 new PMA_fastFilter.filter($obj, $(this).val())
1489 if (event.keyCode === 13) {
1490 $obj.data('fastFilter').update($(this).val());
1493 } else if ($obj.data('fastFilter')) {
1494 $obj.data('fastFilter').restore(true);
1496 // update filter state
1498 if ($(this).attr('name') === 'searchClause2') {
1499 filterName = $(this).siblings('input[name=aPath]').val();
1501 filterName = 'dbFilter';
1503 navFilterStateUpdate(filterName, $(this).val());
1505 clear: function (event) {
1506 event.stopPropagation();
1507 // Clear the input and apply the fast filter with empty input
1508 var filter = $(this).closest('div.list_container').data('fastFilter');
1512 var value = $(this).prev()[0].defaultValue;
1513 $(this).prev().val(value).trigger('keyup');
1518 * Handles a change in the search clause
1520 * @param string searchClause The query string for the filter
1524 PMA_fastFilter.filter.prototype.update = function (searchClause) {
1525 if (this.searchClause !== searchClause) {
1526 this.searchClause = searchClause;
1531 * After a delay of 250mS, initiates a request to retrieve search results
1532 * Multiple calls to this function will always abort the previous request
1536 PMA_fastFilter.filter.prototype.request = function () {
1538 if (self.$this.find('li.fast_filter').find('img.throbber').length === 0) {
1539 self.$this.find('li.fast_filter').append(
1540 $('<div class="throbber"></div>').append(
1541 $('#pma_navigation_content')
1542 .find('img.throbber')
1544 .css({ visibility: 'visible', display: 'block' })
1551 var url = $('#pma_navigation').find('a.navigation_url').attr('href');
1552 var params = self.$this.find('> ul > li > form.fast_filter').first().serialize();
1554 if (self.$this.find('> ul > li > form.fast_filter:first input[name=searchClause]').length === 0) {
1555 var $input = $('#pma_navigation_tree').find('li.fast_filter.db_fast_filter input.searchClause');
1556 if ($input.length && $input.val() !== $input[0].defaultValue) {
1557 params += '&searchClause=' + encodeURIComponent($input.val());
1565 complete: function (jqXHR, status) {
1566 if (status !== 'abort') {
1567 var data = JSON.parse(jqXHR.responseText);
1568 self.$this.find('li.fast_filter').find('div.throbber').remove();
1569 if (data && data.results) {
1570 self.swap.apply(self, [data.message]);
1577 * Replaces the contents of the navigation branch with the search results
1579 * @param string list The search results
1583 PMA_fastFilter.filter.prototype.swap = function (list) {
1585 .html($(list).html())
1589 .find('li.fast_filter input.searchClause')
1590 .val(this.searchClause);
1591 this.$this.data('fastFilter', this);
1594 * Restores the navigation to the original state after the fast filter is cleared
1596 * @param bool focus Whether to also focus the input box of the fast filter
1600 PMA_fastFilter.filter.prototype.restore = function (focus) {
1601 if (this.$this.children('ul').first().hasClass('search_results')) {
1602 this.$this.html(this.$clone.html()).children().show();
1603 this.$this.data('fastFilter', this);
1605 this.$this.find('li.fast_filter input.searchClause').focus();
1608 this.searchClause = '';
1609 this.$this.find('div.pageselector').show();
1610 this.$this.find('div.throbber').remove();
1614 * Show full name when cursor hover and name not shown completely
1616 * @param object $containerELem Container element
1620 function PMA_showFullName ($containerELem) {
1621 $containerELem.find('.hover_show_full').mouseenter(function () {
1623 var $this = $(this);
1624 var thisOffset = $this.offset();
1625 if ($this.text() === '') {
1628 var $parent = $this.parent();
1629 if (($parent.offset().left + $parent.outerWidth())
1630 < (thisOffset.left + $this.outerWidth())) {
1631 var $fullNameLayer = $('#full_name_layer');
1632 if ($fullNameLayer.length === 0) {
1633 $('body').append('<div id="full_name_layer" class="hide"></div>');
1634 $('#full_name_layer').mouseleave(function () {
1636 $(this).addClass('hide')
1637 .removeClass('hovering');
1638 }).mouseenter(function () {
1640 $(this).addClass('hovering');
1642 $fullNameLayer = $('#full_name_layer');
1644 $fullNameLayer.removeClass('hide');
1645 $fullNameLayer.css({ left: thisOffset.left, top: thisOffset.top });
1646 $fullNameLayer.html($this.clone());
1647 setTimeout(function () {
1648 if (! $fullNameLayer.hasClass('hovering')) {
1649 $fullNameLayer.trigger('mouseleave');