From 0cbe6435cfd93390bf92888d307d63fe9561942c Mon Sep 17 00:00:00 2001 From: Taka Date: Fri, 18 Mar 2022 08:00:50 +1100 Subject: [PATCH] Completely hide the UI controls if there are no vehicles/ordnance. --- vasl_templates/webapp/static/main.js | 14 +++++---- .../webapp/tests/test_vehicles_ordnance.py | 4 +-- vasl_templates/webapp/tests/test_vo_notes.py | 30 +++++++++---------- 3 files changed, 25 insertions(+), 23 deletions(-) diff --git a/vasl_templates/webapp/static/main.js b/vasl_templates/webapp/static/main.js index 5a624e8..e756552 100644 --- a/vasl_templates/webapp/static/main.js +++ b/vasl_templates/webapp/static/main.js @@ -802,13 +802,15 @@ function on_player_change( player_no ) $( "#ob_ordnance-sortable_" + player_no ).sortable2( "delete-all" ) ; $("input[name='OB_ORDNANCE_WIDTH_"+player_no+"']").val( "" ) ; - // enable/disable the "add vehicle/ordnance" buttons + // disable the vehicles/ordnance panels if none are available function update_add_vo_button( vo_type ) { - if ( ! gVehicleOrdnanceListings[ vo_type ] ) - return ; - $( "#ob_"+vo_type+"-add_"+player_no ).button( - gVehicleOrdnanceListings[vo_type][player_nat] ? "enable": "disable" - ) ; + var $panel = $( "#panel-ob_" + vo_type + "_" + player_no ) ; + if ( gVehicleOrdnanceListings[ vo_type ] !== undefined && gVehicleOrdnanceListings[vo_type][ player_nat ] !== undefined ) { + $panel.find( ".footer" ).show() ; + } else { + $panel.find( ".footer" ).hide() ; + $panel.find( ".sortable-hint" ).html( "There are no " + vo_type + " available." ) ; + } } update_add_vo_button( "vehicles" ) ; update_add_vo_button( "ordnance" ) ; diff --git a/vasl_templates/webapp/tests/test_vehicles_ordnance.py b/vasl_templates/webapp/tests/test_vehicles_ordnance.py index b957b19..c569068 100644 --- a/vasl_templates/webapp/tests/test_vehicles_ordnance.py +++ b/vasl_templates/webapp/tests/test_vehicles_ordnance.py @@ -415,10 +415,10 @@ def test_common_vo( webapp, webdriver ): #pylint: disable=too-many-locals # check if the nationality has any vehicles/ordnance elem = find_child( "#ob_{}-add_1".format( vo_type ) ) if nat in ["thai","indonesian","anzac","burmese","filipino"]: # nb: these are in the BFP extension - assert not elem.is_enabled() + assert not elem.is_displayed() continue if nat == "kfw-cpva" and vo_type == "vehicles": - assert not elem.is_enabled() + assert not elem.is_displayed() continue if nat == "partisan": continue diff --git a/vasl_templates/webapp/tests/test_vo_notes.py b/vasl_templates/webapp/tests/test_vo_notes.py index 0317fc9..786e0d8 100644 --- a/vasl_templates/webapp/tests/test_vo_notes.py +++ b/vasl_templates/webapp/tests/test_vo_notes.py @@ -447,29 +447,29 @@ def test_update_ui( webapp, webdriver ): webapp.control_tests.set_vo_notes_dir( "{TEST}" ) init_webapp( webapp, webdriver ) - def do_test( nat, veh_expected, ord_expected ): + def do_test( nat, veh_expected, ord_expected, ma_veh_expected, ma_ord_expected ): """Do the test.""" # set the specified player set_player( 1, nat ) select_tab( "ob1" ) - # check that the Multi-Applicable Notes controls are visible/hidden + # check that the controls are visible/hidden fieldset = find_child( "#tabs-ob1 fieldset[name='ob_vehicles_1']" ) - assert find_child( ".snippets-notes", fieldset ).is_displayed() == veh_expected - assert find_child( "label[for='ob']", fieldset ).is_displayed() == veh_expected + assert find_child( ".snippets-ob", fieldset ).is_displayed() == veh_expected + assert find_child( ".snippets-notes", fieldset ).is_displayed() == ma_veh_expected + assert find_child( "label[for='ob']", fieldset ).is_displayed() == ma_veh_expected fieldset = find_child( "#tabs-ob1 fieldset[name='ob_ordnance_1']" ) - assert find_child( ".snippets-notes", fieldset ).is_displayed() == ord_expected - assert find_child( "label[for='ob']", fieldset ).is_displayed() == ord_expected - # the OB snippet controls should always be visible - assert find_child( ".snippets-ob", fieldset ).is_displayed() + assert find_child( ".snippets-ob", fieldset ).is_displayed() == ord_expected + assert find_child( ".snippets-notes", fieldset ).is_displayed() == ma_ord_expected + assert find_child( "label[for='ob']", fieldset ).is_displayed() == ma_ord_expected # do the tests - do_test( "german", True, True ) - do_test( "russian", True, True ) - do_test( "british", True, False ) - do_test( "french", False, True ) - do_test( "finnish", False, False ) - do_test( "dutch", True, True ) # nb: because they are Allied Minor - do_test( "romanian", True, True ) # nb: because they are Axis Minor + do_test( "german", True, True, True, True ) + do_test( "russian", True, True, True, True ) + do_test( "british", True, True, True, False ) + do_test( "french", False, False, False, False ) + do_test( "finnish", False, False, False, False ) + do_test( "dutch", True, True, True, True ) # nb: because they are Allied Minor + do_test( "romanian", True, True, True, True ) # nb: because they are Axis Minor # ---------------------------------------------------------------------