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-19 22:48:25 +08:00
|
|
|
if ( element.type == 'number' ) { // either width or height
|
|
|
|
|
|
|
|
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
|
|
|
}
|
2019-09-19 22:48:25 +08:00
|
|
|
return false;
|
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() {
|
|
|
|
//var protocolSelector = $('contentForm').elements['newMonitor[Protocol]'];
|
|
|
|
//if ( $(protocolSelector).getTag() == 'select' )
|
|
|
|
//updateMethods( $(protocolSelector) );
|
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 ) {
|
|
|
|
console.log('showing');
|
|
|
|
$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 ) {
|
|
|
|
console.log('showing');
|
|
|
|
$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-05-25 00:40:02 +08:00
|
|
|
|
2019-05-24 23:54:14 +08:00
|
|
|
$j('.chosen').chosen();
|
2019-04-26 22:26:16 +08:00
|
|
|
} // end function initPage()
|
|
|
|
|
|
|
|
window.addEventListener('DOMContentLoaded', initPage);
|