2019-09-19 22:48:25 +08:00
|
|
|
function updateMonitorDimensions(element) {
|
2017-05-19 01:50:56 +08:00
|
|
|
var form = element.form;
|
2019-09-20 22:44:38 +08:00
|
|
|
if ( element.type == 'number' ) {
|
|
|
|
// either width or height
|
2019-09-19 22:48:25 +08:00
|
|
|
|
2019-09-20 22:44:38 +08:00
|
|
|
var widthFactor = parseInt(defaultAspectRatio.replace(/:.*$/, ''));
|
|
|
|
var heightFactor = parseInt(defaultAspectRatio.replace(/^.*:/, ''));
|
2008-07-14 21:54:50 +08:00
|
|
|
|
2017-05-19 01:50:56 +08:00
|
|
|
var monitorWidth = parseInt(form.elements['newMonitor[Width]'].value);
|
|
|
|
var monitorHeight = parseInt(form.elements['newMonitor[Height]'].value);
|
2019-09-19 22:48:25 +08:00
|
|
|
|
|
|
|
if ( form.elements['preserveAspectRatio'].checked ) {
|
|
|
|
switch ( element.name ) {
|
|
|
|
case 'newMonitor[Width]':
|
|
|
|
if ( monitorWidth >= 0 ) {
|
|
|
|
form.elements['newMonitor[Height]'].value = Math.round((monitorWidth * heightFactor) / widthFactor);
|
|
|
|
} else {
|
|
|
|
form.elements['newMonitor[Height]'].value = '';
|
|
|
|
}
|
|
|
|
monitorHeight = parseInt(form.elements['newMonitor[Height]'].value);
|
|
|
|
break;
|
|
|
|
case 'newMonitor[Height]':
|
|
|
|
if ( monitorHeight >= 0 ) {
|
|
|
|
form.elements['newMonitor[Width]'].value = Math.round((monitorHeight * widthFactor) / heightFactor);
|
|
|
|
} else {
|
|
|
|
form.elements['newMonitor[Width]'].value = '';
|
|
|
|
}
|
|
|
|
monitorWidth = parseInt(form.elements['newMonitor[Width]'].value);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// If we find a matching option in the dropdown, select it or select custom
|
|
|
|
|
|
|
|
var option = $j('select[name="dimensions_select"] option[value="'+monitorWidth+'x'+monitorHeight+'"]');
|
|
|
|
if ( !option.size() ) {
|
|
|
|
$j('select[name="dimensions_select"]').val('');
|
|
|
|
} else {
|
|
|
|
$j('select[name="dimensions_select"]').val(monitorWidth+'x'+monitorHeight);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// For some reason we get passed the first option instead of the select
|
|
|
|
element = form.elements['dimensions_select'];
|
|
|
|
|
|
|
|
var value = element.options[element.selectedIndex].value;
|
|
|
|
if ( value != '' ) { // custom dimensions
|
|
|
|
var dimensions = value.split('x');
|
|
|
|
form.elements['newMonitor[Width]'].value = dimensions[0];
|
|
|
|
form.elements['newMonitor[Height]'].value = dimensions[1];
|
2008-07-14 21:54:50 +08:00
|
|
|
}
|
2017-05-19 01:50:56 +08:00
|
|
|
}
|
2021-05-06 21:54:06 +08:00
|
|
|
update_estimated_ram_use();
|
2019-09-19 22:48:25 +08:00
|
|
|
return false;
|
2021-05-06 22:17:46 +08:00
|
|
|
} // function updateMonitorDimensions(element)
|
2008-07-14 21:54:50 +08:00
|
|
|
|
2017-05-19 01:50:56 +08:00
|
|
|
function loadLocations( element ) {
|
|
|
|
var form = element.form;
|
|
|
|
var controlIdSelect = form.elements['newMonitor[ControlId]'];
|
|
|
|
var returnLocationSelect = form.elements['newMonitor[ReturnLocation]'];
|
2008-07-14 21:54:50 +08:00
|
|
|
|
2017-05-19 01:50:56 +08:00
|
|
|
returnLocationSelect.options.length = 1;
|
|
|
|
//returnLocationSelect.options[0] = new Option( noneString, -1 );
|
2008-07-14 21:54:50 +08:00
|
|
|
|
2017-05-19 01:50:56 +08:00
|
|
|
var returnLocationOptions = controlOptions[controlIdSelect.selectedIndex];
|
|
|
|
if ( returnLocationOptions ) {
|
|
|
|
for ( var i = 0; i < returnLocationOptions.length; i++ ) {
|
|
|
|
returnLocationSelect.options[returnLocationSelect.options.length] = new Option( returnLocationOptions[i], i );
|
2008-07-14 21:54:50 +08:00
|
|
|
}
|
2017-05-19 01:50:56 +08:00
|
|
|
}
|
2008-07-14 21:54:50 +08:00
|
|
|
}
|
2008-07-16 16:40:21 +08:00
|
|
|
|
2017-05-19 01:50:56 +08:00
|
|
|
function initPage() {
|
2020-08-28 05:30:49 +08:00
|
|
|
var backBtn = $j('#backBtn');
|
2020-08-29 04:22:57 +08:00
|
|
|
var onvifBtn = $j('#onvifBtn');
|
2020-08-28 05:30:49 +08:00
|
|
|
|
2019-03-26 04:25:09 +08:00
|
|
|
document.querySelectorAll('input[name="newMonitor[SignalCheckColour]"]').forEach(function(el) {
|
|
|
|
el.oninput = function(event) {
|
|
|
|
$j('#SignalCheckSwatch').css('background-color', event.target.value);
|
|
|
|
};
|
|
|
|
});
|
|
|
|
document.querySelectorAll('input[name="newMonitor[WebColour]"]').forEach(function(el) {
|
|
|
|
el.oninput = function(event) {
|
|
|
|
$j('#WebSwatch').css('background-color', event.target.value);
|
|
|
|
};
|
|
|
|
});
|
2019-03-30 23:41:04 +08:00
|
|
|
$j('#contentForm').submit(function(event) {
|
2019-03-26 04:25:09 +08:00
|
|
|
if ( validateForm(this) ) {
|
|
|
|
$j('#contentButtons').hide();
|
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
};
|
|
|
|
});
|
2008-07-16 16:40:21 +08:00
|
|
|
|
2019-04-26 22:26:16 +08:00
|
|
|
// Disable form submit on enter
|
2019-04-26 22:40:11 +08:00
|
|
|
$j('#contentForm input').on('keyup keypress', function(e) {
|
2019-04-26 22:26:16 +08:00
|
|
|
var keyCode = e.keyCode || e.which;
|
2019-05-25 00:40:02 +08:00
|
|
|
if ( keyCode == 13 ) {
|
2019-04-26 22:26:16 +08:00
|
|
|
e.preventDefault();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
});
|
2019-05-25 00:40:02 +08:00
|
|
|
|
|
|
|
document.querySelectorAll('input[name="newMonitor[MaxFPS]"]').forEach(function(el) {
|
|
|
|
el.oninput = el.onclick = function(e) {
|
2019-05-27 23:25:49 +08:00
|
|
|
if ( e.target.value ) {
|
|
|
|
$j('#newMonitor\\[MaxFPS\\]').show();
|
|
|
|
} else {
|
|
|
|
$j('#newMonitor\\[MaxFPS\\]').hide();
|
|
|
|
}
|
|
|
|
};
|
2019-05-25 00:40:02 +08:00
|
|
|
});
|
|
|
|
document.querySelectorAll('input[name="newMonitor[AlarmMaxFPS]"]').forEach(function(el) {
|
|
|
|
el.oninput = el.onclick = function(e) {
|
2019-05-27 23:25:49 +08:00
|
|
|
if ( e.target.value ) {
|
|
|
|
$j('#newMonitor\\[AlarmMaxFPS\\]').show();
|
|
|
|
} else {
|
|
|
|
$j('#newMonitor\\[AlarmMaxFPS\\]').hide();
|
|
|
|
}
|
|
|
|
};
|
2019-05-25 00:40:02 +08:00
|
|
|
});
|
2019-09-19 22:48:25 +08:00
|
|
|
document.querySelectorAll('input[name="newMonitor[Width]"]').forEach(function(el) {
|
|
|
|
el.oninput = window['updateMonitorDimensions'].bind(el, el);
|
|
|
|
});
|
|
|
|
document.querySelectorAll('input[name="newMonitor[Height]"]').forEach(function(el) {
|
|
|
|
el.oninput = window['updateMonitorDimensions'].bind(el, el);
|
|
|
|
});
|
|
|
|
document.querySelectorAll('select[name="dimensions_select"]').forEach(function(el) {
|
|
|
|
el.onchange = window['updateMonitorDimensions'].bind(el, el);
|
|
|
|
});
|
2019-09-20 02:56:16 +08:00
|
|
|
document.querySelectorAll('select[name="newMonitor[ControlId]"]').forEach(function(el) {
|
|
|
|
el.onchange = window['loadLocations'].bind(el, el);
|
|
|
|
});
|
2020-01-01 08:10:29 +08:00
|
|
|
document.querySelectorAll('input[name="newMonitor[WebColour]"]').forEach(function(el) {
|
|
|
|
el.onchange = window['change_WebColour'].bind(el);
|
|
|
|
});
|
2020-09-23 02:33:26 +08:00
|
|
|
document.querySelectorAll('select[name="newMonitor[Type]"]').forEach(function(el) {
|
|
|
|
el.onchange = function() {
|
|
|
|
var form = document.getElementById('contentForm');
|
|
|
|
form.tab.value = 'general';
|
|
|
|
form.submit();
|
|
|
|
};
|
|
|
|
});
|
2021-05-09 03:47:29 +08:00
|
|
|
document.querySelectorAll('input[name="newMonitor[ImageBufferCount]"],input[name="newMonitor[MaxImageBufferCount]"],input[name="newMonitor[Width]"],input[name="newMonitor[Height]"],input[name="newMonitor[PreEventCount]"]').forEach(function(el) {
|
2021-05-06 21:54:06 +08:00
|
|
|
el.oninput = window['update_estimated_ram_use'].bind(el);
|
|
|
|
});
|
2021-05-06 22:17:46 +08:00
|
|
|
update_estimated_ram_use();
|
2019-09-20 02:56:16 +08:00
|
|
|
|
2020-12-11 03:32:17 +08:00
|
|
|
document.querySelectorAll('select[name="newMonitor[Function]"]').forEach(function(el) {
|
|
|
|
el.onchange = function() {
|
|
|
|
$j('#function_help div').hide();
|
|
|
|
$j('#'+this.value+'Help').show();
|
|
|
|
if ( this.value == 'Monitor' || this.value == 'None' ) {
|
|
|
|
$j('#FunctionEnabled').hide();
|
|
|
|
} else {
|
|
|
|
$j('#FunctionEnabled').show();
|
|
|
|
}
|
2020-12-11 05:24:33 +08:00
|
|
|
if ( this.value == 'Record' || this.value == 'Nodect' ) {
|
|
|
|
$j('#FunctionDecodingEnabled').show();
|
|
|
|
} else {
|
|
|
|
$j('#FunctionDecodingEnabled').hide();
|
|
|
|
}
|
2020-12-11 03:32:17 +08:00
|
|
|
};
|
|
|
|
el.onchange();
|
|
|
|
});
|
|
|
|
|
2021-05-06 04:48:49 +08:00
|
|
|
document.querySelectorAll('select[name="newMonitor[VideoWriter]"]').forEach(function(el) {
|
|
|
|
el.onchange = function() {
|
|
|
|
if ( this.value == 1 /* Encode */ ) {
|
|
|
|
$j('.OutputCodec').show();
|
|
|
|
$j('.Encoder').show();
|
|
|
|
} else {
|
|
|
|
$j('.OutputCodec').hide();
|
|
|
|
$j('.Encoder').hide();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
el.onchange();
|
|
|
|
});
|
|
|
|
document.querySelectorAll('select[name="newMonitor[OutputCodec]"]').forEach(function(el) {
|
|
|
|
el.onchange = function() {
|
|
|
|
var encoder_dropdown = $j('select[name="newMonitor[Encoder]"]');
|
|
|
|
if (encoder_dropdown) {
|
|
|
|
for (i=0; i<encoder_dropdown[0].options.length; i++) {
|
|
|
|
option = encoder_dropdown[0].options[i];
|
|
|
|
if ( this.value == 27 ) {
|
2021-05-07 05:33:04 +08:00
|
|
|
option.disabled = !option.value.includes('264');
|
2021-05-06 04:48:49 +08:00
|
|
|
if ( option.disabled && option.selected ) {
|
|
|
|
encoder_dropdown[0].options[0].selected = 1;
|
|
|
|
option.selected = false;
|
|
|
|
}
|
|
|
|
} else if ( this.value == 173 /* hevc */ ) {
|
|
|
|
option.disabled = !(option.value.includes('hevc') || option.value.includes('265') );
|
|
|
|
if ( option.disabled && option.selected ) {
|
|
|
|
encoder_dropdown[0].options[0].selected = 1;
|
|
|
|
option.selected = false;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
option.disabled = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
console.log('No encoder');
|
|
|
|
}
|
|
|
|
};
|
|
|
|
el.onchange();
|
|
|
|
});
|
|
|
|
|
2019-05-24 23:54:14 +08:00
|
|
|
$j('.chosen').chosen();
|
2020-08-28 05:30:49 +08:00
|
|
|
|
|
|
|
// Don't enable the back button if there is no previous zm page to go back to
|
|
|
|
backBtn.prop('disabled', !document.referrer.length);
|
|
|
|
|
|
|
|
// Manage the BACK button
|
|
|
|
document.getElementById("backBtn").addEventListener("click", function onBackClick(evt) {
|
|
|
|
evt.preventDefault();
|
|
|
|
window.history.back();
|
|
|
|
});
|
|
|
|
|
|
|
|
// Manage the REFRESH Button
|
|
|
|
document.getElementById("refreshBtn").addEventListener("click", function onRefreshClick(evt) {
|
|
|
|
evt.preventDefault();
|
|
|
|
window.location.reload(true);
|
|
|
|
});
|
2020-08-28 23:56:09 +08:00
|
|
|
|
2020-08-29 04:22:57 +08:00
|
|
|
// Manage the PROBE button
|
|
|
|
$j('#probeBtn').click(function(evt) {
|
|
|
|
var mid = evt.currentTarget.getAttribute("data-mid");
|
|
|
|
evt.preventDefault();
|
|
|
|
|
|
|
|
//FIX-ME: MAKE THIS A MODAL
|
|
|
|
//$j('#modalFunction-'+mid).modal('show');
|
|
|
|
window.location.assign('?view=monitorprobe&mid='+mid);
|
|
|
|
});
|
|
|
|
|
|
|
|
// Manage the ONVIF button
|
|
|
|
$j('#onvifBtn').click(function(evt) {
|
|
|
|
var mid = evt.currentTarget.getAttribute("data-mid");
|
|
|
|
evt.preventDefault();
|
|
|
|
|
|
|
|
//FIX-ME: MAKE THIS A MODAL
|
|
|
|
//$j('#modalFunction-'+mid).modal('show');
|
|
|
|
window.location.assign('?view=onvifprobe&mid='+mid);
|
|
|
|
});
|
|
|
|
|
|
|
|
// Don't enable the onvif button if there is no previous zm page to go back to
|
|
|
|
onvifBtn.prop('disabled', !hasOnvif);
|
|
|
|
|
|
|
|
// Manage the PRESET button
|
|
|
|
$j('#presetBtn').click(function(evt) {
|
|
|
|
var mid = evt.currentTarget.getAttribute("data-mid");
|
|
|
|
evt.preventDefault();
|
|
|
|
|
|
|
|
//FIX-ME: MAKE THIS A MODAL
|
|
|
|
//$j('#modalFunction-'+mid).modal('show');
|
|
|
|
window.location.assign('?view=monitorpreset&mid='+mid);
|
|
|
|
});
|
|
|
|
|
2020-08-28 23:56:09 +08:00
|
|
|
// Manage the CANCEL Button
|
|
|
|
document.getElementById("cancelBtn").addEventListener("click", function onCancelClick(evt) {
|
|
|
|
evt.preventDefault();
|
|
|
|
window.location.assign('?view=console');
|
|
|
|
});
|
2020-09-25 08:30:57 +08:00
|
|
|
|
|
|
|
if ( ZM_OPT_USE_GEOLOCATION ) {
|
|
|
|
if ( window.L ) {
|
|
|
|
var form = document.getElementById('contentForm');
|
|
|
|
var latitude = form.elements['newMonitor[Latitude]'].value;
|
|
|
|
var longitude = form.elements['newMonitor[Longitude]'].value;
|
|
|
|
map = L.map('LocationMap', {
|
|
|
|
center: L.latLng(latitude, longitude),
|
|
|
|
zoom: 13,
|
|
|
|
onclick: function() {
|
|
|
|
alert('click');
|
|
|
|
}
|
|
|
|
});
|
|
|
|
L.tileLayer(ZM_OPT_GEOLOCATION_TILE_PROVIDER, {
|
|
|
|
attribution: 'Map data © <a href="https://www.openstreetmap.org/">OpenStreetMap</a> contributors, <a href="https://creativecommons.org/licenses/by-sa/2.0/">CC-BY-SA</a>, Imagery © <a href="https://www.mapbox.com/">Mapbox</a>',
|
|
|
|
maxZoom: 18,
|
|
|
|
id: 'mapbox/streets-v11',
|
|
|
|
tileSize: 512,
|
|
|
|
zoomOffset: -1,
|
|
|
|
accessToken: ZM_OPT_GEOLOCATION_ACCESS_TOKEN,
|
|
|
|
}).addTo(map);
|
|
|
|
L.marker([latitude, longitude]).addTo(map);
|
|
|
|
} else {
|
|
|
|
console.log('Location turned on but leaflet not installed.');
|
|
|
|
}
|
|
|
|
} // end if ZM_OPT_USE_GEOLOCATION
|
2019-04-26 22:26:16 +08:00
|
|
|
} // end function initPage()
|
|
|
|
|
2020-01-01 08:10:29 +08:00
|
|
|
function change_WebColour() {
|
|
|
|
$j('#WebSwatch').css(
|
2020-01-01 09:24:51 +08:00
|
|
|
'backgroundColor',
|
|
|
|
$j('input[name="newMonitor[WebColour]"]').val()
|
2020-01-01 08:10:29 +08:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
function getRandomColour() {
|
|
|
|
var letters = '0123456789ABCDEF';
|
|
|
|
var colour = '#';
|
|
|
|
for (var i = 0; i < 6; i++) {
|
|
|
|
colour += letters[Math.floor(Math.random() * 16)];
|
|
|
|
}
|
|
|
|
return colour;
|
|
|
|
}
|
|
|
|
|
|
|
|
function random_WebColour() {
|
|
|
|
var new_colour = getRandomColour();
|
|
|
|
$j('input[name="newMonitor[WebColour]"]').val(new_colour);
|
|
|
|
$j('#WebSwatch').css(
|
2020-01-01 09:24:51 +08:00
|
|
|
'backgroundColor', new_colour
|
2020-01-01 08:10:29 +08:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2021-05-06 21:54:06 +08:00
|
|
|
function update_estimated_ram_use() {
|
|
|
|
var width = document.querySelectorAll('input[name="newMonitor[Width]"]')[0].value;
|
|
|
|
var height = document.querySelectorAll('input[name="newMonitor[Height]"]')[0].value;
|
|
|
|
var colours = document.querySelectorAll('select[name="newMonitor[Colours]"]')[0].value;
|
|
|
|
|
2021-05-06 22:17:46 +08:00
|
|
|
var min_buffer_count = parseInt(document.querySelectorAll('input[name="newMonitor[ImageBufferCount]"]')[0].value);
|
2021-05-09 03:47:29 +08:00
|
|
|
min_buffer_count += parseInt(document.querySelectorAll('input[name="newMonitor[PreEventCount]"]')[0].value);
|
2021-05-06 22:17:46 +08:00
|
|
|
var min_buffer_size = min_buffer_count * width * height * colours;
|
|
|
|
document.getElementById('estimated_ram_use').innerHTML = 'Min: ' + human_filesize(min_buffer_size);
|
|
|
|
|
|
|
|
var max_buffer_count = parseInt(document.querySelectorAll('input[name="newMonitor[MaxImageBufferCount]"]')[0].value);
|
|
|
|
if (max_buffer_count) {
|
|
|
|
var max_buffer_size = (min_buffer_count + max_buffer_count) * width * height * colours;
|
|
|
|
document.getElementById('estimated_ram_use').innerHTML += ' Max: ' + human_filesize(max_buffer_size);
|
|
|
|
} else {
|
|
|
|
document.getElementById('estimated_ram_use').innerHTML += ' Max: Unlimited';
|
|
|
|
}
|
2021-05-06 21:54:06 +08:00
|
|
|
}
|
|
|
|
|
2020-09-24 21:13:44 +08:00
|
|
|
function updateLatitudeAndLongitude(latitude, longitude) {
|
2020-09-24 21:01:30 +08:00
|
|
|
var form = document.getElementById('contentForm');
|
|
|
|
form.elements['newMonitor[Latitude]'].value = latitude;
|
|
|
|
form.elements['newMonitor[Longitude]'].value = longitude;
|
|
|
|
}
|
|
|
|
function getLocation() {
|
2020-09-24 21:13:44 +08:00
|
|
|
if ('geolocation' in navigator) {
|
2020-09-24 21:01:30 +08:00
|
|
|
navigator.geolocation.getCurrentPosition((position) => {
|
|
|
|
updateLatitudeAndLongitude(position.coords.latitude, position.coords.longitude);
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
console.log("Geolocation not available");
|
|
|
|
}
|
|
|
|
}
|
2020-09-23 04:21:59 +08:00
|
|
|
|
2021-07-07 21:47:32 +08:00
|
|
|
function ManufacturerId_onchange(ManufacturerId_select) {
|
|
|
|
if (ManufacturerId_select.value())
|
|
|
|
$j('newMonitor[Manufacturer]').hide();
|
|
|
|
else
|
|
|
|
$j('newMonitor[Manufacturer]').show();
|
|
|
|
}
|
|
|
|
function ModelId_onchange(ModelId_select) {
|
|
|
|
if (ModelId_select.value())
|
|
|
|
$j('newMonitor[Model]').hide();
|
|
|
|
else
|
|
|
|
$j('newMonitor[Model]').show();
|
|
|
|
}
|
|
|
|
|
2019-04-26 22:26:16 +08:00
|
|
|
window.addEventListener('DOMContentLoaded', initPage);
|