From 26b47d12964b3756aae89bde0a7377206d536fab Mon Sep 17 00:00:00 2001 From: Oliver Gorwits Date: Fri, 20 Sep 2013 19:56:38 +0100 Subject: [PATCH] conditionally show csv icon for device and search tabs --- .../Netdisco/Web/Plugin/Device/Addresses.pm | 2 +- .../App/Netdisco/Web/Plugin/Search/Device.pm | 2 +- .../App/Netdisco/Web/Plugin/Search/Port.pm | 2 +- .../App/Netdisco/Web/Plugin/Search/VLAN.pm | 2 +- Netdisco/share/views/device.tt | 4 ++-- Netdisco/share/views/js/common.js | 20 ++++++++++++------- 6 files changed, 19 insertions(+), 13 deletions(-) diff --git a/Netdisco/lib/App/Netdisco/Web/Plugin/Device/Addresses.pm b/Netdisco/lib/App/Netdisco/Web/Plugin/Device/Addresses.pm index 83f5186e..e9b26dde 100644 --- a/Netdisco/lib/App/Netdisco/Web/Plugin/Device/Addresses.pm +++ b/Netdisco/lib/App/Netdisco/Web/Plugin/Device/Addresses.pm @@ -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 { diff --git a/Netdisco/lib/App/Netdisco/Web/Plugin/Search/Device.pm b/Netdisco/lib/App/Netdisco/Web/Plugin/Search/Device.pm index 7e42246f..98dc6561 100644 --- a/Netdisco/lib/App/Netdisco/Web/Plugin/Search/Device.pm +++ b/Netdisco/lib/App/Netdisco/Web/Plugin/Search/Device.pm @@ -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']; diff --git a/Netdisco/lib/App/Netdisco/Web/Plugin/Search/Port.pm b/Netdisco/lib/App/Netdisco/Web/Plugin/Search/Port.pm index 986d87b9..1dda5c89 100644 --- a/Netdisco/lib/App/Netdisco/Web/Plugin/Search/Port.pm +++ b/Netdisco/lib/App/Netdisco/Web/Plugin/Search/Port.pm @@ -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 { diff --git a/Netdisco/lib/App/Netdisco/Web/Plugin/Search/VLAN.pm b/Netdisco/lib/App/Netdisco/Web/Plugin/Search/VLAN.pm index 5bbddd4f..8081dd8b 100644 --- a/Netdisco/lib/App/Netdisco/Web/Plugin/Search/VLAN.pm +++ b/Netdisco/lib/App/Netdisco/Web/Plugin/Search/VLAN.pm @@ -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 { diff --git a/Netdisco/share/views/device.tt b/Netdisco/share/views/device.tt index ce5c56fc..e70a2de7 100644 --- a/Netdisco/share/views/device.tt +++ b/Netdisco/share/views/device.tt @@ -46,8 +46,8 @@ [% tab.label %] [% END %] - [% d.dns || d.name | html_entity %]   - + [% d.dns || d.name | html_entity %] +   diff --git a/Netdisco/share/views/js/common.js b/Netdisco/share/views/js/common.js index 2fa3da0a..d37deaa0 100644 --- a/Netdisco/share/views/js/common.js +++ b/Netdisco/share/views/js/common.js @@ -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 %]