From feebe9f63c2a3e741e5996e208543251ad86837b Mon Sep 17 00:00:00 2001 From: Taka Date: Tue, 19 Jul 2022 00:29:58 +1000 Subject: [PATCH] Disable snippet-width textbox's when disabling snippet buttons. --- vasl_templates/webapp/static/main.js | 15 +++++++++++++-- vasl_templates/webapp/static/snippets.js | 5 ++++- .../webapp/tests/test_template_packs.py | 13 +++++++++++-- 3 files changed, 28 insertions(+), 5 deletions(-) diff --git a/vasl_templates/webapp/static/main.js b/vasl_templates/webapp/static/main.js index 61e0ed5..a6bc938 100644 --- a/vasl_templates/webapp/static/main.js +++ b/vasl_templates/webapp/static/main.js @@ -795,9 +795,20 @@ function install_template_pack( data ) if ( template_id.match( /^ob_(vehicles|ordnance).*_[12]$/ ) ) template_id = template_id.substring( 0, template_id.length-2 ) ; var enable = is_template_available( template_id ) ; - if ( $btn.parent().hasClass( "snippet-control" ) ) + if ( $btn.parent().hasClass( "snippet-control" ) ) { $btn.parent().controlgroup( enable ? "enable" : "disable" ) ; - else + // check if there's a corresponding "snippet-width" textbox + var sel = $btn.attr( "data-id" ) ; + if ( sel.match( /_[12]$/ ) ) + sel = sel.substr( 0, sel.length-2 ) + "_width" + sel.substr( sel.length-2 ) ; + else + sel += "_width" ; + var $width = $( "input.snippet-width[name='" + sel.toUpperCase() + "']" ) ; + if ( $width.length > 0 ) { + // yup - update it as well + $width.val( "" ).prop( "disabled", !enable ) ; + } + } else $btn.button( enable ? "enable": "disable" ) ; } $( "button.generate" ).each( function() { update_button( $(this) ) ; } ) ; diff --git a/vasl_templates/webapp/static/snippets.js b/vasl_templates/webapp/static/snippets.js index 894240d..4317849 100644 --- a/vasl_templates/webapp/static/snippets.js +++ b/vasl_templates/webapp/static/snippets.js @@ -1733,7 +1733,10 @@ function do_load_scenario_data( params ) } } else { - $elem.val( params[key] ) ; + if ( $elem.prop( "disabled" ) ) + $elem.val( "" ) ; + else + $elem.val( params[key] ) ; if ( key === "ASA_ID" ) updateForConnectedScenario( params[key], params.ROAR_ID ) ; } diff --git a/vasl_templates/webapp/tests/test_template_packs.py b/vasl_templates/webapp/tests/test_template_packs.py index 46573b5..a0892a2 100644 --- a/vasl_templates/webapp/tests/test_template_packs.py +++ b/vasl_templates/webapp/tests/test_template_packs.py @@ -204,13 +204,13 @@ def test_missing_templates( webapp, webdriver ): # check the UI state of the next button template_id = adjust_template_id( btn.get_attribute( "data-id" ) ) if fname == "national-capabilities.json": - expected = False # nb: this is the JSON file, not the template file, and so doesn't effect buttons + expected = False # nb: this is the JSON file, not the template file, and so doesn't affect buttons elif fname == "nat_caps.j2": expected = template_id.startswith( "nat_caps_" ) else: expected = os.path.splitext( fname )[0] == template_id disabled = webdriver.execute_script( "return $(arguments[0]).button('option','disabled')", btn ) - assert expected == disabled + assert disabled == expected # check that snippet control groups have been enabled/disabled correctly parent = btn.find_element( By.XPATH, ".." ) parent_classes = get_css_classes( parent ) @@ -224,6 +224,15 @@ def test_missing_templates( webapp, webdriver ): assert "ui-selectmenu-disabled" not in elem_classes else: assert "snippet-control" not in parent_classes + # check if the button has an associated "snippet-width" textbox + sel = btn.get_attribute( "data-id" ) + if sel.endswith( ( "_1", "_2" ) ): + sel = sel[:-2] + "_width" + sel[-2:] + else: + sel = sel + "_width" + elem = find_child( "input.snippet-width[name='{}']".format( sel.upper() ) ) + if elem: + assert not elem.is_enabled() == expected # upload the template pack, with one file missing each time for fname in files: