diff --git a/vasl_templates/webapp/static/css/sortable.css b/vasl_templates/webapp/static/css/sortable.css index f44b8c2..f5bed89 100644 --- a/vasl_templates/webapp/static/css/sortable.css +++ b/vasl_templates/webapp/static/css/sortable.css @@ -1,5 +1,7 @@ button.sortable-add { vertical-align: top ; height: 30px ; padding: 4px 10px ; } img.sortable-add { vertical-align: middle ; height: 15px ; margin-right: 0.25em ; } +button.sortable-reset { vertical-align: top ; height: 30px ; padding: 4px 10px ; } +img.sortable-reset { vertical-align: middle ; height: 15px ; margin-right: 0.25em ; } .sortable { list-style-type: none ; margin: 0 ; padding: 0 ; } diff --git a/vasl_templates/webapp/static/images/sortable-reset.png b/vasl_templates/webapp/static/images/sortable-reset.png new file mode 100755 index 0000000..1d50e12 Binary files /dev/null and b/vasl_templates/webapp/static/images/sortable-reset.png differ diff --git a/vasl_templates/webapp/static/sortable.js b/vasl_templates/webapp/static/sortable.js index 6497587..29cf354 100644 --- a/vasl_templates/webapp/static/sortable.js +++ b/vasl_templates/webapp/static/sortable.js @@ -81,6 +81,15 @@ $.fn.sortable2 = function( action, args ) var $add = find_helper( $sortable2, "add" ) ; $add.prop( "title", "Add a new " + display_name[0] ) .click( args.add ) ; + if ( args.reset ) { + $sortable2.data( "on_reset", args.reset ) ; + var $reset_btn = find_helper( $sortable2, "reset" ) ; + $reset_btn.prepend( $( "
Reset
" ) ) + .addClass( "ui-button" ) ; + var $reset = find_helper( $sortable2, "reset" ) ; + $reset.prop( "title", "Reset the " + display_name[1] ) + .click( args.reset ) ; + } // handle overflow when there are too many entries // NOTE: We do this by setting the height of the entry list fairly low; if there are diff --git a/vasl_templates/webapp/static/vo2.js b/vasl_templates/webapp/static/vo2.js index 6adcf56..d0a3abc 100644 --- a/vasl_templates/webapp/static/vo2.js +++ b/vasl_templates/webapp/static/vo2.js @@ -65,6 +65,13 @@ function _do_edit_ob_vo( $entry, player_no, vo_type ) } ) ; } + function on_reset_capabilities() { + $capabilities.sortable2( "delete-all" ) ; + var capabilities = get_default_capabilities() ; + for ( var i=0 ; i < capabilities.length ; ++i ) + add_capability( capabilities[i] ) ; + } + // show the dialog var $dlg = $( "#edit-vo" ).dialog( { dialogClass: "edit-vo", @@ -81,6 +88,7 @@ function _do_edit_ob_vo( $entry, player_no, vo_type ) $elem.find( "input[type='text']" ).focus() ; $elem[0].scrollIntoView() ; }, + reset: on_reset_capabilities, no_confirm_delete: true, } ) ; }, @@ -112,18 +120,10 @@ function _do_edit_ob_vo( $entry, player_no, vo_type ) if ( val ) capabilities.push( val ) ; } ) ; - if ( capabilities.length > 0 ) { - if ( capabilities.join() !== get_default_capabilities( false ).join() ) - $entry.data( "sortable2-data" ).custom_capabilities = capabilities ; - else { - // the capabilities are the same as the default - no need to retain these custom settings - delete $entry.data( "sortable2-data" ).custom_capabilities ; - } - } else { - // NOTE: We treat "no capabilities" as meaning "revert back to the default capabilities". - // This means that the user can never have a V/O that actually has no capabilities, but then - // why would they want to include that V/O in a label in the scenario? :shrug: If they - // really want it there, they can always include a dummy capability of "none" or "-"... + if ( capabilities.join() !== get_default_capabilities( false ).join() ) + $entry.data( "sortable2-data" ).custom_capabilities = capabilities ; + else { + // the capabilities are the same as the default - no need to retain these custom settings delete $entry.data( "sortable2-data" ).custom_capabilities ; } // update the original V/O entry to reflect the changes diff --git a/vasl_templates/webapp/templates/edit-vo-dialog.html b/vasl_templates/webapp/templates/edit-vo-dialog.html index c576710..e2023f6 100644 --- a/vasl_templates/webapp/templates/edit-vo-dialog.html +++ b/vasl_templates/webapp/templates/edit-vo-dialog.html @@ -10,6 +10,8 @@ diff --git a/vasl_templates/webapp/tests/test_capabilities.py b/vasl_templates/webapp/tests/test_capabilities.py index 90e330b..3a302f3 100644 --- a/vasl_templates/webapp/tests/test_capabilities.py +++ b/vasl_templates/webapp/tests/test_capabilities.py @@ -445,7 +445,7 @@ def test_custom_capabilities( webapp, webdriver ): #pylint: disable=too-many-sta def extract_capabilities( clipboard ): """Extract the capabilities.""" mo = re.search( r"^- capabilities: (.*)$", clipboard, re.MULTILINE ) - return mo.group(1) + return mo.group(1) if mo else "" def check_snippet( expected ): """Check the vehicle's snippet.""" snippet_btn.click() @@ -503,18 +503,34 @@ def test_custom_capabilities( webapp, webdriver ): #pylint: disable=too-many-sta ActionChains(webdriver).double_click( elems[0] ).perform() elems = check_capabilities_in_dialog( [ "QSU (modified)", "a new capability" ] ) - # delete all capabilities (this will revert the capabilities back to default) + # delete all capabilities for elem in elems: ActionChains(webdriver).key_down( Keys.CONTROL ).click( elem ).key_up( Keys.CONTROL ).perform() click_dialog_button( "OK" ) - check_snippet( '"QSU" "cs 4 (brew up)"') + check_snippet( "" ) + + # save the scenario + saved_scenario2 = save_scenario() + assert len(saved_scenario2["OB_VEHICLES_1"]) == 1 + assert saved_scenario2["OB_VEHICLES_1"][0]["custom_capabilities"] == [] + + # reload the scenario, and reset the vehicle's capabilities back to the default + load_scenario( saved_scenario ) + select_tab( "ob1" ) + elems = find_children( "li", vehicles_sortable ) + assert len(elems) == 1 + ActionChains(webdriver).double_click( elems[0] ).perform() + btn = find_child( "#vo_capabilities-reset" ) + btn.click() + click_dialog_button( "OK" ) + check_snippet( '"QSU" "cs 4 (brew up)"' ) # make sure the custom capabilities are no longer saved in the scenario saved_scenario2 = save_scenario() assert len(saved_scenario2["OB_VEHICLES_1"]) == 1 assert "custom_capabilities" not in saved_scenario2["OB_VEHICLES_1"][0] - # reload the scenario, and edit the vehicle's capabilities to be the default + # reload the scenario, and manually set the vehicle's capabilities to be the same as the default load_scenario( saved_scenario ) select_tab( "ob1" ) elems = find_children( "li", vehicles_sortable )