// --------------------------------------------------------------------
function add_vo( vo_type, player_no )
{
// load the available vehicles/ordnance
var nat = $( "select[name='PLAYER_" + player_no + "']" ).val() ;
var entries = gVehicleOrdnanceListings[vo_type][nat] ;
if ( entries === undefined ) {
showWarningMsg( "There are no " + get_nationality_display_name(nat) + " " + vo_type + " listings." ) ;
return ;
}
var buf = [] ;
for ( var i=0 ; i < entries.length ; ++i )
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 = [ "
Do you want to add it again?", {
ok: add_sel_entry,
} ) ;
return ;
}
// add the new vehicle/ordnance
add_sel_entry() ;
},
Cancel: function() { $(this).dialog( "close" ) ; },
},
} ) ;
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
function do_add_vo( vo_type, player_no, vo_entry, vo_image_id, elite, custom_capabilities, custom_comments, seq_id )
{
// add the specified vehicle/ordnance
// NOTE: We set a fixed height for the sortable2 entries (based on the CSS settings in tabs-ob.css),
// so that the vehicle/ordnance images won't get truncated if there are a lot of them.
var nat = get_player_nat( player_no ) ;
var $sortable2 = $( "#ob_" + vo_type + "-sortable_" + player_no ) ;
var div_tag = "
" ;
var data = {
caption: vo_entry.name,
vo_entry: vo_entry,
vo_image_id: vo_image_id,
elite: elite,
fixed_height: fixed_height
} ;
if ( custom_capabilities )
data.custom_capabilities = custom_capabilities ;
if ( custom_comments )
data.custom_comments = custom_comments ;
data.id = seq_id ;
var buf = [ div_tag,
"
",
"
"
] ;
var vo_note_key = get_vo_note_key( vo_entry ) ;
var vo_note = get_vo_note( vo_type, nat, vo_note_key ) ;
var vo_note_image_url = null ;
if ( vo_note )
vo_note_image_url = APP_URL_BASE + "/" + vo_type + "/" + nat + "/note/" + vo_note_key ;
else {
// NOTE: Note numbers seem to be distinct across all Allied Minor or all Axis Minor vehicles/ordnance,
// so if we don't find a note in a given nationality's normal vehicles/ordnance, we can get away with
// just checking their corresponding common vehicles/ordnance.
var nat_type = gTemplatePack.nationalities[ nat ].type ;
if ( ["allied-minor","axis-minor"].indexOf( nat_type ) !== -1 ) {
vo_note = get_vo_note( vo_type, nat_type, vo_note_key ) ;
if ( vo_note )
vo_note_image_url = APP_URL_BASE + "/" + vo_type + "/" + nat_type + "/note/" + vo_note_key ;
}
}
if ( vo_note ) {
var template_id = (vo_type === "vehicles") ? "ob_vehicle_note" : "ob_ordnance_note" ;
if ( is_template_available( template_id ) ) {
buf.push(
"
"
) ;
}
data.vo_note = vo_note ;
data.vo_note_image_url = vo_note_image_url ;
}
buf.push( "
" ) ;
var $content = $( buf.join("") ) ;
var $entry = $sortable2.sortable2( "add", {
content: $content,
data: data,
} ) ;
update_vo_sortable2_entry( $entry ) ;
// add a handler for the snippet button
$content.children("img.snippet").click( function( evt ) {
generate_snippet( $(this), evt, {} ) ;
return false ;
} ) ;
}
function update_vo_sortable2_entry( $entry, snippet_params )
{
// initialize
if ( ! snippet_params )
snippet_params = unload_snippet_params( true, null ) ;
var data = $entry.data( "sortable2-data" ) ;
var vo_entry = data.vo_entry ;
var vo_image_id = data.vo_image_id ;
var capabilities = 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 ],
data.elite,
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, false ) ;
var $content = $entry.children( ".vo-entry" ) ;
$content.find( "img.vasl-image" ).attr( "src", url ) ;
var name = vo_entry.name ;
if ( data.elite )
name += " \u24ba" ;
$content.find( "div.vo-name" ).html( name ) ;
for ( var i=0 ; i < capabilities.length ; ++i )
capabilities[i] = "