@ -63,6 +63,14 @@ function _show_extra_template( template_id )
// parse the template (nb: we do this every time since the user may have changed it in the UI)
var template _info = _parse _extra _template ( template _id , gTemplatePack . templates [ template _id ] ) ;
function add _player _nats ( buf ) {
var nats = get _sorted _nats ( ) ;
for ( var i = 0 ; i < nats . length ; ++ i ) {
var nat _info = gTemplatePack . nationalities [ nats [ i ] ] ;
buf . push ( "<option value='" , nats [ i ] , "'>" , nat _info . display _name , "</option>" ) ;
}
}
// generate the form for entering the template parameters
var buf = [ "<div>" ] ;
buf . push ( "<div class='name'>" , template _info . name , "</div>" ) ;
@ -77,7 +85,6 @@ function _show_extra_template( template_id )
var display _name = template _info . params [ i ] . caption || template _info . params [ i ] . name ;
buf . push ( "<td class='caption'>" , escapeHTML ( display _name ) + ":" ) ;
buf . push ( "<td class='value'>" ) ;
var j ;
if ( template _info . params [ i ] . type === "input" ) {
buf . push ( "<input class='param' name='" + escapeHTML ( template _info . params [ i ] . name ) + "' type='text'" ) ;
if ( template _info . params [ i ] . width )
@ -92,16 +99,20 @@ function _show_extra_template( template_id )
for ( j = 0 ; j < template _info . params [ i ] . options . length ; ++ j )
buf . push ( "<option>" , template _info . params [ i ] . options [ j ] , "</option>" ) ;
buf . push ( "</select>" ) ;
} else if ( template _info . params [ i ] . type . substr ( 0 , 22 ) === "player-color2 -droplist" ) {
buf . push ( "<select class='param' name='PLAYER_COLOR2_ DROPLIST' style='width:11.5em;'>" ) ;
if ( template _info . params [ i ] . type === "player-color2-droplist-ex" )
buf . push ( "<option value='black'>black</option>" , "<option value='#c0c0c0'>gray</option >" ) ;
var nats = get _sorted _nats ( ) ;
for ( j = 0 ; j < nats . length ; ++ j ) {
var nat _info = gTemplatePack . nationalities [ nats [ j ] ] ;
buf . push ( "<option value='" , nat _info . ob _colors [ 2 ] , "'>" , nat _info . display _name , " </option>" ) ;
}
} else if ( template _info . params [ i ] . type === "player-droplist" ) {
buf . push ( "<select name='_ PLAYER_DROPLIST_ ' style='width:11.5em;'>" ) ;
add _player _nats ( buf ) ;
buf . push ( "</select >" ) ;
} else if ( template _info . params [ i ] . type === "player-color-droplist" ) {
buf . push ( "<select name='_PLAYER_DROPLIST_' style='width:11.5em;'>" ) ;
buf . push ( "<option value=':black:'>black</option>" ) ;
buf . push ( "<option value=':gray:'>gray </option>" ) ;
add _player _nats ( buf ) ;
buf . push ( "</select>" ) ;
// FUDGE! We create some hidden textboxes that contain the actual player colors (these will be updated
// as the user changes the selected player).
for ( var j = 0 ; j <= 2 ; ++ j )
buf . push ( "<input type='text' class='param' name='PLAYER_COLOR" + j + "' size='8' hidden></input>" ) ;
}
}
buf . push ( "</table>" ) ;
@ -131,6 +142,20 @@ function _show_extra_template( template_id )
return ;
}
function on _player _droplist _change ( $sel ) {
// update the hidden player colors
var nat = $sel . val ( ) ;
var colors ;
if ( nat === ":black:" )
colors = [ "#f0f0f0" , "black" , "black" ] ;
else if ( nat === ":gray:" )
colors = [ "#f0f0f0" , "#c0c0c0" , "#c0c0c0" ] ;
else
colors = gTemplatePack . nationalities [ nat ] . ob _colors ;
for ( var i = 0 ; i <= 2 ; ++ i )
$form . find ( "input[name='PLAYER_COLOR" + i + "']" ) . val ( colors [ i ] ) ;
}
// generate the form
var $form = $ ( buf ) ;
$form . find ( "select" ) . select2 ( {
@ -139,6 +164,11 @@ function _show_extra_template( template_id )
restrict _droplist _height ( $ ( this ) ) ;
} ) ;
fixup _external _links ( $form ) ;
var $sel = $form . find ( "select[name='_PLAYER_DROPLIST_']" ) ;
if ( $sel . length > 0 ) {
$sel . on ( "change" , function ( ) { on _player _droplist _change ( $ ( this ) ) ; } ) ;
on _player _droplist _change ( $sel ) ;
}
// initialize the "generate" button
init _snippet _button ( $form . find ( "button.generate" ) ) ;
@ -183,10 +213,10 @@ function _parse_extra_template( template_id, template )
// we have a <select>
param . type = "select" ;
param . options = val . split ( "::" ) ;
} else if ( param . name === "PLAYER_COLOR2_ DROPLIST" )
param . type = "player-color2- droplist" ;
else if ( param . name === "PLAYER_COLOR2 _DROPLIST_EX " )
param . type = "player-color2 -droplist-ex " ;
} else if ( param . name === "PLAYER_DROPLIST" )
param . type = "player-droplist" ;
else if ( param . name === "PLAYER_COLOR_DROPLIST" )
param . type = "player-color-droplist" ;
else {
// we have an <input>
param . type = "input" ;