From e190daac2c3180f5b0e84de0c974b116c3313083 Mon Sep 17 00:00:00 2001 From: j Date: Wed, 24 Nov 2021 19:42:00 +0100 Subject: [PATCH] unify button update --- static/js/cccc.js | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/static/js/cccc.js b/static/js/cccc.js index e65f91a..2f57829 100644 --- a/static/js/cccc.js +++ b/static/js/cccc.js @@ -330,7 +330,7 @@ function formatDict(position) { return pos.trim() } -function updateButtons(disabed, is_active) { +function updateButtons(disabled, is_active) { $('button.run_from').attr({disabled: disabled}) $('button.loop').attr({disabled: disabled}) $('button.hour_loop').attr({disabled: disabled}) @@ -346,11 +346,12 @@ function updateStatus() { api('status', {}, function(response) { if (response.result) { var gotSelection = grid.getSelectedRows().length > 0 - var disabled = !gotSelection || response.result.status == 'Active' + var is_active = response.result.status == 'Active' + var disabled = !gotSelection || is_active $('#status').html(response.result.status) - updateButtons(disabled, response.result.status == 'Active') - if (response.result.duration && response.result.status == 'Active') { + updateButtons(disabled, is_active) + if (response.result.duration && is_active) { $('#duration').html(formatDuration(response.result.duration)) } else { $('#duration').html(formatDuration(totalDuration())) @@ -414,8 +415,9 @@ function updateStatus() { } var gotSelection = grid.getSelectedRows().length > 0 - var disabled = !gotSelection - updateButtons(disabled, document.querySelector('#status').innerText == 'Active') + var is_active = document.querySelector('#status').innerText == 'Active' + var disabled = !gotSelection || is_active + updateButtons(disabled, is_active) }