zoneminder/web/skins/classic/views/js/add_monitors.js

107 lines
2.9 KiB
JavaScript
Raw Normal View History

2017-10-28 11:52:08 +08:00
var probeReq = new Request.JSON( {url: thisUrl, method: 'get', timeout: AJAX_TIMEOUT, link: 'cancel', onSuccess: getProbeResponse} );
2017-10-28 11:52:08 +08:00
function probe( url_e ) {
probeReq.send( "request=add_monitors&action=probe&url="+url_e.value );
}
var ProbeResults;
function getProbeResponse( respObj, respText ) {
2018-01-26 01:14:21 +08:00
if ( checkStreamForErrors( "getProbeResponse", respObj ) ) {
console.log(respText);
2017-10-28 11:52:08 +08:00
return;
2018-01-26 01:14:21 +08:00
}
2017-10-28 11:52:08 +08:00
2018-01-26 01:14:21 +08:00
if ( respObj.Streams && respObj.Streams.length ) {
2017-10-28 11:52:08 +08:00
parseStreams( respObj.Streams );
} else {
var results_div = $j('#results')[0];
if ( ! results_div ) {
console.log("No results div found.");
return;
}
results_div.innerHTML = 'No streams found.';
//console.log("No streams: " + respText);
2017-10-28 11:52:08 +08:00
}
} // end function getProbeResponse
function parseStreams( Streams ) {
ProbeResults = Array();
2017-10-28 11:52:08 +08:00
var results_div = $j('#results')[0];
if ( ! results_div ) {
console.log("No results div found.");
return;
}
results_div.innerHTML = '';
var html = '';
for ( i in Streams ) {
var stream = Streams[i];
if ( stream.url ) {
html += '<p>'+stream.Monitor.Name + ' at ' + stream.url;
if ( stream.Monitor.Id ) {
html += ' is already entered into the system by Monitor ' + stream.Monitor.Id + ' ' + stream.Monitor.Name + '<br/>';
html += '<input type="button" value="Edit" onclick="addMonitor(\''+stream.url+'\');"/>';
2017-10-28 11:52:08 +08:00
} else {
html += '<input type="button" value="Add" onclick="addMonitor(\''+stream.url+'\');"/>';
2017-10-28 11:52:08 +08:00
}
html += '</p>';
ProbeResults[stream.url] = stream;
} else {
//console.log(stream);
}
} // end for eah Stream
results_div.innerHTML = html;
2017-10-28 11:52:08 +08:00
}
function addMonitor(url) {
if ( ! ProbeResults[url] ) {
alert("Monitor for url " + url + " not found in probe results." );
return;
}
var Stream = ProbeResults[url];
var Monitor = Stream.Monitor;
var mid = Monitor.Id ? Monitor.Id : '';
popup_url = '?view=monitor&mid='+mid+'&newMonitor[Path]='+url;
2017-10-28 11:52:08 +08:00
keys = Object.keys( Monitor );
for ( i in Monitor ) {
if ( ! Monitor[i] ) {
2017-10-28 11:52:08 +08:00
continue;
}
if ( Monitor[i] == 'null' ) {
2017-10-28 11:52:08 +08:00
Monitor[i]='';
}
2017-10-28 11:52:08 +08:00
popup_url += '&newMonitor['+i+']='+Monitor[i];
}
createPopup( popup_url, 'zmMonitor'+mid, 'monitor' );
2017-10-28 11:52:08 +08:00
}
2017-10-28 11:52:08 +08:00
function import_csv( form ) {
var formData = new FormData( form );
console.log(formData);
//formData.append('file', $('#file')[0].files[0]);
$j.ajax({
url: thisUrl+"?request=add_monitors&action=import",
type: 'POST',
data: formData,
processData: false, // tell jQuery not to process the data
contentType: false, // tell jQuery not to set contentType
success: function(data) {
var json = JSON.parse(data);
parseStreams( json.Streams );
}
2017-10-28 11:52:08 +08:00
});
}
function initPage() {
url = $j('#Url')[0];
if ( url.value ) {
probe(url);
}
}
window.addEventListener( 'DOMContentLoaded', initPage );