From e9079dd7aa30bdd268ae2c31c1af47ad924d5a71 Mon Sep 17 00:00:00 2001 From: Taka Date: Sat, 4 Jul 2020 07:28:06 +0000 Subject: [PATCH] Allow a caption to be set in the "grid" extras template. --- .../data/default-template-pack/extras/grid.j2 | 11 +++- vasl_templates/webapp/static/extras.js | 58 ++++++++++++++----- 2 files changed, 53 insertions(+), 16 deletions(-) diff --git a/vasl_templates/webapp/data/default-template-pack/extras/grid.j2 b/vasl_templates/webapp/data/default-template-pack/extras/grid.j2 index c82ff90..5edec61 100644 --- a/vasl_templates/webapp/data/default-template-pack/extras/grid.j2 +++ b/vasl_templates/webapp/data/default-template-pack/extras/grid.j2 @@ -3,9 +3,10 @@ + - + {% set RANGE = [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50] %} +{%if CAPTION%} {% for col in RANGE %} {% if col <= COLS %}
{{CAPTION}} {%endif%} {% for row in RANGE %} {% if row <= ROWS %}
{%endif%} {%endfor%} {%endif%} {%endfor%} diff --git a/vasl_templates/webapp/static/extras.js b/vasl_templates/webapp/static/extras.js index 8497848..8a8f4ff 100644 --- a/vasl_templates/webapp/static/extras.js +++ b/vasl_templates/webapp/static/extras.js @@ -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( "" ) ; + } + } + // generate the form for entering the template parameters var buf = [ "
" ] ; buf.push( "
", template_info.name, "
" ) ; @@ -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( "
", escapeHTML(display_name)+":" ) ; buf.push( "" ) ; - var j ; if ( template_info.params[i].type === "input" ) { buf.push( "", template_info.params[i].options[j], "" ) ; buf.push( "" ) ; - } else if ( template_info.params[i].type.substr(0,22) === "player-color2-droplist" ) { - buf.push( "" ) ; + add_player_nats( buf ) ; + buf.push( "" ) ; + } else if ( template_info.params[i].type === "player-color-droplist" ) { + buf.push( "" ) ; + // 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( "" ) ; } } buf.push( "
" ) ; @@ -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 param.type = "input" ;