From 3271c019314554a9fc247f4720870c8dcd578555 Mon Sep 17 00:00:00 2001 From: Oliver Gorwits Date: Sun, 5 May 2013 21:45:17 +0100 Subject: [PATCH] complete the code for admin tasks page loading --- Netdisco/lib/App/Netdisco/Web.pm | 1 + Netdisco/lib/App/Netdisco/Web/Plugin.pm | 11 +----- Netdisco/share/public/javascripts/netdisco.js | 4 +- Netdisco/share/views/admintask.tt | 38 +++++++++++++++++++ Netdisco/share/views/js/admintask.js | 11 ++++++ Netdisco/share/views/js/common.js | 7 +++- Netdisco/share/views/layouts/main.tt | 8 ++-- 7 files changed, 63 insertions(+), 17 deletions(-) create mode 100644 Netdisco/share/views/admintask.tt create mode 100644 Netdisco/share/views/js/admintask.js diff --git a/Netdisco/lib/App/Netdisco/Web.pm b/Netdisco/lib/App/Netdisco/Web.pm index 797b7283..d51d4bf4 100644 --- a/Netdisco/lib/App/Netdisco/Web.pm +++ b/Netdisco/lib/App/Netdisco/Web.pm @@ -13,6 +13,7 @@ use App::Netdisco::Web::AuthN; use App::Netdisco::Web::Search; use App::Netdisco::Web::Device; use App::Netdisco::Web::Report; +use App::Netdisco::Web::AdminTask; use App::Netdisco::Web::TypeAhead; use App::Netdisco::Web::PortControl; diff --git a/Netdisco/lib/App/Netdisco/Web/Plugin.pm b/Netdisco/lib/App/Netdisco/Web/Plugin.pm index 11a6a179..53c17859 100644 --- a/Netdisco/lib/App/Netdisco/Web/Plugin.pm +++ b/Netdisco/lib/App/Netdisco/Web/Plugin.pm @@ -7,7 +7,7 @@ set( 'navbar_items' => [], 'search_tabs' => [], 'device_tabs' => [], - 'admin_tasks' => [], + 'admin_tasks' => {}, 'reports_menu' => {}, 'reports' => {}, 'report_order' => [qw/Device Port Node VLAN Network Wireless/], @@ -60,14 +60,7 @@ register 'register_admin_task' => sub { return; } - foreach my $item (@{ setting('admin_tasks') }) { - if ($item->{tag} eq $config->{tag}) { - $item = $config; - return; - } - } - - push @{ setting('admin_tasks') }, $config; + setting('admin_tasks')->{ $config->{tag} } = $config; }; sub _register_tab { diff --git a/Netdisco/share/public/javascripts/netdisco.js b/Netdisco/share/public/javascripts/netdisco.js index 865eb60e..d8f6527c 100644 --- a/Netdisco/share/public/javascripts/netdisco.js +++ b/Netdisco/share/public/javascripts/netdisco.js @@ -44,8 +44,8 @@ function do_search (event, tab) { // update browser search history with the new query. // however if it's the same tab, this is a *replace* of the query url. - // and just skip this bit if it's the reports display. - if (path != 'report' && window.History && window.History.enabled) { + // and just skip this bit if it's the report or admin display. + if (path != 'report' && path != 'admin' && window.History && window.History.enabled) { is_from_history_plugin = 1; window.History.replaceState( {name: tab, fields: $(form).serializeArray()}, diff --git a/Netdisco/share/views/admintask.tt b/Netdisco/share/views/admintask.tt new file mode 100644 index 00000000..8957a6a1 --- /dev/null +++ b/Netdisco/share/views/admintask.tt @@ -0,0 +1,38 @@ + +
+ + +
+ +
+
+
+
+ + diff --git a/Netdisco/share/views/js/admintask.js b/Netdisco/share/views/js/admintask.js new file mode 100644 index 00000000..096e2017 --- /dev/null +++ b/Netdisco/share/views/js/admintask.js @@ -0,0 +1,11 @@ + // used by the tabbing interface to make sure the correct + // ajax content is loaded + var path = 'admin'; + + // this is called by do_search to support local code + // here, when tab changes need to strike/unstrike the navbar search + function inner_view_processing(tab) { } + + // on load, check initial Device Search Options form state, + // and on each change to the form fields + $(document).ready(function() { }); diff --git a/Netdisco/share/views/js/common.js b/Netdisco/share/views/js/common.js index 7b23897b..a5d50079 100644 --- a/Netdisco/share/views/js/common.js +++ b/Netdisco/share/views/js/common.js @@ -7,11 +7,16 @@ $('[% "#${tab.tag}_form" %]').submit(function(event){ do_search(event, '[% tab.tag %]'); }); [% END %] - // and for the reports page + // and for the report pages [% IF report %] $('[% "#${report.tag}_form" %]').submit(function(event){ do_search(event, '[% report.tag %]'); }); [% END %] + // and for the admin pages + [% IF task %] + $('[% "#${task.tag}_form" %]').submit(function(event){ do_search(event, '[% task.tag %]'); }); + [% END %] + // on page load, load the content for the active tab [% IF params.tab %] $('#[% params.tab %]_form').trigger("submit"); diff --git a/Netdisco/share/views/layouts/main.tt b/Netdisco/share/views/layouts/main.tt index c85f56b3..0c8b3544 100644 --- a/Netdisco/share/views/layouts/main.tt +++ b/Netdisco/share/views/layouts/main.tt @@ -84,18 +84,16 @@ - [% IF vars.user.admin %] + [% IF vars.user.admin AND settings.admin_tasks.size %] [% END %]