Added a button to reset a vehicle/ordnance's capabilities back to default.

master
Pacman Ghost 6 years ago
parent 9ea39a0ec0
commit 91b26d963c
  1. 2
      vasl_templates/webapp/static/css/sortable.css
  2. BIN
      vasl_templates/webapp/static/images/sortable-reset.png
  3. 9
      vasl_templates/webapp/static/sortable.js
  4. 24
      vasl_templates/webapp/static/vo2.js
  5. 2
      vasl_templates/webapp/templates/edit-vo-dialog.html
  6. 24
      vasl_templates/webapp/tests/test_capabilities.py

@ -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 ; }

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.8 KiB

@ -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( $( "<div><img src='" + gImagesBaseUrl + "/sortable-reset.png' class='sortable-reset'> Reset</div>" ) )
.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

@ -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

@ -10,6 +10,8 @@
<div class="footer">
<button id="vo_capabilities-add" class="sortable-add"></button>
<img id="vo_capabilities-trash" class="sortable-trash">
<span class="spacer"></span>
<button id="vo_capabilities-reset" class="sortable-reset"></button>
</div>
</div>

@ -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 <i>new</i> 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 <small><i>(brew up)</i></small>"')
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 <small><i>(brew up)</i></small>"' )
# 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 )

Loading…
Cancel
Save