Files
librenms-librenms/html/js/librenms.js

423 lines
12 KiB
JavaScript
Raw Normal View History

2015-11-17 05:14:41 -08:00
function override_config(event, state, tmp_this) {
event.preventDefault();
var $this = tmp_this;
var attrib = $this.data('attrib');
var device_id = $this.data('device_id');
$.ajax({
type: 'POST',
url: 'ajax_form.php',
data: { type: 'override-config', device_id: device_id, attrib: attrib, state: state },
dataType: 'json',
success: function(data) {
if (data.status == 'ok') {
toastr.success(data.message);
}
else {
toastr.error(data.message);
}
},
error: function() {
toastr.error('Could not set this override');
}
});
}
var oldH;
var oldW;
2015-10-10 13:49:09 +00:00
$(document).ready(function() {
// Device override ajax calls
2015-10-10 13:49:09 +00:00
$("[name='override_config']").bootstrapSwitch('offColor','danger');
$('input[name="override_config"]').on('switchChange.bootstrapSwitch', function(event, state) {
2015-11-17 05:14:41 -08:00
override_config(event,state,$(this));
});
// Device override for text inputs
$(document).on('blur', 'input[name="override_config_text"]', function(event) {
event.preventDefault();
var $this = $(this);
var attrib = $this.data('attrib');
var device_id = $this.data('device_id');
var value = $this.val();
$.ajax({
type: 'POST',
url: 'ajax_form.php',
data: { type: 'override-config', device_id: device_id, attrib: attrib, state: value },
dataType: 'json',
success: function(data) {
if (data.status == 'ok') {
toastr.success(data.message);
}
else {
toastr.error(data.message);
}
},
error: function() {
toastr.error('Could not set this override');
2015-10-10 13:49:09 +00:00
}
});
});
// Checkbox config ajax calls
$("[name='global-config-check']").bootstrapSwitch('offColor','danger');
$('input[name="global-config-check"]').on('switchChange.bootstrapSwitch', function(event, state) {
event.preventDefault();
var $this = $(this);
var config_id = $this.data("config_id");
$.ajax({
type: 'POST',
url: 'ajax_form.php',
data: {type: "update-config-item", config_id: config_id, config_value: state},
dataType: "json",
success: function (data) {
if (data.status == 'ok') {
toastr.success('Config updated');
} else {
toastr.error(data.message);
}
},
error: function () {
toastr.error(data.message);
}
});
});
// Input field config ajax calls
$(document).on('blur', 'input[name="global-config-input"]', function(event) {
event.preventDefault();
var $this = $(this);
var config_id = $this.data("config_id");
var config_value = $this.val();
2018-01-05 16:04:47 +01:00
if ($this[0].checkValidity()) {
$.ajax({
type: 'POST',
url: 'ajax_form.php',
data: {type: "update-config-item", config_id: config_id, config_value: config_value},
dataType: "json",
success: function (data) {
if (data.status == 'ok') {
toastr.success('Config updated');
} else {
toastr.error(data.message);
}
},
error: function () {
toastr.error(data.message);
}
});
}
});
// Select config ajax calls
$( 'select[name="global-config-select"]').change(function(event) {
event.preventDefault();
var $this = $(this);
var config_id = $this.data("config_id");
var config_value = $this.val();
$.ajax({
type: 'POST',
url: 'ajax_form.php',
data: {type: "update-config-item", config_id: config_id, config_value: config_value},
dataType: "json",
success: function (data) {
if (data.status == 'ok') {
toastr.success('Config updated');
} else {
toastr.error(data.message);
}
},
error: function () {
toastr.error(data.message);
}
});
});
oldW=$(window).width();
oldH=$(window).height();
2015-10-10 13:49:09 +00:00
});
function submitCustomRange(frmdata) {
var reto = /to=([0-9a-zA-Z\-])+/g;
var refrom = /from=([0-9a-zA-Z\-])+/g;
var tsto = moment(frmdata.dtpickerto.value).unix();
var tsfrom = moment(frmdata.dtpickerfrom.value).unix();
frmdata.selfaction.value = frmdata.selfaction.value.replace(reto, 'to=' + tsto);
frmdata.selfaction.value = frmdata.selfaction.value.replace(refrom, 'from=' + tsfrom);
frmdata.action = frmdata.selfaction.value;
return true;
}
function updateResolution(refresh)
2015-11-20 12:02:51 +00:00
{
Add Laravel to LibreNMS (#8318) * Add Laravel to LibreNMS. * Try to set permissions during initial install and first composer update to Laravel. * Fix composer.lock Fix missing db config keys * Start building v1 layout Port ajax_setresolution, inject csrf into jquery ajax calls Layout works, building menu Partially done. * Fix device group list remove stupid count relationships * Print messages for common boot errors. Don't log to laravel.log file. Log to error_log until booted, then librenms.log * Fix up some issues with Config loading Start of custom directives * Custom blade directives: config, notconfig, admin * Preflight checks Only load config files once. * Update the composer.lock for php 5.6 * Menu through routing * Start of alert menu * Better alert scopes * reduce cruft in models * Alerting menu more or less working :D * Fix style * Improved preflight * Fix chicken-eggs! * Remove examples * Better alert_rule status queries Debugbar * fix app.env check * User Menu * Settings bar (dropped refresh) Search JS * Toastr messages * Rename preflight * Use hasAccess(User) on most models. Add port counts * Missed a Preflight -> Checks rename * Fix some formatting * Boot Eloquent outside of Laravel Use Eloquent for Config and Plugins so we don't have to connect with dbFacile inside Laravel. Move locate_binary() into Config class * Config WIP * Try to fix a lot of config loading issues. * Improve menu for non-admins removing unneeded menus url() for all in menu * Only use eloquent if it exists * Include APP_URL in initial .env settings * Implement Legacy User Provider * Helper class for using Eloquent outside of Laravel. Allows access to DB style queries too and checking the connection status. * Fix up tests * Fix device groups query * Checking Travis * copy config.test.php earlier * dbFacile check config before connecting Don't use exception to check if eloquent is connected, it gets grabbed by the exception handler. Ignore missing config.php error. * Fix config load with database is not migrated yet. * Remove Config::load() from early boot. * Use laravel config settings to init db (this prefers .env settings) Fix bgp vars not set in menu add _ide_helper.php to .gitignore * Restrict dependencies to versions that support php 5.6 * Update ConfigTest * Fix a couple of installation issues * Add unique NODE_ID to .env * Correct handling of title image * Fix database config not loading. Thanks @laf * Don't prepend / * add class_exists checks for development service providers * Fix config value casting * Don't use functions that may not exist * Update dbFacile.php * d_echo may not be defined when Config used called. * Add SELinux configuration steps More detailed permissions check. Check all and give complete corrective commands in one step. * Ignore node_modules directory * Re-add accidetal removal
2018-05-09 08:05:17 -05:00
$.post('ajax/set_resolution',
{
width: $(window).width(),
height:$(window).height()
},
function(data) {
if(refresh == true) {
location.reload();
}
},'json'
2015-11-20 12:02:51 +00:00
);
}
var rtime;
var timeout = false;
var delta = 500;
var newH;
var newW;
$(window).on('resize', function(){
rtime = new Date();
if (timeout === false && !(typeof no_refresh === 'boolean' && no_refresh === true)) {
timeout = true;
setTimeout(resizeend, delta);
}
});
function resizeend() {
if (new Date() - rtime < delta) {
setTimeout(resizeend, delta);
2018-01-05 16:04:47 +01:00
}
else {
newH=$(window).height();
newW=$(window).width();
timeout = false;
if(Math.abs(oldW - newW) >= 200)
{
refresh = true;
}
else {
refresh = false;
resizeGraphs();
}
updateResolution(refresh);
2018-01-05 16:04:47 +01:00
}
};
2015-11-20 12:02:51 +00:00
function resizeGraphs() {
ratioW=newW/oldW;
ratioH=newH/oldH;
$('.graphs').each(function (){
var img = jQuery(this);
img.attr('width',img.width() * ratioW);
});
oldH=newH;
oldW=newW;
}
$(document).on("click", '.collapse-neighbors', function(event)
{
var caller = $(this);
var button = caller.find('.neighbors-button');
var list = caller.find('.neighbors-interface-list');
var continued = caller.find('.neighbors-list-continued');
if(button.hasClass("fa-plus")) {
button.addClass('fa-minus').removeClass('fa-plus');
2015-11-20 14:47:59 +00:00
}
else {
button.addClass('fa-plus').removeClass('fa-minus');
}
2018-01-05 16:04:47 +01:00
list.toggle();
continued.toggle();
});
//availability-map mode change
2016-08-12 22:51:29 +03:00
$(document).on("change", '#mode', function() {
$.post('ajax_mapview.php',
{
map_view: $(this).val()
2016-08-12 22:51:29 +03:00
},
function(data) {
location.reload();
},'json'
);
});
//availability-map device group
$(document).on("change", '#group', function() {
$.post('ajax_mapview.php',
{
group_view: $(this).val()
},
function(data){
location.reload();
},'json'
);
});
$(document).ready(function() {
var lines = 'on';
$("#linenumbers").button().click(function() {
if (lines == 'on') {
$($('.config').find('ol').get().reverse()).each(function(){
$(this).replaceWith($('<ul>'+$(this).html()+'</ul>'))
lines = 'off';
$('#linenumbers').val('Show line numbers');
});
}
else {
$($('.config').find('ul').get().reverse()).each(function(){
$(this).replaceWith($('<ol>'+$(this).html()+'</ol>'));
lines = 'on';
$('#linenumbers').val('Hide line numbers');
});
}
});
});
function refresh_oxidized_node(device_hostname){
$.ajax({
type: 'POST',
url: 'ajax_form.php',
data: {
type: "refresh-oxidized-node",
device_hostname: device_hostname
},
success: function (data) {
if(data['status'] == 'ok') {
toastr.success(data['message']);
} else {
toastr.error(data['message']);
}
},
error:function(){
toastr.error('An error occured while queuing refresh for an oxidized node (hostname: ' + device_hostname + ')');
}
});
}
$(document).ready(function () {
setInterval(function () {
$('.bootgrid-table').each(function() {
$(this).bootgrid('reload');
});
}, 300000);
});
function loadScript(src, callback) {
var script = document.createElement("script");
script.type = "text/javascript";
if(callback)script.onload=callback;
document.getElementsByTagName("head")[0].appendChild(script);
script.src = src;
}
function init_map(id, engine, api_key) {
var leaflet = L.map(id);
var baseMaps = {};
leaflet.setView([0, 0], 15);
if (engine === 'google') {
loadScript('https://maps.googleapis.com/maps/api/js?key=' + api_key, function () {
loadScript('js/Leaflet.GoogleMutant.js', function () {
var roads = L.gridLayer.googleMutant({
type: 'roadmap' // valid values are 'roadmap', 'satellite', 'terrain' and 'hybrid'
});
var satellite = L.gridLayer.googleMutant({
type: 'satellite'
});
baseMaps = {
"Streets": roads,
"Satellite": satellite
};
L.control.layers(baseMaps, null, {position: 'bottomleft'}).addTo(leaflet);
roads.addTo(leaflet);
});
});
} else if (engine === 'bing') {
loadScript('js/leaflet-bing-layer.min.js', function () {
var roads = L.tileLayer.bing({
bingMapsKey: api_key,
imagerySet: 'RoadOnDemand'
});
var satellite = L.tileLayer.bing({
bingMapsKey: api_key,
imagerySet: 'AerialWithLabelsOnDemand'
});
baseMaps = {
"Streets": roads,
"Satellite": satellite
};
L.control.layers(baseMaps, null, {position: 'bottomleft'}).addTo(leaflet);
roads.addTo(leaflet);
});
} else {
var osm = L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
maxZoom: 19,
attribution: '&copy; <a href="http://www.openstreetmap.org/copyright">OpenStreetMap</a>'
});
// var esri = L.tileLayer('https://server.arcgisonline.com/ArcGIS/rest/services/World_Imagery/MapServer/tile/{z}/{y}/{x}', {
// attribution: 'Tiles &copy; Esri &mdash; Source: Esri, i-cubed, USDA, USGS, AEX, GeoEye, Getmapping, Aerogrid, IGN, IGP, UPR-EGP, and the GIS User Community'
// });
//
// baseMaps = {
// "OpenStreetMap": osm,
// "Satellite": esri
// };
// L.control.layers(baseMaps, null, {position: 'bottomleft'}).addTo(leaflet);
osm.addTo(leaflet);
}
if (location.protocol === 'https:') {
// can't request location permission without https
L.control.locate().addTo(leaflet);
}
return leaflet;
}
function init_map_marker(leaflet, latlng) {
var marker = L.marker(latlng);
marker.addTo(leaflet);
leaflet.setView(latlng);
// move marker on drag
leaflet.on('drag', function () {
marker.setLatLng(leaflet.getCenter());
});
// center map on zoom
leaflet.on('zoom', function () {
leaflet.setView(marker.getLatLng());
});
return marker;
}
function update_location(id, latlng, callback) {
$.ajax({
method: 'PATCH',
url: "ajax/location/" + id,
data: {lat: latlng.lat, lng: latlng.lng}
}).success(function () {
toastr.success('Location updated');
typeof callback === 'function' && callback(true);
}).error(function (e) {
var msg = 'Failed to update location: ' + e.statusText;
var data = e.responseJSON;
if (data) {
if (data.hasOwnProperty('lat')) {
msg = data.lat.join(' ') + '<br />';
}
if (data.hasOwnProperty('lng')) {
if (!data.hasOwnProperty('lat')) {
msg = '';
}
msg += data.lng.join(' ')
}
}
toastr.error(msg);
typeof callback === 'function' && callback(false);
});
}