relocate repo files so ND2 is the only code

This commit is contained in:
Oliver Gorwits
2017-04-14 23:08:55 +01:00
parent 9a016ea6ba
commit d23b32500f
469 changed files with 0 additions and 6920 deletions

182
share/views/js/admintask.js Normal file
View File

@@ -0,0 +1,182 @@
// used by the tabbing interface to make sure the correct
// ajax content is loaded
var path = 'admin';
// keep track of timers so we can kill them
var nd_timers = new Array();
var timermax = [% settings.jobqueue_refresh || 5 | html_entity %];
var timercache = timermax - 1;
// 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) {
// reload this table every 5 seconds
if (tab == 'jobqueue'
&& $('#nd_countdown-control-icon').hasClass('icon-play')) {
$('#nd_countdown').text(timermax);
// add new timers
for (var i = timercache; i > 0; i--) {
nd_timers.push(setTimeout(function() {
$('#nd_countdown').text(timercache);
timercache = timercache - 1;
}, ((timermax * 1000) - (i * 1000)) ));
}
nd_timers.push(setTimeout(function() {
// clear any running timers
for (var i = 0; i < nd_timers.length; i++) {
clearTimeout(nd_timers[i]);
}
// reset the timer cache
timercache = timermax - 1;
// reload the tab content in...
$('#' + tab + '_form').trigger('submit');
}, (timermax * 1000)));
}
// activate typeahead on the topo boxes
$('.nd_topo_dev').autocomplete({
source: uri_base + '/ajax/data/deviceip/typeahead'
,delay: 150
,minLength: 0
});
// activate typeahead on the topo boxes
$('.nd_topo_port.nd_topo_dev1').autocomplete({
source: function (request, response) {
var query = $('.nd_topo_dev1').serialize();
return $.get( uri_base + '/ajax/data/port/typeahead', query, function (data) {
return response(data);
});
}
,delay: 150
,minLength: 0
});
// activate typeahead on the topo boxes
$('.nd_topo_port.nd_topo_dev2').autocomplete({
source: function (request, response) {
var query = $('.nd_topo_dev2').serialize();
return $.get( uri_base + '/ajax/data/port/typeahead', query, function (data) {
return response(data);
});
}
,delay: 150
,minLength: 0
});
// activate modals
$('.nd_modal').modal({show: false});
}
// 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
$(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').val('');
$(this).siblings('.nd_topo_port').autocomplete('search');
});
// job control refresh icon should reload the page
$('#nd_countdown-refresh').click(function(event) {
event.preventDefault();
for (var i = 0; i < nd_timers.length; i++) {
clearTimeout(nd_timers[i]);
}
$('#' + tab + '_form').trigger('submit');
});
// job control pause/play icon switcheroo
$('#nd_countdown-control').click(function(event) {
event.preventDefault();
var icon = $('#nd_countdown-control-icon');
icon.toggleClass('icon-pause icon-play text-error text-success');
if (icon.hasClass('icon-pause')) {
for (var i = 0; i < nd_timers.length; i++) {
clearTimeout(nd_timers[i]);
}
$('#nd_countdown').text('0');
}
else {
$('#' + tab + '_form').trigger('submit');
}
});
// activity for admin task tables
// dynamically bind to all forms in the table
$('.content').on('click', '.nd_adminbutton', function(event) {
// stop form from submitting normally
event.preventDefault();
// clear any running timers
for (var i = 0; i < nd_timers.length; i++) {
clearTimeout(nd_timers[i]);
}
// what purpose - add/update/del
var mode = $(this).attr('name');
// submit the query and put results into the tab pane
$.ajax({
type: 'POST'
,async: true
,dataType: 'html'
,url: uri_base + '/ajax/control/admin/' + tab + '/' + mode
,data: $(this).closest('tr').find('input[data-form="' + mode + '"]').serializeArray()
,beforeSend: function() {
$(target).html(
'<div class="span2 alert">Request submitted...</div>'
);
}
,success: function() {
$('#' + tab + '_form').trigger('submit');
}
// skip any error reporting for now
// TODO: fix sanity_ok in Netdisco Web
,error: function() {
$('#' + tab + '_form').trigger('submit');
}
});
});
// bind qtip2 to show the event log output
$(target).on('mouseover', '.nd_jobqueueitem', function(event) {
$(this).qtip({
overwrite: false,
content: {
attr: 'data-content'
},
show: {
event: event.type,
ready: true,
delay: 100
},
position: {
my: 'top center',
at: 'bottom center',
target: false
},
style: {
classes: 'qtip-cluetip qtip-rounded nd_qtip-unconstrained'
}
});
});
});

