// --------------------------------------------------------------------
function add_vo( vo_type, player_no )
{
// get the vehicles/ordnance already added
var $sortable2 = $( "#ob_" + vo_type + "-sortable_" + player_no ) ;
var vo_present = [];
$sortable2.children("li").each( function() {
var vo_entry = $(this).data( "sortable2-data" ).vo_entry ;
vo_present.push( vo_entry.id ) ;
} ) ;
// load the available vehicles/ordnance
var nat = $( "select[name='PLAYER_" + player_no + "']" ).val() ;
var entries = gVehicleOrdnanceListings[vo_type][nat] ;
if ( entries === undefined ) {
showErrorMsg( "There are no " + get_nationality_display_name(nat) + " " + vo_type + " listings." ) ;
return ;
}
var buf = [] ;
for ( var i=0 ; i < entries.length ; ++i ) {
if ( vo_present.indexOf( entries[i].id ) !== -1 )
continue ;
buf.push( "" ) ;
}
function format_vo_entry( opt ) {
if ( ! opt.id )
return opt.text ;
var vo_entry = entries[opt.id] ;
var div_class = "vo-entry" ;
if ( is_small_vasl_piece( vo_entry ) )
div_class += " small-piece" ;
var buf2 = [ "
" ;
var data = {
caption: vo_entry.name,
vo_entry: vo_entry,
vo_image_id: vo_image_id,
fixed_height: fixed_height
} ;
if ( custom_capabilities )
data.custom_capabilities = custom_capabilities ;
var buf = [ div_tag,
"
",
"
",
"
" ] ;
var $entry = $sortable2.sortable2( "add", {
content: $( buf.join("") ),
data: data,
} ) ;
update_vo_sortable2_entry( $entry ) ;
}
function update_vo_sortable2_entry( $entry, snippet_params )
{
// initialize
if ( ! snippet_params )
snippet_params = unload_snippet_params( true, null ) ;
var vo_entry = $entry.data( "sortable2-data" ).vo_entry ;
var vo_image_id = $entry.data( "sortable2-data" ).vo_image_id ;
var capabilities = $entry.data( "sortable2-data" ).custom_capabilities ;
if ( capabilities )
capabilities = capabilities.slice() ;
else {
var player_no = get_player_no_for_element( $entry ) ;
capabilities = make_capabilities(
false,
vo_entry,
snippet_params[ "PLAYER_"+player_no ],
snippet_params.SCENARIO_THEATER, snippet_params.SCENARIO_YEAR, snippet_params.SCENARIO_MONTH,
false
) ;
}
// update the vehicle/ordnance's sortable2 entry
var url = get_vo_image_url( vo_entry, vo_image_id, true ) ;
var $content = $entry.children( ".vo-entry" ) ;
$content.find( "img.vasl-image" ).attr( "src", url ) ;
$content.find( "div.vo-name" ).html( vo_entry.name ) ;
for ( var i=0 ; i < capabilities.length ; ++i )
capabilities[i] = "