From d4b4f131e9ca0be753032a56aa65cd2a808520e7 Mon Sep 17 00:00:00 2001 From: j Date: Wed, 24 Nov 2021 19:39:57 +0100 Subject: [PATCH] unify button update --- static/js/cccc.js | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/static/js/cccc.js b/static/js/cccc.js index 3801af2..e65f91a 100644 --- a/static/js/cccc.js +++ b/static/js/cccc.js @@ -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') }