15
share/views/js/bootstrap-tree.js vendored Normal file
View File

@@ -0,0 +1,15 @@
$(document).ready(function() {
$('.tree > ul').attr('role', 'tree').find('ul').attr('role', 'group');
$('.tree').find('li:has(ul)').addClass('parent_li').attr('role', 'treeitem').find(' > span').attr('title', 'Collapse this branch').on('click', function (e) {
var children = $(this).parent('li.parent_li').find(' > ul > li');
if (children.is(':visible')) {
children.hide('fast');
$(this).attr('title', 'Expand this branch').find(' > i').addClass('icon-plus-sign').removeClass('icon-minus-sign');
}
else {
children.show('fast');
$(this).attr('title', 'Collapse this branch').find(' > i').addClass('icon-minus-sign').removeClass('icon-plus-sign');
}
e.stopPropagation();
});
});

149
share/views/js/common.js Normal file
View File

@@ -0,0 +1,149 @@
// csv download icon on any table page
// needs to be dynamically updated to use current search options
function update_csv_download_link (type, tab, show) {
var form = '#' + tab + '_form';
var query = $(form).serialize();
if (show.length) {
$('#nd_csv-download')
.attr('href', uri_base + '/ajax/content/' + type + '/' + tab + '?' + query)
.attr('download', 'netdisco-' + type + '-' + tab + '.csv')
.show();
}
else {
$('#nd_csv-download').hide();
}
}
// page title includes tab name and possibly device name
// this is nice for when you have multiple netdisco pages open in the
// browser
function update_page_title (tab) {
var pgtitle = 'Netdisco';
if ($.trim($('#nd_device-name').text()).length) {
pgtitle = $.trim($('#nd_device-name').text()) +' - '+ $('#'+ tab + '_link').text();
}
return pgtitle;
}
// update browser search history with the new query.
// support history add (push) or replace via push parameter
function update_browser_history (tab, pgtitle, push) {
var form = '#' + tab + '_form';
var query = $(form).serialize();
if (query.length) { query = '?' + query }
if (window.History && window.History.enabled) {
is_from_history_plugin = 1;
if (push.length) {
var target = uri_base + '/' + path + '/' + tab + query;
if (location.pathname == target) { return };
window.History.pushState(
{name: tab, fields: $(form).serializeArray()}, pgtitle, target
);
}
else {
var target = uri_base + '/' + path + query;
window.History.replaceState(
{name: tab, fields: $(form).serializeArray()}, pgtitle, target
);
}
is_from_history_plugin = 0;
}
}
// each sidebar search form has a hidden copy of the main navbar search
function copy_navbar_to_sidebar (tab) {
var form = '#' + tab + '_form';
// copy navbar value to currently active sidebar form
if ($('#nq').val()) {
$(form).find("input[name=q]").val( $('#nq').val() );
}
// then copy to all other inactive tab sidebars
$('form').find("input[name=q]").each( function() {
$(this).val( $(form).find("input[name=q]").val() );
});
}
$(document).ready(function() {
[% IF search %]
// search tabs
[% FOREACH tab IN settings._search_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('search', '[% tab.tag %]', '[% tab.provides_csv %]');
do_search(event, '[% tab.tag %]');
});
[% END %]
[% END %]
[% IF device %]
// 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=[% 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=[% tab.tag %]&reset=on&' +
$('#netmap_form').find('input[name="q"]').serialize());
[% END %]
do_search(event, '[% tab.tag %]');
});
[% END %]
[% END %]
[% IF report %]
// for the report pages
$('[% "#${report.tag}_form" %]').submit(function (event) {
var pgtitle = update_page_title('[% report.tag %]');
update_browser_history('[% report.tag %]', pgtitle, '1');
update_csv_download_link('report', '[% report.tag %]', '1');
do_search(event, '[% report.tag %]');
});
[% END -%]
[% IF task %]
// for the admin pages
$('[% "#${task.tag}_form" %]').submit(function (event) {
update_page_title('[% task.tag %]');
update_csv_download_link('admin', '[% task.tag %]', '1');
do_search(event, '[% task.tag %]');
});
[% END %]
// on page load, load the content for the active tab
[% IF params.tab %]
[% IF params.tab == 'ipinventory' OR params.tab == 'subnets' %]
$('#[% params.tab %]_submit').click();
[% ELSE %]
$('#[% params.tab %]_form').trigger("submit");
[% END %]
[% END %]
});

