Files
netdisco/Netdisco/share/views/js/common.js
Oliver Gorwits ca6a08ef46 Change from ?tab=tabname param to .../tabname path
The reason for this is that DataTables keys local data on the page path, so
each tab should have its own path. We're already doing this for reports and
admin tasks, so it also makes sense to have consistency with search and device
tabs.

Squashed commit of the following:

commit 4ad33a23a81122496adfe561ad14f039e6255eff
Author: Oliver Gorwits <oliver@cpan.org>
Date:   Sat Oct 25 14:46:17 2014 +0100

    fix search preference selection

commit 363e094935d386961e8773f787af41c46b83129a
Author: Oliver Gorwits <oliver@cpan.org>
Date:   Sat Oct 25 14:36:45 2014 +0100

    fix css selector to match begins with /search

commit 43c972ee0d9401f74dcc3bd30052dba130b0d068
Author: Oliver Gorwits <oliver@cpan.org>
Date:   Sat Oct 25 14:18:24 2014 +0100

    fix history push

commit 84f83eb46874b0222c0484014389713e4f027c8a
Author: Oliver Gorwits <oliver@cpan.org>
Date:   Sat Oct 25 14:06:44 2014 +0100

    update sidebar form for tab-path, remove hidden tab name field

commit 344d4679a83f714c998cd475c041f8effab0c696
Author: Oliver Gorwits <oliver@cpan.org>
Date:   Sat Oct 25 14:05:49 2014 +0100

    update template links for tab path

commit 9cf370d7eb4413aac6fc19c2c13a9bf670600965
Author: Oliver Gorwits <oliver@cpan.org>
Date:   Sat Oct 25 14:04:57 2014 +0100

    move tab-specific JS from common into specific includes files

commit c2d8592a18e389535368d1e74fed29fe5a0eabd8
Author: Oliver Gorwits <oliver@cpan.org>
Date:   Sat Oct 25 14:02:46 2014 +0100

    fix mode

commit 52487cea47eaaea7f5c74536ad6d4bb2a8d6ba4c
Author: Oliver Gorwits <oliver@cpan.org>
Date:   Sat Oct 25 14:01:15 2014 +0100

    move from tab param to tabname template var

commit b5a2424631a0050d5de3bc658746a40cd822e869
Merge: 531782b d8102bf
Author: Oliver Gorwits <oliver@cpan.org>
Date:   Sat Oct 25 10:50:00 2014 +0100

    Merge branch 'master' into em-device-ports-json
2014-10-25 14:51:15 +01:00

81 lines
2.5 KiB
JavaScript

// csv download icon on any table page
// needs to be dynamically updated to use current search options
function update_csv_download_link (type, tab, show) {
var form = '#' + tab + '_form';
var query = $(form).serialize();
if (show.length) {
$('#nd_csv-download')
.attr('href', uri_base + '/ajax/content/' + type + '/' + tab + '?' + query)
.attr('download', 'netdisco-' + type + '-' + tab + '.csv')
.show();
}
else {
$('#nd_csv-download').hide();
}
}
// page title includes tab name and possibly device name
// this is nice for when you have multiple netdisco pages open in the
// browser
function update_page_title (tab) {
var pgtitle = 'Netdisco';
if ($.trim($('#nd_device-name').text()).length) {
pgtitle = $.trim($('#nd_device-name').text()) +' - '+ $('#'+ tab + '_link').text();
}
return pgtitle;
}
// update browser search history with the new query.
// support history add (push) or replace via push parameter
function update_browser_history (tab, pgtitle, push) {
return; // FIXME
var form = '#' + tab + '_form';
var query = $(form).serialize();
if (query.length) { query = '?' + query }
if (window.History && window.History.enabled) {
is_from_history_plugin = 1;
var target = uri_base + '/' + path + '/' + tab + query;
if (push.length) {
if (location.pathname == target) { return };
window.History.pushState(
{name: tab, fields: $(form).serializeArray()}, pgtitle, target
);
}
else {
window.History.replaceState(
{name: tab, fields: $(form).serializeArray()}, pgtitle, target
);
}
is_from_history_plugin = 0;
}
}
// each sidebar search form has a hidden copy of the main navbar search
function copy_navbar_to_sidebar (tab) {
var form = '#' + tab + '_form';
// copy navbar value to currently active sidebar form
if ($('#nq').val()) {
$(form).find("input[name=q]").val( $('#nq').val() );
}
// then copy to all other inactive tab sidebars
$('form').find("input[name=q]").each( function() {
$(this).val( $(form).find("input[name=q]").val() );
});
}
$(document).ready(function() {
// on page load, load the content for the active tab
[% IF tabname %]
[% IF tabname == 'ipinventory' OR tabname == 'subnets' %]
$('#[% tabname %]_submit').click();
[% ELSE %]
$('#[% tabname %]_form').trigger("submit");
[% END %]
[% END %]
});