From 5667eaa0a5c8c94e7fc6ab10a57b655543c06537 Mon Sep 17 00:00:00 2001 From: Taka Date: Mon, 6 May 2019 17:20:36 +0000 Subject: [PATCH] Added an extras template to generate a grid. --- .../data/default-template-pack/extras/grid.j2 | 27 +++++++++++++++++++ vasl_templates/webapp/static/extras.js | 25 ++++++++++++++--- vasl_templates/webapp/static/main.js | 14 +--------- vasl_templates/webapp/static/utils.js | 17 ++++++++++++ 4 files changed, 67 insertions(+), 16 deletions(-) create mode 100644 vasl_templates/webapp/data/default-template-pack/extras/grid.j2 diff --git a/vasl_templates/webapp/data/default-template-pack/extras/grid.j2 b/vasl_templates/webapp/data/default-template-pack/extras/grid.j2 new file mode 100644 index 0000000..2ba50ec --- /dev/null +++ b/vasl_templates/webapp/data/default-template-pack/extras/grid.j2 @@ -0,0 +1,27 @@ + + + + + + + + + + +{% for row in [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 row <= ROWS %} + + {% for col in [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 col <= COLS %}
{%endif%} + {%endfor%} + {%endif%} +{%endfor%} +
+ + diff --git a/vasl_templates/webapp/static/extras.js b/vasl_templates/webapp/static/extras.js index fa6f4c4..85def64 100644 --- a/vasl_templates/webapp/static/extras.js +++ b/vasl_templates/webapp/static/extras.js @@ -77,6 +77,7 @@ 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( "" ) ; } else if ( template_info.params[i].type === "select" ) { buf.push( "" ) ; + } else if ( template_info.params[i].type.substr(0,22) === "player-color2-droplist" ) { + buf.push( "" ) ; } } buf.push( "" ) ; @@ -98,7 +109,11 @@ function _show_extra_template( template_id ) buf.push( "" ) ; buf.push( "" ) ; var $form = $( buf.join("") ) ; - $form.find( "select" ).select2( { minimumResultsForSearch: -1 } ) ; + $form.find( "select" ).select2( { + minimumResultsForSearch: -1 + } ).on( "select2:open", function() { + restrict_droplist_height( $(this) ) ; + } ) ; fixup_external_links( $form ) ; // initialize the "generate" button @@ -140,7 +155,11 @@ function _parse_extra_template( template_id, template ) // we have a param.type = "input" ; // extract the default value and field width diff --git a/vasl_templates/webapp/static/main.js b/vasl_templates/webapp/static/main.js index 14556d1..3bbf673 100644 --- a/vasl_templates/webapp/static/main.js +++ b/vasl_templates/webapp/static/main.js @@ -581,20 +581,8 @@ function install_template_pack( data ) gTemplatePack = data ; init_extras() ; - // sort the nationalities - var nats = Object.keys( gTemplatePack.nationalities ) ; - nats.sort( function( lhs, rhs ) { - lhs = gTemplatePack.nationalities[lhs].display_name.toUpperCase() ; - rhs = gTemplatePack.nationalities[rhs].display_name.toUpperCase() ; - if ( lhs < rhs ) - return -1 ; - else if ( lhs > rhs ) - return +1 ; - else - return 0 ; - } ) ; - // update the player droplists + var nats = get_sorted_nats() ; var curSel = { 1: $("select[name='PLAYER_1']").val(), 2: $("select[name='PLAYER_2']").val() diff --git a/vasl_templates/webapp/static/utils.js b/vasl_templates/webapp/static/utils.js index aa8991b..900151c 100644 --- a/vasl_templates/webapp/static/utils.js +++ b/vasl_templates/webapp/static/utils.js @@ -15,6 +15,23 @@ function get_player_nat( player_no ) return $( "select[name='PLAYER_" + player_no + "']" ).val() ; } +function get_sorted_nats() +{ + // sort the nationalities by display name + var nats = Object.keys( gTemplatePack.nationalities ) ; + nats.sort( function( lhs, rhs ) { + lhs = gTemplatePack.nationalities[lhs].display_name.toUpperCase() ; + rhs = gTemplatePack.nationalities[rhs].display_name.toUpperCase() ; + if ( lhs < rhs ) + return -1 ; + else if ( lhs > rhs ) + return +1 ; + else + return 0 ; + } ) ; + return nats ; +} + function get_player_colors( player_no ) { // get the colors for the specified player