135
share/views/js/device.js Normal file
View File

@@ -0,0 +1,135 @@
// 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');
}
});
// 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);
});
});

86
share/views/js/report.js Normal file
View File

@@ -0,0 +1,86 @@
// used by the tabbing interface to make sure the correct
// ajax content is loaded
var path = 'report';
// colored input fields in the Report Options sidebar forms
var form_inputs = $(".nd_colored-input");
// 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) {
// activate modals, tooltips and popovers
$('.nd_modal').modal({show: false});
$("[rel=tooltip]").tooltip({live: true});
$("[rel=popover]").popover({live: true});
}
// on load, check initial Report Options form state,
// and on each change to the form fields
$(document).ready(function() {
var tab = '[% report.tag %]'
var target = '#' + tab + '_pane';
// sidebar form fields should change colour and have trash icon
form_inputs.each(function() {device_form_state($(this))});
form_inputs.change(function() {device_form_state($(this))});
// handler for bin icon in search forms
$('.nd_field-clear-icon').click(function() {
var name = $(this).data('btn-for');
var input = $('[name=' + name + ']');
input.val('');
device_form_state(input); // reset input field
});
$('#nd_ipinventory-subnet').on('input', function(event) {
if ($(this).val().indexOf(':') != -1) {
$('#never').attr('disabled', 'disabled');
}
else {
$('#never').removeAttr('disabled');
}
});
// activate typeahead on prefix/subnet box
$('#nd_ipinventory-subnet').autocomplete({
source: function (request, response) {
return $.get( uri_base + '/ajax/data/subnet/typeahead', request, function (data) {
return response(data);
});
}
,delay: 150
,minLength: 3
});
// dynamically bind to all forms in the table
$('.content').on('click', '.nd_adminbutton', function(event) {
// stop form from submitting normally
event.preventDefault();
// what purpose - add/update/del
var mode = $(this).attr('name');
// submit the query and put results into the tab pane
$.ajax({
type: 'POST'
,async: true
,dataType: 'html'
,url: uri_base + '/ajax/control/report/' + tab + '/' + mode
,data: $(this).closest('tr').find('input[data-form="' + mode + '"]').serializeArray()
,beforeSend: function() {
$(target).html(
'<div class="span2 alert">Request submitted...</div>'
);
}
,success: function() {
$('#' + tab + '_form').trigger('submit');
}
// skip any error reporting for now
// TODO: fix sanity_ok in Netdisco Web
,error: function() {
$('#' + tab + '_form').trigger('submit');
}
});
});
});

39
share/views/js/search.js Normal file
View File

@@ -0,0 +1,39 @@
// used by the tabbing interface to make sure the correct
// ajax content is loaded
var path = 'search';
// fields in the Device Search Options form (Device tab)
var form_inputs = $("#device_form .clearfix input").not('[type="checkbox"]')
.add("#device_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) {
}
// on load, establish global delegations for now and future
$(document).ready(function() {
var tab = '[% tab.tag %]'
var target = '#' + tab + '_pane';
// sidebar form fields should change colour and have bin/copy icon
form_inputs.each(function() {device_form_state($(this))});
form_inputs.change(function() {device_form_state($(this))});
// handler for copy icon in search option
$('.nd_field-copy-icon').click(function() {
var name = $(this).data('btn-for');
var input = $('#device_form [name=' + name + ']');
input.val( $('#nq').val() );
device_form_state(input); // will hide copy icons
});
// handler for bin icon in search option
$('.nd_field-clear-icon').click(function() {
var name = $(this).data('btn-for');
var input = $('#device_form [name=' + name + ']');
input.val('');
device_form_state(input); // will hide copy icons
});
});