Added an extras template to generate a grid.

master
Pacman Ghost 5 years ago
parent 187faa112b
commit 5667eaa0a5
  1. 27
      vasl_templates/webapp/data/default-template-pack/extras/grid.j2
  2. 25
      vasl_templates/webapp/static/extras.js
  3. 14
      vasl_templates/webapp/static/main.js
  4. 17
      vasl_templates/webapp/static/utils.js

@ -0,0 +1,27 @@
<html> <!-- vasl-templates:id {{SNIPPET_ID}} -->
<!-- vasl-templates:name Grid -->
<!-- vasl-templates:description Generates a grid. -->
<!-- #cols = {{COLS:3/2|# columns}} ; #rows = {{ROWS:2/2|# rows}} ; color = {{PLAYER_COLOR2_DROPLIST_EX:|Border color}} -->
<style>
td {
width: {{WIDTH:160px/5|Cell width}} ;
height: {{HEIGHT:60px/5|Cell height}} ;
border: 1px solid {{PLAYER_COLOR2_DROPLIST}} ;
}
</style>
</head>
<table>
{% 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 %}
<tr>
{% 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 %} <td> {%endif%}
{%endfor%}
{%endif%}
{%endfor%}
</table>
</html>

@ -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( "<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 )
@ -88,9 +89,19 @@ function _show_extra_template( template_id )
buf.push( ">" ) ;
} else if ( template_info.params[i].type === "select" ) {
buf.push( "<select class='param' name='" + escapeHTML(template_info.params[i].name) + "'>" ) ;
for ( var j=0 ; j < template_info.params[i].options.length ; ++j )
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:9em;'>" ) ;
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>" ) ;
}
buf.push( "</select>" ) ;
}
}
buf.push( "</table>" ) ;
@ -98,7 +109,11 @@ function _show_extra_template( template_id )
buf.push( "<button class='generate' data-id='" + template_info.template_id + "'>Snippet</button>" ) ;
buf.push( "</div>" ) ;
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 <select>
param.type = "select" ;
param.options = val.split( "::" ) ;
} else {
} 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 {
// we have an <input>
param.type = "input" ;
// extract the default value and field width

@ -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()

@ -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

Loading…
Cancel
Save