diff --git a/vasl_templates/webapp/data/default-scenario.json b/vasl_templates/webapp/data/default-scenario.json index 0926c2d..f43d380 100644 --- a/vasl_templates/webapp/data/default-scenario.json +++ b/vasl_templates/webapp/data/default-scenario.json @@ -1,5 +1,7 @@ { +"SCENARIO_THEATER": "ETO", + "PLAYER_1": "german", "PLAYER_1_ELR": "5", "PLAYER_1_SAN": "2", diff --git a/vasl_templates/webapp/static/css/tabs-scenario.css b/vasl_templates/webapp/static/css/tabs-scenario.css index 2a345ec..7694664 100644 --- a/vasl_templates/webapp/static/css/tabs-scenario.css +++ b/vasl_templates/webapp/static/css/tabs-scenario.css @@ -4,7 +4,8 @@ #panel-scenario .row { display: flex ; align-items: center ; } #panel-scenario input { flex-grow: 1 ; } -#panel-scenario input[name='SCENARIO_ID'] { margin-left: 0.25em ; width: 4em ; flex-grow: 0 ; } +#panel-scenario input[name='SCENARIO_ID'] { margin-left: 0.25em ; width: 70px ; flex-grow: 0 ; } +#panel-scenario .ui-selectmenu-button.scenario_theater { margin: -3px 0 0 0.25em ; width: 60px ; flex-grow: 0 ; } #panel-scenario input[name='SCENARIO_DATE'] { width: 6em ; flex-grow: 0 ; } #panel-scenario label { font-weight: bold ; width: 5em ; } diff --git a/vasl_templates/webapp/static/main.js b/vasl_templates/webapp/static/main.js index 8790e5e..569e728 100644 --- a/vasl_templates/webapp/static/main.js +++ b/vasl_templates/webapp/static/main.js @@ -30,7 +30,7 @@ $(document).ready( function () { // initialize the menu var $menu = $("#menu input") ; $menu.popmenu( { - new_scenario: { label: "New scenario", action: function() { on_new_scenario(true) ; } }, + new_scenario: { label: "New scenario", action: function() { on_new_scenario() ; } }, load_scenario: { label: "Load scenario", action: on_load_scenario }, save_scenario: { label: "Save scenario", action: on_save_scenario }, separator: { type: "separator" }, @@ -91,6 +91,11 @@ $(document).ready( function () { var navHeight = $("#tabs .ui-tabs-nav").height() ; $("#tabs .ui-tabs-nav a").click( function() { $(this).blur() ; } ) ; + // initialize the scenario theater + $( "select[name='SCENARIO_THEATER']" ).selectmenu( { + classes: { "ui-selectmenu-button": "scenario_theater" }, + } ) ; + // initialize the scenario date picker $("input[name='SCENARIO_DATE']").datepicker( { showAnim: "slideDown", @@ -220,7 +225,7 @@ $(document).ready( function () { } } install_template_pack( data ) ; - on_new_scenario( false ) ; + do_on_new_scenario() ; gDefaultNationalities = $.extend( true, {}, data.nationalities ) ; // NOTE: If we are loading a user-defined template pack, then what we think // is the set of valid template ID's will depend on what's in it :-/ diff --git a/vasl_templates/webapp/static/snippets.js b/vasl_templates/webapp/static/snippets.js index 25f0ab4..60c16e8 100644 --- a/vasl_templates/webapp/static/snippets.js +++ b/vasl_templates/webapp/static/snippets.js @@ -228,10 +228,20 @@ function unload_snippet_params( params, check_date_capabilities ) // but by the time the filter gets called, it's too late :-( Instead, we provide a "raw_capabilities" // parameter that people can use in their templates - ugly, but probably not something that will // get a lot of use :-/ - var capabilities = make_capabilities( entry, params.SCENARIO_YEAR, params.SCENARIO_MONTH, check_date_capabilities, false ) ; + var capabilities = make_capabilities( + entry, + params.SCENARIO_THEATER, + params.SCENARIO_YEAR, params.SCENARIO_MONTH, check_date_capabilities, + false + ) ; if ( capabilities ) obj.capabilities = capabilities ; - capabilities = make_capabilities( entry, params.SCENARIO_YEAR, params.SCENARIO_MONTH, check_date_capabilities, true ) ; + capabilities = make_capabilities( + entry, + params.SCENARIO_THEATER, + params.SCENARIO_YEAR, params.SCENARIO_MONTH, check_date_capabilities, + true + ) ; if ( capabilities ) obj.raw_capabilities = capabilities ; var crew_survival = make_crew_survival( entry ) ; @@ -252,7 +262,7 @@ function unload_snippet_params( params, check_date_capabilities ) // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -function make_capabilities( entry, scenario_year, scenario_month, check_date_capabilities, raw ) +function make_capabilities( entry, scenario_theater, scenario_year, scenario_month, check_date_capabilities, raw ) { var capabilities = [] ; @@ -523,6 +533,10 @@ function on_load_scenario_file_selected() function do_load_scenario( data, fname ) { + // NOTE: We reset the scenario first, in case the loaded scenario is missing fields, + // so that those fields will be reset to their default values (instead of just staying unchanged). + do_on_new_scenario() ; + // load the scenario try { data = JSON.parse( data ) ; @@ -742,43 +756,45 @@ function unload_params_for_save() // -------------------------------------------------------------------- -function on_new_scenario( verbose ) +function on_new_scenario() { // check if the scenario is dirty if ( ! is_scenario_dirty() ) - do_on_new_scenario() ; + do_on_new_scenario( true ) ; else { // yup - confirm the operation ask( "New scenario", "

This scenario has been changed.

Do you want to reset it, and lose your changes?", { - ok: do_on_new_scenario, + ok: function() { do_on_new_scenario( true ) ; }, cancel: function() {}, } ) ; } +} - function do_on_new_scenario() { - // load the default scenario - if ( gDefaultScenario ) - do_load_scenario_data( gDefaultScenario ) ; - else { - $.getJSON( gGetDefaultScenarioUrl, function(data) { - gDefaultScenario = data ; - do_load_scenario_data( data ) ; - update_page_load_status( "default-scenario" ) ; - } ).fail( function( xhr, status, errorMsg ) { - showErrorMsg( "Can't get the default scenario:

" + escapeHTML(errorMsg) + "
" ) ; - return ; - } ) ; - } - - // flag that we have a new scenario - gLastSavedScenarioFilename = null ; - if ( gWebChannelHandler ) - gWebChannelHandler.on_new_scenario() ; +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // provide some feedback to the user - if ( verbose ) - showInfoMsg( "The scenario was reset." ) ; +function do_on_new_scenario( verbose ) { + // load the default scenario + if ( gDefaultScenario ) + do_load_scenario_data( gDefaultScenario ) ; + else { + $.getJSON( gGetDefaultScenarioUrl, function(data) { + gDefaultScenario = data ; + do_load_scenario_data( data ) ; + update_page_load_status( "default-scenario" ) ; + } ).fail( function( xhr, status, errorMsg ) { + showErrorMsg( "Can't get the default scenario:
" + escapeHTML(errorMsg) + "
" ) ; + return ; + } ) ; } + + // flag that we have a new scenario + gLastSavedScenarioFilename = null ; + if ( gWebChannelHandler ) + gWebChannelHandler.on_new_scenario() ; + + // provide some feedback to the user + if ( verbose ) + showInfoMsg( "The scenario was reset." ) ; } function reset_scenario() diff --git a/vasl_templates/webapp/templates/index.html b/vasl_templates/webapp/templates/index.html index 8ea632c..4aaad6a 100644 --- a/vasl_templates/webapp/templates/index.html +++ b/vasl_templates/webapp/templates/index.html @@ -59,6 +59,11 @@
+
diff --git a/vasl_templates/webapp/templates/vo-report.html b/vasl_templates/webapp/templates/vo-report.html index 24dbf55..4748522 100644 --- a/vasl_templates/webapp/templates/vo-report.html +++ b/vasl_templates/webapp/templates/vo-report.html @@ -68,9 +68,10 @@ function load_vo_listings( objs ) buf.push( "", fmtval( obj.no_if ? "" : "✓" ) ) ; buf.push( "", fmtval(make_crew_survival(obj)) ) ; } - var capabilities = make_capabilities( obj, year, month, true, true ) ; + var theater = "ETO" ; + var capabilities = make_capabilities( obj, theater, year, month, true, true ) ; buf.push( "", listval(capabilities) ) ; - var capabilities = make_capabilities( obj, year, month, true, false ) ; + var capabilities = make_capabilities( obj, theater, year, month, true, false ) ; buf.push( "", listval(capabilities) ) ; buf.push( "", "" + fmtval(obj.note_number) + "" ) ; buf.push( "", listval(obj.notes) ) ; diff --git a/vasl_templates/webapp/tests/fixtures/data/default-scenario.json b/vasl_templates/webapp/tests/fixtures/data/default-scenario.json index ddc9613..3a0ba63 100644 --- a/vasl_templates/webapp/tests/fixtures/data/default-scenario.json +++ b/vasl_templates/webapp/tests/fixtures/data/default-scenario.json @@ -1,5 +1,7 @@ { +"SCENARIO_THEATER": "ETO", + "PLAYER_1": "german", "PLAYER_1_ELR": "5", "PLAYER_1_SAN": "2", diff --git a/vasl_templates/webapp/tests/test_scenario_persistence.py b/vasl_templates/webapp/tests/test_scenario_persistence.py index b8afed6..fb6ec45 100644 --- a/vasl_templates/webapp/tests/test_scenario_persistence.py +++ b/vasl_templates/webapp/tests/test_scenario_persistence.py @@ -14,7 +14,9 @@ from vasl_templates.webapp.tests.utils import \ # this table lists all parameters stored in a scenario ALL_SCENARIO_PARAMS = { "scenario": [ - "SCENARIO_NAME", "SCENARIO_ID", "SCENARIO_LOCATION", "SCENARIO_DATE", "SCENARIO_WIDTH", + "SCENARIO_NAME", "SCENARIO_ID", + "SCENARIO_LOCATION", "SCENARIO_THEATER", + "SCENARIO_DATE", "SCENARIO_WIDTH", "PLAYER_1", "PLAYER_1_ELR", "PLAYER_1_SAN", "PLAYER_2", "PLAYER_2_ELR", "PLAYER_2_SAN", "VICTORY_CONDITIONS", "VICTORY_CONDITIONS_WIDTH", @@ -62,6 +64,7 @@ def test_scenario_persistence( webapp, webdriver ): #pylint: disable=too-many-st "SCENARIO_NAME": "my test scenario", "SCENARIO_ID": "xyz123", "SCENARIO_LOCATION": "right here", + "SCENARIO_THEATER": "PTO", "SCENARIO_DATE": "12/31/1945", "SCENARIO_WIDTH": "101", "PLAYER_1": "russian", "PLAYER_1_ELR": "1", "PLAYER_1_SAN": "2", @@ -132,6 +135,7 @@ def test_scenario_persistence( webapp, webdriver ): #pylint: disable=too-many-st data = _save_scenario() data2 = { k: v for k,v in data.items() if v } assert data2 == { + "SCENARIO_THEATER": "ETO", "PLAYER_1": "german", "PLAYER_1_ELR": "5", "PLAYER_1_SAN": "2", "PLAYER_2": "russian", "PLAYER_2_ELR": "5", "PLAYER_2_SAN": "2", }