unify button update

This commit is contained in:
j 2021-11-24 19:39:57 +01:00
parent 92a1cc4c9f
commit d4b4f131e9

View File

@ -330,6 +330,18 @@ function formatDict(position) {
return pos.trim()
}
function updateButtons(disabed, is_active) {
$('button.run_from').attr({disabled: disabled})
$('button.loop').attr({disabled: disabled})
$('button.hour_loop').attr({disabled: disabled})
$('button.continue_from').attr({disabled: disabled})
if (is_active != undefined) {
$('button.run').attr({disabled: is_active})
$('button.stop').attr({disabled: is_active})
}
}
function updateStatus() {
api('status', {}, function(response) {
if (response.result) {
@ -337,12 +349,7 @@ function updateStatus() {
var disabled = !gotSelection || response.result.status == 'Active'
$('#status').html(response.result.status)
$('button.run').attr({disabled: response.result.status == 'Active'})
$('button.run_from').attr({disabled: disabled})
$('button.loop').attr({disabled: disabled})
$('button.hour_loop').attr({disabled: disabled})
$('button.continue_from').attr({disabled: disabled})
$('button.stop').attr({disabled: response.result.status != 'Active'})
updateButtons(disabled, response.result.status == 'Active')
if (response.result.duration && response.result.status == 'Active') {
$('#duration').html(formatDuration(response.result.duration))
} else {
@ -407,11 +414,8 @@ function updateStatus() {
}
var gotSelection = grid.getSelectedRows().length > 0
$('button.goto').attr({disabled: !gotSelection})
$('button.run_from').attr({disabled: !gotSelection})
$('button.continue_from').attr({disabled: !gotSelection})
$('button.insert').attr({disabled: !gotSelection})
$('button.delete').attr({disabled: !gotSelection})
var disabled = !gotSelection
updateButtons(disabled, document.querySelector('#status').innerText == 'Active')
}