The reason for this is that DataTables keys local data on the page path, so each tab should have its own path. We're already doing this for reports and admin tasks, so it also makes sense to have consistency with search and device tabs. Squashed commit of the following: commit 4ad33a23a81122496adfe561ad14f039e6255eff Author: Oliver Gorwits <oliver@cpan.org> Date: Sat Oct 25 14:46:17 2014 +0100 fix search preference selection commit 363e094935d386961e8773f787af41c46b83129a Author: Oliver Gorwits <oliver@cpan.org> Date: Sat Oct 25 14:36:45 2014 +0100 fix css selector to match begins with /search commit 43c972ee0d9401f74dcc3bd30052dba130b0d068 Author: Oliver Gorwits <oliver@cpan.org> Date: Sat Oct 25 14:18:24 2014 +0100 fix history push commit 84f83eb46874b0222c0484014389713e4f027c8a Author: Oliver Gorwits <oliver@cpan.org> Date: Sat Oct 25 14:06:44 2014 +0100 update sidebar form for tab-path, remove hidden tab name field commit 344d4679a83f714c998cd475c041f8effab0c696 Author: Oliver Gorwits <oliver@cpan.org> Date: Sat Oct 25 14:05:49 2014 +0100 update template links for tab path commit 9cf370d7eb4413aac6fc19c2c13a9bf670600965 Author: Oliver Gorwits <oliver@cpan.org> Date: Sat Oct 25 14:04:57 2014 +0100 move tab-specific JS from common into specific includes files commit c2d8592a18e389535368d1e74fed29fe5a0eabd8 Author: Oliver Gorwits <oliver@cpan.org> Date: Sat Oct 25 14:02:46 2014 +0100 fix mode commit 52487cea47eaaea7f5c74536ad6d4bb2a8d6ba4c Author: Oliver Gorwits <oliver@cpan.org> Date: Sat Oct 25 14:01:15 2014 +0100 move from tab param to tabname template var commit b5a2424631a0050d5de3bc658746a40cd822e869 Merge:531782bd8102bfAuthor: Oliver Gorwits <oliver@cpan.org> Date: Sat Oct 25 10:50:00 2014 +0100 Merge branch 'master' into em-device-ports-json
177 lines
6.8 KiB
JavaScript
177 lines
6.8 KiB
JavaScript
// used by the tabbing interface to make sure the correct
|
|
// ajax content is loaded
|
|
var path = 'device';
|
|
|
|
// fields in the Device Search Options form (Device tab)
|
|
var form_inputs = $("#ports_form .clearfix input").not('[type="checkbox"]')
|
|
.add("#ports_form .clearfix select");
|
|
|
|
// this is called by do_search to support local code
|
|
// which might need to act on the newly inserted content
|
|
// but which cannot use jQuery delegation via .on()
|
|
function inner_view_processing(tab) {
|
|
|
|
// LT wanted the page title to reflect what's on the page :)
|
|
document.title = $('#nd_device-name').text()
|
|
+' - '+ $('#'+ tab + '_link').text();
|
|
|
|
// used for contenteditable cells to find out whether the user has made
|
|
// changes, and only reset when they submit or cancel the change
|
|
var dirty = false;
|
|
|
|
// activate modals, tooltips and popovers
|
|
$('.nd_modal').modal({show: false});
|
|
$("[rel=tooltip]").tooltip({live: true});
|
|
$("[rel=popover]").popover({live: true});
|
|
}
|
|
|
|
// on load, establish global delegations for now and future
|
|
$(document).ready(function() {
|
|
var tab = '[% tab.tag %]'
|
|
var target = '#' + tab + '_pane';
|
|
var portfilter = $('#ports_form').find("input[name=f]");
|
|
|
|
// sidebar form fields should change colour and have trash/copy icon
|
|
form_inputs.each(function() {device_form_state($(this))});
|
|
form_inputs.change(function() {device_form_state($(this))});
|
|
|
|
// sidebar collapser events trigger change of up/down arrow
|
|
$('.collapse').on('show', function() {
|
|
$(this).siblings().find('.nd_arrow-up-down-right')
|
|
.toggleClass('icon-chevron-up icon-chevron-down');
|
|
});
|
|
|
|
$('.collapse').on('hide', function() {
|
|
$(this).siblings().find('.nd_arrow-up-down-right')
|
|
.toggleClass('icon-chevron-up icon-chevron-down');
|
|
});
|
|
|
|
// if the user edits the filter box, revert to automagical search
|
|
$('#ports_form').on('input', "input[name=f]", function() {
|
|
$('#nd_ports-form-prefer-field').attr('value', '');
|
|
});
|
|
|
|
// handler for trashcan icon in port filter box
|
|
$('.nd_field-clear-icon').click(function() {
|
|
portfilter.val('');
|
|
$('#nd_ports-form-prefer-field').attr('value', '');
|
|
$('#ports_form').trigger('submit');
|
|
device_form_state(portfilter); // will hide copy icons
|
|
});
|
|
|
|
// allow port filter to have a preference for port/name/vlan
|
|
$('#ports_form').on('click', '.nd_device-port-submit-prefer', function() {
|
|
event.preventDefault();
|
|
$('#nd_ports-form-prefer-field').attr('value', $(this).data('prefer'));
|
|
$(this).parents('form').submit();
|
|
});
|
|
|
|
// clickable device port names can simply resubmit AJAX rather than
|
|
// fetch the whole page again.
|
|
$('#ports_pane').on('click', '.nd_this-port-only', function(event) {
|
|
event.preventDefault(); // link is real so prevent page submit
|
|
|
|
var port = $(this).text();
|
|
port = $.trim(port);
|
|
portfilter.val(port);
|
|
$('.nd_field-clear-icon').show();
|
|
|
|
// make sure we're preferring a port filter
|
|
$('#nd_ports-form-prefer-field').attr('value', 'port');
|
|
|
|
$('#ports_form').trigger('submit');
|
|
device_form_state(portfilter); // will hide copy icons
|
|
});
|
|
|
|
// VLANs column list collapser trigger
|
|
// it's a bit of a faff because we can't easily use Bootstrap's collapser
|
|
$('#ports_pane').on('click', '.nd_collapse-vlans', function() {
|
|
$(this).siblings('.nd_collapsing').toggle();
|
|
if ($(this).find('.nd_arrow-up-down-left').hasClass('icon-chevron-up')) {
|
|
$(this).html('<div class="nd_arrow-up-down-left icon-chevron-down icon-large"></div>Hide VLANs');
|
|
}
|
|
else {
|
|
$(this).html('<div class="nd_arrow-up-down-left icon-chevron-up icon-large"></div>Show VLANs');
|
|
}
|
|
});
|
|
|
|
// dynamic show/hide data in device ports connected nodes/devices column
|
|
$('#ports_form').on('change', "input[type=checkbox].nd_dynamic-dp", function(event) {
|
|
var target = $(this).attr('id');
|
|
$('span.' + target).toggle();
|
|
});
|
|
|
|
// activity for admin tasks in device details
|
|
$('#details_pane').on('click', '.nd_adminbutton', function(event) {
|
|
// stop form from submitting normally
|
|
event.preventDefault();
|
|
|
|
// what purpose - discover/macsuck/arpnip
|
|
var mode = $(this).attr('name');
|
|
var tr = $(this).closest('tr');
|
|
|
|
// submit the query
|
|
$.ajax({
|
|
type: 'POST'
|
|
,async: true
|
|
,dataType: 'html'
|
|
,url: uri_base + '/ajax/control/admin/' + mode
|
|
,data: tr.find('input[data-form="' + mode + '"],textarea[data-form="' + mode + '"]').serializeArray()
|
|
,success: function() {
|
|
if (mode != 'delete') {
|
|
toastr.info('Requested '+ mode +' for device '+ tr.data('for-device'));
|
|
}
|
|
else {
|
|
toastr.success('Deleted device '+ tr.data('for-device'));
|
|
}
|
|
}
|
|
// skip any error reporting for now
|
|
// TODO: fix sanity_ok in Netdisco Web
|
|
,error: function() {
|
|
toastr.error('Failed to '+ mode +' device '+ tr.data('for-device'));
|
|
}
|
|
});
|
|
});
|
|
|
|
// clear any values in the delete confirm dialog
|
|
$('#details_pane').on('hidden', '.nd_modal', function () {
|
|
$('#nd_devdel-log').val('');
|
|
$('#nd_devdel-archive').attr('checked', false);
|
|
});
|
|
|
|
// device tabs
|
|
[% FOREACH tab IN settings._device_tabs %]
|
|
$('[% "#${tab.tag}_form" %]').submit(function (event) {
|
|
var pgtitle = update_page_title('[% tab.tag %]');
|
|
copy_navbar_to_sidebar('[% tab.tag %]');
|
|
update_browser_history('[% tab.tag %]', pgtitle, '');
|
|
update_csv_download_link('device', '[% tab.tag %]', '[% tab.provides_csv %]');
|
|
|
|
[% IF tab.tag == 'ports' %]
|
|
// to be fair I can't remember why we do this in JS and not from the app
|
|
// perhaps because selecting form fields to go in the cookie is easier?
|
|
var cookie = $('#ports_form').find('input,select')
|
|
.not('#nd_port-query,input[name="q"],input[name="tab"]')
|
|
.serializeArray();
|
|
$('#ports_form').find('input[type="checkbox"]').map(function() {
|
|
cookie.push({'name': 'columns', 'value': $(this).attr('name')});
|
|
});
|
|
$.cookie('nd_ports-form', $.param(cookie) ,{ expires: 365 });
|
|
|
|
// form reset icon on ports tab
|
|
$('#nd_sidebar-reset-link').attr('href', uri_base + '/device/[% tab.tag %]?reset=on&' +
|
|
$('#ports_form')
|
|
.find('input[name="q"],input[name="f"],input[name="partial"],input[name="invert"]')
|
|
.serialize());
|
|
|
|
[% ELSIF tab.tag == 'netmap' %]
|
|
// form reset icon on netmap tab
|
|
$('#nd_sidebar-reset-link').attr('href', uri_base + '/device/[% tab.tag %]?reset=on&' +
|
|
$('#netmap_form').find('input[name="q"]').serialize());
|
|
[% END %]
|
|
|
|
do_search(event, '[% tab.tag %]');
|
|
});
|
|
[% END %]
|
|
});
|