conditionally show csv icon for device and search tabs

This commit is contained in:
Oliver Gorwits
2013-09-20 19:56:38 +01:00
parent 119d2c672d
commit 26b47d1296
6 changed files with 19 additions and 13 deletions

View File

@@ -6,7 +6,7 @@ use Dancer::Plugin::Auth::Extensible;
use App::Netdisco::Web::Plugin;
register_device_tab( { tag => 'addresses', label => 'Addresses' } );
register_device_tab( { tag => 'addresses', label => 'Addresses', provides_csv => 1 } );
# device interface addresses
get '/ajax/content/device/addresses' => require_login sub {

View File

@@ -8,7 +8,7 @@ use List::MoreUtils ();
use App::Netdisco::Web::Plugin;
register_search_tab({ tag => 'device', label => 'Device' });
register_search_tab({ tag => 'device', label => 'Device', provides_csv => 1 });
my $headers = ['Device','Contact','Location','System Name','Model','OS Version','Management IP','Serial'];

View File

@@ -6,7 +6,7 @@ use Dancer::Plugin::Auth::Extensible;
use App::Netdisco::Web::Plugin;
register_search_tab({ tag => 'port', label => 'Port' });
register_search_tab({ tag => 'port', label => 'Port', provides_csv => 1 });
# device ports with a description (er, name) matching
get '/ajax/content/search/port' => require_login sub {

View File

@@ -6,7 +6,7 @@ use Dancer::Plugin::Auth::Extensible;
use App::Netdisco::Web::Plugin;
register_search_tab( { tag => 'vlan', label => 'VLAN' } );
register_search_tab( { tag => 'vlan', label => 'VLAN', provides_csv => 1 } );
# devices carrying vlan xxx
get '/ajax/content/search/vlan' => require_login sub {

View File

@@ -46,8 +46,8 @@
<li[% ' class="active"' IF params.tab == tab.tag %]><a id="[% tab.tag %]_link" href="#[% tab.tag %]_pane">[% tab.label %]</a></li>
[% END %]
<span id="nd_device-name">
[% d.dns || d.name | html_entity %] &nbsp;
<a id="nd_csv-download" href="#" download="netdisco.csv">
[% d.dns || d.name | html_entity %]
<a id="nd_csv-download" href="#" download="netdisco.csv">&nbsp;
<i id="nd_csv-download-icon" class="text-info icon-file-text-alt icon-large"
rel="tooltip" data-placement="left" data-offset="5" data-title="Download as CSV"></i></a>
</span>

View File

@@ -1,11 +1,17 @@
// csv download icon on any table page
// needs to be dynamically updated to use current search options
function update_csv_download_link (type, tab) {
function update_csv_download_link (type, tab, show) {
var form = '#' + tab + '_form';
var query = $(form).serialize();
$('#nd_csv-download').attr('href',
'/ajax/content/' + type + '/' + tab + '?' + query);
if (show == '1') {
$('#nd_csv-download').attr('href',
'/ajax/content/' + type + '/' + tab + '?' + query);
$('#nd_csv-download').show();
}
else {
$('#nd_csv-download').hide();
}
}
// page title includes tab name and possibly device name
@@ -56,7 +62,7 @@
[% FOREACH tab IN settings._search_tabs %]
$('[% "#${tab.tag}_form" %]').submit(function (event) {
var pgtitle = update_page_title('[% tab.tag %]');
update_csv_download_link('search', '[% tab.tag %]');
update_csv_download_link('search', '[% tab.tag %]', '[% tab.provides_csv %]');
update_browser_history('[% tab.tag %]', pgtitle);
copy_navbar_to_sidebar('[% tab.tag %]');
do_search(event, '[% tab.tag %]');
@@ -69,7 +75,7 @@
[% FOREACH tab IN settings._device_tabs %]
$('[% "#${tab.tag}_form" %]').submit(function (event) {
var pgtitle = update_page_title('[% tab.tag %]');
update_csv_download_link('device', '[% tab.tag %]');
update_csv_download_link('device', '[% tab.tag %]', '[% tab.provides_csv %]');
update_browser_history('[% tab.tag %]', pgtitle);
copy_navbar_to_sidebar('[% tab.tag %]');
@@ -92,7 +98,7 @@
// for the report pages
$('[% "#${report.tag}_form" %]').submit(function (event) {
update_page_title('[% report.tag %]');
update_csv_download_link('report', '[% report.tag %]');
update_csv_download_link('report', '[% report.tag %]', '1');
do_search(event, '[% report.tag %]');
});
[% END -%]
@@ -101,7 +107,7 @@
// for the admin pages
$('[% "#${task.tag}_form" %]').submit(function (event) {
update_page_title('[% task.tag %]');
update_csv_download_link('task', '[% task.tag %]');
update_csv_download_link('task', '[% task.tag %]', '1');
do_search(event, '[% task.tag %]');
});
[% END %]