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');
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2015-11-27 11:58:56 +00:00
|
|
|
var oldH;
|
|
|
|
var oldW;
|
2015-10-10 13:49:09 +00:00
|
|
|
$(document).ready(function() {
|
2015-10-12 21:28:31 +00:00
|
|
|
// 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));
|
2015-11-17 00:20:06 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
// 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
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
2015-10-12 21:28:31 +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()) {
|
2018-01-05 09:58:42 +01:00
|
|
|
$.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 () {
|
2015-10-12 21:28:31 +00:00
|
|
|
toastr.error(data.message);
|
|
|
|
}
|
2018-01-05 09:58:42 +01:00
|
|
|
});
|
|
|
|
}
|
2015-10-12 21:28:31 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
// 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);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
2015-11-19 09:54:26 +00:00
|
|
|
|
2015-11-27 11:58:56 +00:00
|
|
|
oldW=$(window).width();
|
|
|
|
oldH=$(window).height();
|
2015-10-10 13:49:09 +00:00
|
|
|
});
|
2015-10-20 21:35:08 +00:00
|
|
|
|
|
|
|
function submitCustomRange(frmdata) {
|
2015-10-26 19:49:30 +00:00
|
|
|
var reto = /to=([0-9a-zA-Z\-])+/g;
|
|
|
|
var refrom = /from=([0-9a-zA-Z\-])+/g;
|
2015-10-20 21:35:08 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2015-11-30 11:10:35 +00:00
|
|
|
function updateResolution(refresh)
|
2015-11-20 12:02:51 +00:00
|
|
|
{
|
2018-05-09 08:05:17 -05:00
|
|
|
$.post('ajax/set_resolution',
|
2015-11-26 12:14:57 +00:00
|
|
|
{
|
|
|
|
width: $(window).width(),
|
|
|
|
height:$(window).height()
|
|
|
|
},
|
|
|
|
function(data) {
|
2015-11-30 11:10:35 +00:00
|
|
|
if(refresh == true) {
|
|
|
|
location.reload();
|
|
|
|
}
|
2015-11-26 12:14:57 +00:00
|
|
|
},'json'
|
2015-11-20 12:02:51 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2015-11-26 12:14:57 +00:00
|
|
|
var rtime;
|
|
|
|
var timeout = false;
|
2015-11-27 11:58:56 +00:00
|
|
|
var delta = 500;
|
2015-11-30 11:10:35 +00:00
|
|
|
var newH;
|
|
|
|
var newW;
|
2015-11-26 12:14:57 +00:00
|
|
|
|
|
|
|
$(window).on('resize', function(){
|
|
|
|
rtime = new Date();
|
2016-09-20 09:21:46 -05:00
|
|
|
if (timeout === false && !(typeof no_refresh === 'boolean' && no_refresh === true)) {
|
2015-11-26 12:14:57 +00:00
|
|
|
timeout = true;
|
|
|
|
setTimeout(resizeend, delta);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
function resizeend() {
|
|
|
|
if (new Date() - rtime < delta) {
|
|
|
|
setTimeout(resizeend, delta);
|
2018-01-05 16:04:47 +01:00
|
|
|
}
|
2015-11-26 17:41:41 +00:00
|
|
|
else {
|
2015-11-30 11:10:35 +00:00
|
|
|
newH=$(window).height();
|
|
|
|
newW=$(window).width();
|
2015-11-26 12:14:57 +00:00
|
|
|
timeout = false;
|
2015-11-30 11:10:35 +00:00
|
|
|
if(Math.abs(oldW - newW) >= 200)
|
|
|
|
{
|
|
|
|
refresh = true;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
refresh = false;
|
|
|
|
resizeGraphs();
|
|
|
|
}
|
|
|
|
updateResolution(refresh);
|
2018-01-05 16:04:47 +01:00
|
|
|
}
|
2015-11-26 12:14:57 +00:00
|
|
|
};
|
2015-11-20 12:02:51 +00:00
|
|
|
|
2015-11-27 11:58:56 +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;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-11-19 09:54:26 +00:00
|
|
|
$(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');
|
|
|
|
|
2016-09-22 10:44:17 -04:00
|
|
|
if(button.hasClass("fa-plus")) {
|
|
|
|
button.addClass('fa-minus').removeClass('fa-plus');
|
2015-11-20 14:47:59 +00:00
|
|
|
}
|
|
|
|
else {
|
2016-09-22 10:44:17 -04:00
|
|
|
button.addClass('fa-plus').removeClass('fa-minus');
|
2015-11-19 09:54:26 +00:00
|
|
|
}
|
2018-01-05 16:04:47 +01:00
|
|
|
|
2015-11-19 09:54:26 +00:00
|
|
|
list.toggle();
|
|
|
|
continued.toggle();
|
|
|
|
});
|
2016-02-11 23:19:56 +00:00
|
|
|
|
2016-09-02 20:42:45 +03:00
|
|
|
//availability-map mode change
|
2016-08-12 22:51:29 +03:00
|
|
|
$(document).on("change", '#mode', function() {
|
|
|
|
$.post('ajax_mapview.php',
|
|
|
|
{
|
2016-09-02 20:42:45 +03:00
|
|
|
map_view: $(this).val()
|
2016-08-12 22:51:29 +03:00
|
|
|
},
|
|
|
|
function(data) {
|
|
|
|
location.reload();
|
|
|
|
},'json'
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
2016-09-02 20:42:45 +03:00
|
|
|
//availability-map device group
|
|
|
|
$(document).on("change", '#group', function() {
|
|
|
|
$.post('ajax_mapview.php',
|
|
|
|
{
|
|
|
|
group_view: $(this).val()
|
|
|
|
},
|
|
|
|
function(data){
|
|
|
|
location.reload();
|
|
|
|
},'json'
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
2016-02-11 23:19:56 +00:00
|
|
|
$(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');
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
2016-08-13 03:20:55 +03:00
|
|
|
});
|
2018-09-10 16:04:39 +02:00
|
|
|
|
|
|
|
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 + ')');
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2018-11-08 16:29:20 -06:00
|
|
|
|
|
|
|
$(document).ready(function () {
|
|
|
|
setInterval(function () {
|
|
|
|
$('.bootgrid-table').each(function() {
|
|
|
|
$(this).bootgrid('reload');
|
|
|
|
});
|
|
|
|
}, 300000);
|
|
|
|
});
|
2018-11-29 19:23:40 -06:00
|
|
|
|
2018-12-16 15:18:17 -06:00
|
|
|
var jsfilesadded = [];
|
|
|
|
function loadjs(filename, func){
|
|
|
|
if (jsfilesadded.indexOf(filename) < 0) {
|
|
|
|
$.getScript(filename, func);
|
|
|
|
jsfilesadded.push(filename);
|
|
|
|
} else {
|
|
|
|
func();
|
|
|
|
}
|
2018-11-29 19:23:40 -06:00
|
|
|
}
|
|
|
|
|
2018-12-16 14:56:29 +00:00
|
|
|
function init_map(id, engine, api_key, config) {
|
2018-11-29 19:23:40 -06:00
|
|
|
var leaflet = L.map(id);
|
|
|
|
var baseMaps = {};
|
|
|
|
leaflet.setView([0, 0], 15);
|
|
|
|
|
|
|
|
if (engine === 'google') {
|
2018-12-16 15:18:17 -06:00
|
|
|
loadjs('https://maps.googleapis.com/maps/api/js?key=' + api_key, function () {
|
|
|
|
loadjs('js/Leaflet.GoogleMutant.js', function () {
|
2018-11-30 14:36:52 -06:00
|
|
|
var roads = L.gridLayer.googleMutant({
|
2018-11-29 19:23:40 -06:00
|
|
|
type: 'roadmap' // valid values are 'roadmap', 'satellite', 'terrain' and 'hybrid'
|
|
|
|
});
|
2018-11-30 14:36:52 -06:00
|
|
|
var satellite = L.gridLayer.googleMutant({
|
2018-11-29 19:23:40 -06:00
|
|
|
type: 'satellite'
|
|
|
|
});
|
|
|
|
|
|
|
|
baseMaps = {
|
|
|
|
"Streets": roads,
|
|
|
|
"Satellite": satellite
|
|
|
|
};
|
|
|
|
L.control.layers(baseMaps, null, {position: 'bottomleft'}).addTo(leaflet);
|
|
|
|
roads.addTo(leaflet);
|
|
|
|
});
|
|
|
|
});
|
2018-11-30 14:36:52 -06:00
|
|
|
} else if (engine === 'bing') {
|
2018-12-16 15:18:17 -06:00
|
|
|
loadjs('js/leaflet-bing-layer.min.js', function () {
|
2018-11-30 14:36:52 -06:00
|
|
|
var roads = L.tileLayer.bing({
|
|
|
|
bingMapsKey: api_key,
|
|
|
|
imagerySet: 'RoadOnDemand'
|
|
|
|
});
|
|
|
|
var satellite = L.tileLayer.bing({
|
|
|
|
bingMapsKey: api_key,
|
|
|
|
imagerySet: 'AerialWithLabelsOnDemand'
|
|
|
|
});
|
|
|
|
|
2018-12-11 08:14:59 -06:00
|
|
|
baseMaps = {
|
|
|
|
"Streets": roads,
|
|
|
|
"Satellite": satellite
|
|
|
|
};
|
|
|
|
L.control.layers(baseMaps, null, {position: 'bottomleft'}).addTo(leaflet);
|
|
|
|
roads.addTo(leaflet);
|
|
|
|
});
|
|
|
|
} else if (engine === 'mapquest') {
|
|
|
|
loadScript('https://www.mapquestapi.com/sdk/leaflet/v2.2/mq-map.js?key=' + api_key, function () {
|
|
|
|
var roads = MQ.mapLayer();
|
|
|
|
var satellite = MQ.hybridLayer();
|
|
|
|
|
2018-11-30 14:36:52 -06:00
|
|
|
baseMaps = {
|
|
|
|
"Streets": roads,
|
|
|
|
"Satellite": satellite
|
|
|
|
};
|
|
|
|
L.control.layers(baseMaps, null, {position: 'bottomleft'}).addTo(leaflet);
|
|
|
|
roads.addTo(leaflet);
|
|
|
|
});
|
2018-11-29 19:23:40 -06:00
|
|
|
} else {
|
2018-12-16 14:56:29 +00:00
|
|
|
var osm = L.tileLayer('//' + config.tile_url + '/{z}/{x}/{y}.png', {
|
2018-11-29 19:23:40 -06:00
|
|
|
maxZoom: 19,
|
|
|
|
attribution: '© <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 © Esri — 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);
|
|
|
|
|
|
|
|
});
|
|
|
|
}
|
2018-12-05 13:52:07 -06:00
|
|
|
|
|
|
|
function http_fallback(link) {
|
|
|
|
var url = link.getAttribute('href');
|
|
|
|
try {
|
|
|
|
var xhr = new XMLHttpRequest();
|
|
|
|
xhr.open('GET', url, false);
|
|
|
|
xhr.timeout = 2000;
|
|
|
|
xhr.send(null);
|
|
|
|
|
|
|
|
if (xhr.status !== 200) {
|
|
|
|
url = url.replace(/^https:\/\//, 'http://');
|
|
|
|
}
|
|
|
|
} catch (e) {
|
|
|
|
url = url.replace(/^https:\/\//, 'http://');
|
|
|
|
}
|
|
|
|
|
|
|
|
window.open(url, '_blank');
|
|
|
|
return false;
|
|
|
|
}
|
2018-12-16 15:18:17 -06:00
|
|
|
|
|
|
|
function init_select2(selector, type, data, selected) {
|
|
|
|
var $select = $(selector);
|
|
|
|
|
|
|
|
// allow function to be assigned to pass data
|
|
|
|
var data_function = function(params) {
|
|
|
|
data.term = params.term;
|
|
|
|
data.page = params.page || 1;
|
|
|
|
return data;
|
|
|
|
};
|
|
|
|
if ($.isFunction(data)) {
|
|
|
|
data_function = data;
|
|
|
|
}
|
|
|
|
|
|
|
|
$select.select2({
|
|
|
|
theme: "bootstrap",
|
|
|
|
dropdownAutoWidth : true,
|
|
|
|
width: "auto",
|
|
|
|
allowClear: true,
|
|
|
|
ajax: {
|
|
|
|
url: 'ajax/select/' + type,
|
|
|
|
delay: 150,
|
|
|
|
data: data_function
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
if (selected) {
|
|
|
|
$select.val(selected);
|
|
|
|
$select.trigger('change');
|
|
|
|
}
|
|
|
|
}
|