librenms-librenms/html/js/librenms.js

168 lines
5.5 KiB
JavaScript
Raw Normal View History

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) {
event.preventDefault();
var $this = $(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');
}
});
});
// 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();
$.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);
}
});
});
updateResolution();
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;
}
$(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("glyphicon-plus"))
{
button.addClass('glyphicon-minus').removeClass('glyphicon-plus');
}else
{
button.addClass('glyphicon-plus').removeClass('glyphicon-minus');
}
list.toggle();
continued.toggle();
});
function updateResolution()
{
$.post('ajax_setresolution.php', { width: $(window).width() , height:$(window).height() }, function(json) {
},'json');
}
$(window).on('resize', function(){ updateResolution();});