diff --git a/Netdisco/lib/App/Netdisco/Web/Plugin/AdminTask/PseudoDevice.pm b/Netdisco/lib/App/Netdisco/Web/Plugin/AdminTask/PseudoDevice.pm index eba5e08a..3fd0b924 100644 --- a/Netdisco/lib/App/Netdisco/Web/Plugin/AdminTask/PseudoDevice.pm +++ b/Netdisco/lib/App/Netdisco/Web/Plugin/AdminTask/PseudoDevice.pm @@ -29,8 +29,7 @@ sub _sanity_ok { } ajax '/ajax/content/admin/pseudodevice/add' => sub { - forward '/ajax/content/admin/pseudodevice' - unless _sanity_ok(); + return unless _sanity_ok(); schema('netdisco')->txn_do(sub { my $device = schema('netdisco')->resultset('Device') @@ -47,13 +46,10 @@ ajax '/ajax/content/admin/pseudodevice/add' => sub { map {["Port$_"]} @{[1 .. param('ports')]}, ]); }); - - forward '/ajax/content/admin/pseudodevice'; }; ajax '/ajax/content/admin/pseudodevice/del' => sub { - forward '/ajax/content/admin/pseudodevice' - unless _sanity_ok(); + return unless _sanity_ok(); schema('netdisco')->txn_do(sub { my $device = schema('netdisco')->resultset('Device') @@ -62,13 +58,10 @@ ajax '/ajax/content/admin/pseudodevice/del' => sub { $device->ports->delete; $device->delete; }); - - forward '/ajax/content/admin/pseudodevice'; }; ajax '/ajax/content/admin/pseudodevice/update' => sub { - forward '/ajax/content/admin/pseudodevice' - unless _sanity_ok(); + return unless _sanity_ok(); schema('netdisco')->txn_do(sub { my $device = schema('netdisco')->resultset('Device') @@ -90,8 +83,6 @@ ajax '/ajax/content/admin/pseudodevice/update' => sub { for ($start .. $count); } }); - - forward '/ajax/content/admin/pseudodevice'; }; ajax '/ajax/content/admin/pseudodevice' => sub { diff --git a/Netdisco/lib/App/Netdisco/Web/Plugin/AdminTask/Topology.pm b/Netdisco/lib/App/Netdisco/Web/Plugin/AdminTask/Topology.pm index 0745a1d2..d735d8c4 100644 --- a/Netdisco/lib/App/Netdisco/Web/Plugin/AdminTask/Topology.pm +++ b/Netdisco/lib/App/Netdisco/Web/Plugin/AdminTask/Topology.pm @@ -28,8 +28,7 @@ sub _sanity_ok { } ajax '/ajax/content/admin/topology/add' => sub { - forward '/ajax/content/admin/topology' - unless _sanity_ok(); + return unless _sanity_ok(); my $device = schema('netdisco')->resultset('Topology') ->create({ @@ -38,13 +37,10 @@ ajax '/ajax/content/admin/topology/add' => sub { dev2 => param('dev2'), port2 => param('port2'), }); - - forward '/ajax/content/admin/topology'; }; ajax '/ajax/content/admin/topology/del' => sub { - forward '/ajax/content/admin/topology' - unless _sanity_ok(); + return unless _sanity_ok(); schema('netdisco')->txn_do(sub { my $device = schema('netdisco')->resultset('Topology') @@ -55,8 +51,6 @@ ajax '/ajax/content/admin/topology/del' => sub { port2 => param('port2'), })->delete; }); - - forward '/ajax/content/admin/topology'; }; ajax '/ajax/content/admin/topology' => sub { diff --git a/Netdisco/share/views/js/admintask.js b/Netdisco/share/views/js/admintask.js index 9fcb8483..4bd2d25f 100644 --- a/Netdisco/share/views/js/admintask.js +++ b/Netdisco/share/views/js/admintask.js @@ -3,9 +3,9 @@ var path = 'admin'; // this is called by do_search to support local code - // here, when tab changes need to strike/unstrike the navbar search + // which might need to act on the newly inserted content + // but which cannot use jQuery delegation via .on() function inner_view_processing(tab) { - var target = '#' + tab + '_pane'; // activate typeahead on the topo boxes $('.nd_topo_dev').autocomplete({ @@ -14,10 +14,6 @@ ,minLength: 0 }); - // get all devices on device input focus - $(".nd_topo_dev").on('focus', function(e) { $(this).autocomplete('search', '%') }); - $(".nd_topo_dev_caret").on('click', function(e) { $(this).siblings('.nd_topo_dev').autocomplete('search', '%') }); - // activate typeahead on the topo boxes $('.nd_topo_port.nd_topo_dev1').autocomplete({ source: function (request, response) { @@ -40,10 +36,25 @@ ,delay: 150 ,minLength: 0 }); + } + + // on load, establish global delegations for now and future + $(document).ready(function() { + var tab = '[% task.tag %]' + var target = '#' + tab + '_pane'; + + // get all devices on device input focus + $(target).on('focus', '.nd_topo_dev', function(e) { + $(this).autocomplete('search', '%') }); + $(target).on('click', '.nd_topo_dev_caret', function(e) { + $(this).siblings('.nd_topo_dev').autocomplete('search', '%') }); // get all ports on port input focus - $(".nd_topo_port").on('focus', function(e) { $(this).autocomplete('search') }); - $(".nd_topo_port_caret").on('click', function(e) { $(this).siblings('.nd_topo_port').autocomplete('search') }); + $(target).on('focus', '.nd_topo_port', function(e) { + $(this).autocomplete('search') }); + $(target).on('click', '.nd_topo_port_caret', function(e) { + $(this).siblings('.nd_topo_port').autocomplete('search') }); + // activity for admin task tables // dynamically bind to all forms in the table @@ -54,7 +65,7 @@ // submit the query and put results into the tab pane $.ajax({ type: 'POST' - ,async: false + ,async: true ,dataType: 'html' ,url: uri_base + '/ajax/content/admin/' + tab + '/' + $(this).attr('name') ,data: $(this).serializeArray() @@ -64,7 +75,7 @@ ); } ,success: function(content) { - $(target).html(content); + $('#' + tab + '_form').trigger('submit'); } ,error: function() { $(target).html( @@ -74,8 +85,4 @@ } }); }); - } - - // on load, check initial Device Search Options form state, - // and on each change to the form fields - $(document).ready(function() { }); + });