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

95 lines
2.4 KiB
JavaScript
Raw Normal View History

2020-10-02 04:52:33 +08:00
var newDeviceBtn = $j('#newDeviceBtn');
2017-05-19 01:50:56 +08:00
function switchDeviceOn( element, key ) {
var form = element.form;
form.view.value = currentView;
form.action.value = 'device';
form.command.value = 'on';
form.key.value = key;
form.submit();
}
2017-05-19 01:50:56 +08:00
function switchDeviceOff( element, key ) {
var form = element.form;
form.view.value = currentView;
form.action.value = 'device';
form.command.value = 'off';
form.key.value = key;
form.submit();
}
2017-05-19 01:50:56 +08:00
function deleteDevice( element ) {
var form = element.form;
form.view.value = currentView;
form.action.value = 'delete';
form.submit();
}
2017-05-19 01:50:56 +08:00
function configureButtons( element, name ) {
var form = element.form;
var checked = false;
for (var i = 0; i < form.elements.length; i++) {
if ( form.elements[i].name.indexOf(name) == 0) {
if ( form.elements[i].checked ) {
checked = true;
break;
}
}
2017-05-19 01:50:56 +08:00
}
form.deleteBtn.disabled = !checked;
}
2020-10-02 04:52:33 +08:00
// Load the Device Modal HTML via Ajax call
function getDeviceModal(did) {
$j.getJSON(thisUrl + '?request=modal&modal=device&did=' + did)
.done(function(data) {
if ( $j('#deviceModal').length ) {
$j('#deviceModal').replaceWith(data.html);
} else {
$j("body").append(data.html);
}
$j('#deviceModal').modal('show');
// Manage the Save button
$j('#deviceSaveBtn').click(function(evt) {
evt.preventDefault();
$j('#deviceModalForm').submit();
});
})
.fail(logAjaxFail);
}
function enableDeviceModal() {
$j(".deviceCol").click(function(evt) {
evt.preventDefault();
var did = $j(this).data('did');
getDeviceModal(did);
});
newDeviceBtn.click(function(evt) {
evt.preventDefault();
getDeviceModal(0);
});
2020-10-02 01:52:20 +08:00
}
function initPage() {
2020-10-02 04:52:33 +08:00
if ( canEditDevice ) enableDeviceModal();
newDeviceBtn.prop('disabled', !canEditDevice);
2020-10-02 01:52:20 +08:00
// Manage the BACK button
document.getElementById("backBtn").addEventListener("click", function onBackClick(evt) {
evt.preventDefault();
window.history.back();
});
// Disable the back button if there is nothing to go back to
$j('#backBtn').prop('disabled', !document.referrer.length);
// Manage the REFRESH Button
document.getElementById("refreshBtn").addEventListener("click", function onRefreshClick(evt) {
evt.preventDefault();
window.location.reload(true);
});
}
$j(document).ready(initPage);