From f0899e16b3cd92df43ed705f1fbace6ae87753a3 Mon Sep 17 00:00:00 2001 From: Oliver Gorwits Date: Sun, 5 May 2013 23:53:20 +0100 Subject: [PATCH] add frontend pseudo device add form --- .../Web/Plugin/AdminTask/PseudoDevice.pm | 21 +++++++----- Netdisco/share/public/css/netdisco.css | 5 +++ .../views/ajax/admintask/pseudodevice.tt | 32 +++++++++++++++++ Netdisco/share/views/js/admintask.js | 34 ++++++++++++++++++- 4 files changed, 82 insertions(+), 10 deletions(-) create mode 100644 Netdisco/share/views/ajax/admintask/pseudodevice.tt diff --git a/Netdisco/lib/App/Netdisco/Web/Plugin/AdminTask/PseudoDevice.pm b/Netdisco/lib/App/Netdisco/Web/Plugin/AdminTask/PseudoDevice.pm index 15f208c9..6ac3a208 100644 --- a/Netdisco/lib/App/Netdisco/Web/Plugin/AdminTask/PseudoDevice.pm +++ b/Netdisco/lib/App/Netdisco/Web/Plugin/AdminTask/PseudoDevice.pm @@ -11,14 +11,17 @@ register_admin_task({ label => 'Manage Pseudo Devices', }); -#ajax '/ajax/content/report/duplexmismatch' => sub { -# my $set = schema('netdisco')->resultset('Virtual::DuplexMismatch'); -# return unless $set->count; -# -# content_type('text/html'); -# template 'ajax/report/duplexmismatch.tt', { -# results => $set, -# }, { layout => undef }; -#}; +ajax '/ajax/content/admin/pseudodevice' => sub { + my $set = schema('netdisco')->resultset('Device') + ->search( + {vendor => 'netdisco'}, + {order_by => { -desc => 'last_discover' }}, + ); + + content_type('text/html'); + template 'ajax/admintask/pseudodevice.tt', { + results => $set, + }, { layout => undef }; +}; true; diff --git a/Netdisco/share/public/css/netdisco.css b/Netdisco/share/public/css/netdisco.css index 3e54494b..d380136f 100644 --- a/Netdisco/share/public/css/netdisco.css +++ b/Netdisco/share/public/css/netdisco.css @@ -191,6 +191,11 @@ td { text-align: center; } +/* manage pseudo devices table form */ +.center_cell input { + margin-bottom: 2px; +} + /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */ /* tabs */ diff --git a/Netdisco/share/views/ajax/admintask/pseudodevice.tt b/Netdisco/share/views/ajax/admintask/pseudodevice.tt new file mode 100644 index 00000000..98e73c98 --- /dev/null +++ b/Netdisco/share/views/ajax/admintask/pseudodevice.tt @@ -0,0 +1,32 @@ + + + + + + + + + + + + + + + + + + + [% WHILE (row = results.next) %] + + + + + + + [% END %] + +
Device NameDevice IPNumber of PortsAction
+ +
[% row.dns | html_entity %][% row.ip | html_entity %][% row.ports.count | html_entity %] Add
+ diff --git a/Netdisco/share/views/js/admintask.js b/Netdisco/share/views/js/admintask.js index 096e2017..3848ce04 100644 --- a/Netdisco/share/views/js/admintask.js +++ b/Netdisco/share/views/js/admintask.js @@ -4,7 +4,39 @@ // 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) { } + function inner_view_processing(tab) { + var target = '#pseudodevice_pane'; + + // activity for add pseudo device + // dynamically bind to all forms in the table + $(target).on('submit', 'form', function() { + // stop form from submitting normally + event.preventDefault(); + + // submit the query and put results into the tab pane + $.ajax({ + type: 'POST' + ,async: false + ,dataType: 'html' + ,url: uri_base + '/ajax/content/admin/pseudodevice/' + $(this).attr('name') + ,data: $(this).serializeArray() + ,beforeSend: function() { + $(target).html( + '
Waiting for results...
' + ); + } + ,success: function(content) { + $(target).html(content); + } + ,error: function() { + $(target).html( + '
' + + 'Update failed! Please contact your site administrator.
' + ); + } + }); + }); + } // on load, check initial Device Search Options form state, // and on each change to the form fields