fix crazy races with javasacript by using global delegations
This commit is contained in:
@@ -29,8 +29,7 @@ sub _sanity_ok {
|
|||||||
}
|
}
|
||||||
|
|
||||||
ajax '/ajax/content/admin/pseudodevice/add' => sub {
|
ajax '/ajax/content/admin/pseudodevice/add' => sub {
|
||||||
forward '/ajax/content/admin/pseudodevice'
|
return unless _sanity_ok();
|
||||||
unless _sanity_ok();
|
|
||||||
|
|
||||||
schema('netdisco')->txn_do(sub {
|
schema('netdisco')->txn_do(sub {
|
||||||
my $device = schema('netdisco')->resultset('Device')
|
my $device = schema('netdisco')->resultset('Device')
|
||||||
@@ -47,13 +46,10 @@ ajax '/ajax/content/admin/pseudodevice/add' => sub {
|
|||||||
map {["Port$_"]} @{[1 .. param('ports')]},
|
map {["Port$_"]} @{[1 .. param('ports')]},
|
||||||
]);
|
]);
|
||||||
});
|
});
|
||||||
|
|
||||||
forward '/ajax/content/admin/pseudodevice';
|
|
||||||
};
|
};
|
||||||
|
|
||||||
ajax '/ajax/content/admin/pseudodevice/del' => sub {
|
ajax '/ajax/content/admin/pseudodevice/del' => sub {
|
||||||
forward '/ajax/content/admin/pseudodevice'
|
return unless _sanity_ok();
|
||||||
unless _sanity_ok();
|
|
||||||
|
|
||||||
schema('netdisco')->txn_do(sub {
|
schema('netdisco')->txn_do(sub {
|
||||||
my $device = schema('netdisco')->resultset('Device')
|
my $device = schema('netdisco')->resultset('Device')
|
||||||
@@ -62,13 +58,10 @@ ajax '/ajax/content/admin/pseudodevice/del' => sub {
|
|||||||
$device->ports->delete;
|
$device->ports->delete;
|
||||||
$device->delete;
|
$device->delete;
|
||||||
});
|
});
|
||||||
|
|
||||||
forward '/ajax/content/admin/pseudodevice';
|
|
||||||
};
|
};
|
||||||
|
|
||||||
ajax '/ajax/content/admin/pseudodevice/update' => sub {
|
ajax '/ajax/content/admin/pseudodevice/update' => sub {
|
||||||
forward '/ajax/content/admin/pseudodevice'
|
return unless _sanity_ok();
|
||||||
unless _sanity_ok();
|
|
||||||
|
|
||||||
schema('netdisco')->txn_do(sub {
|
schema('netdisco')->txn_do(sub {
|
||||||
my $device = schema('netdisco')->resultset('Device')
|
my $device = schema('netdisco')->resultset('Device')
|
||||||
@@ -90,8 +83,6 @@ ajax '/ajax/content/admin/pseudodevice/update' => sub {
|
|||||||
for ($start .. $count);
|
for ($start .. $count);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
forward '/ajax/content/admin/pseudodevice';
|
|
||||||
};
|
};
|
||||||
|
|
||||||
ajax '/ajax/content/admin/pseudodevice' => sub {
|
ajax '/ajax/content/admin/pseudodevice' => sub {
|
||||||
|
|||||||
@@ -28,8 +28,7 @@ sub _sanity_ok {
|
|||||||
}
|
}
|
||||||
|
|
||||||
ajax '/ajax/content/admin/topology/add' => sub {
|
ajax '/ajax/content/admin/topology/add' => sub {
|
||||||
forward '/ajax/content/admin/topology'
|
return unless _sanity_ok();
|
||||||
unless _sanity_ok();
|
|
||||||
|
|
||||||
my $device = schema('netdisco')->resultset('Topology')
|
my $device = schema('netdisco')->resultset('Topology')
|
||||||
->create({
|
->create({
|
||||||
@@ -38,13 +37,10 @@ ajax '/ajax/content/admin/topology/add' => sub {
|
|||||||
dev2 => param('dev2'),
|
dev2 => param('dev2'),
|
||||||
port2 => param('port2'),
|
port2 => param('port2'),
|
||||||
});
|
});
|
||||||
|
|
||||||
forward '/ajax/content/admin/topology';
|
|
||||||
};
|
};
|
||||||
|
|
||||||
ajax '/ajax/content/admin/topology/del' => sub {
|
ajax '/ajax/content/admin/topology/del' => sub {
|
||||||
forward '/ajax/content/admin/topology'
|
return unless _sanity_ok();
|
||||||
unless _sanity_ok();
|
|
||||||
|
|
||||||
schema('netdisco')->txn_do(sub {
|
schema('netdisco')->txn_do(sub {
|
||||||
my $device = schema('netdisco')->resultset('Topology')
|
my $device = schema('netdisco')->resultset('Topology')
|
||||||
@@ -55,8 +51,6 @@ ajax '/ajax/content/admin/topology/del' => sub {
|
|||||||
port2 => param('port2'),
|
port2 => param('port2'),
|
||||||
})->delete;
|
})->delete;
|
||||||
});
|
});
|
||||||
|
|
||||||
forward '/ajax/content/admin/topology';
|
|
||||||
};
|
};
|
||||||
|
|
||||||
ajax '/ajax/content/admin/topology' => sub {
|
ajax '/ajax/content/admin/topology' => sub {
|
||||||
|
|||||||
@@ -3,9 +3,9 @@
|
|||||||
var path = 'admin';
|
var path = 'admin';
|
||||||
|
|
||||||
// this is called by do_search to support local code
|
// 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) {
|
function inner_view_processing(tab) {
|
||||||
var target = '#' + tab + '_pane';
|
|
||||||
|
|
||||||
// activate typeahead on the topo boxes
|
// activate typeahead on the topo boxes
|
||||||
$('.nd_topo_dev').autocomplete({
|
$('.nd_topo_dev').autocomplete({
|
||||||
@@ -14,10 +14,6 @@
|
|||||||
,minLength: 0
|
,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
|
// activate typeahead on the topo boxes
|
||||||
$('.nd_topo_port.nd_topo_dev1').autocomplete({
|
$('.nd_topo_port.nd_topo_dev1').autocomplete({
|
||||||
source: function (request, response) {
|
source: function (request, response) {
|
||||||
@@ -40,10 +36,25 @@
|
|||||||
,delay: 150
|
,delay: 150
|
||||||
,minLength: 0
|
,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
|
// get all ports on port input focus
|
||||||
$(".nd_topo_port").on('focus', function(e) { $(this).autocomplete('search') });
|
$(target).on('focus', '.nd_topo_port', function(e) {
|
||||||
$(".nd_topo_port_caret").on('click', function(e) { $(this).siblings('.nd_topo_port').autocomplete('search') });
|
$(this).autocomplete('search') });
|
||||||
|
$(target).on('click', '.nd_topo_port_caret', function(e) {
|
||||||
|
$(this).siblings('.nd_topo_port').autocomplete('search') });
|
||||||
|
|
||||||
|
|
||||||
// activity for admin task tables
|
// activity for admin task tables
|
||||||
// dynamically bind to all forms in the table
|
// dynamically bind to all forms in the table
|
||||||
@@ -54,7 +65,7 @@
|
|||||||
// submit the query and put results into the tab pane
|
// submit the query and put results into the tab pane
|
||||||
$.ajax({
|
$.ajax({
|
||||||
type: 'POST'
|
type: 'POST'
|
||||||
,async: false
|
,async: true
|
||||||
,dataType: 'html'
|
,dataType: 'html'
|
||||||
,url: uri_base + '/ajax/content/admin/' + tab + '/' + $(this).attr('name')
|
,url: uri_base + '/ajax/content/admin/' + tab + '/' + $(this).attr('name')
|
||||||
,data: $(this).serializeArray()
|
,data: $(this).serializeArray()
|
||||||
@@ -64,7 +75,7 @@
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
,success: function(content) {
|
,success: function(content) {
|
||||||
$(target).html(content);
|
$('#' + tab + '_form').trigger('submit');
|
||||||
}
|
}
|
||||||
,error: function() {
|
,error: function() {
|
||||||
$(target).html(
|
$(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() { });
|
|
||||||
|
|||||||
Reference in New Issue
Block a user