Newer
Older
<!DOCTYPE html>
<html>
<head>
{% for src in js %}
<script type="text/javascript" src="{{ src }}"></script>
{% endfor %}
{% for src in css %}
<link type="text/css" rel="stylesheet" href="{{ src }}">
{% endfor %}
<script type="text/javascript" src="{{ url_for( 'send_app_files', path = 'functions.js' ) }}"></script>
<link type="text/css" rel="stylesheet" href="{{ url_for( 'send_app_files', path = 'app.css' ) }}">
<script type="text/javascript">
baseurl = "{{ baseurl }}";
var start_f1_f5_button = false;
var start_hv = false;
var points = [];

Marco De Donno
committed
var zones_array = new Array();
{% for zone in zones %}
zones_array.push( {{ zone[ 'pc' ] }} );
{% endfor %}
var data_columns = new Array();
{% for d in datacolumns %}
data_columns.push( "{{ d }}" );
{% endfor %}
var dpc = {{ card_img_info[ 'dpc' ] }};
var svg_width = {{ svg_width }};
var svg_height = {{ svg_height }};
var clear = function()
{
$( 'input' ).val( "" );
updateSVG();
}

Marco De Donno
committed
var update_zone_coordinates = function( pc, coordinate, value )
{
if( value )
{
$.ajax( {
url: "{{ url_for( 'update_zone_coordinates', card = card_id ) }}",
dataType: 'json',
method: 'POST',
data: {
pc: pc,
coordinate: coordinate,
value: value
},
success: function( data )
{
if( ! data.error )
{
updateSVG();
}
}
} );
} else {
updateSVG();
}

Marco De Donno
committed
}
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
var updateSVG = function()
{
var zonesData = {};
for( var i = 0; i < zones_array.length; i++ )
{
var pc = zones_array[ i ];
zonesData[ pc ] = {}
for( var j = 0; j < data_columns.length; j++ )
{
var z = data_columns[ j ];
var v = $( '#icnml_zone_' + pc + '_' + z + ' > input' ).val()
zonesData[ pc ][ z ] = parseFloat( v );
}
}
$( "#tp_polygones" ).empty();
for( var i = 0; i < zones_array.length; i++ )
{
var pc = zones_array[ i ];
var $svg = $( "#tp_polygones" );
var a = zonesData[ pc ][ 'tl_x' ] * dpc + "," + zonesData[ pc ][ 'tl_y' ] * dpc;
var b = zonesData[ pc ][ 'br_x' ] * dpc + "," + zonesData[ pc ][ 'tl_y' ] * dpc;
var c = zonesData[ pc ][ 'br_x' ] * dpc + "," + zonesData[ pc ][ 'br_y' ] * dpc;
var d = zonesData[ pc ][ 'tl_x' ] * dpc + "," + zonesData[ pc ][ 'br_y' ] * dpc;
var p = a + " " + b + " " + c + " " + d;
if( ! p.includes( "NaN" ) )
{
$( SVG( 'polygon' ) )
.attr( 'id', 'pc_' + pc )
.attr( 'points', p )
.attr( 'fill', 'rgb( 255, 0, 0 )' )
.attr( 'fill-opacity', '0.1' )
.attr( 'stroke', 'red' )
.attr( 'stroke-width', '1' )
.appendTo( $svg );
}
}
}
<div class="icnml_central" style="height: {{ svg_height }}px; width: {{ svg_width * 2 }}px">
<div class="icnml_tp_cardbox">
<div style="width: {{ svg_width }}px; height: {{ svg_height }}px">
<svg id="template_svg" width="100%" height="100%">
<defs>
<clipPath id="zoom_circle_clipping">
<circle cx="0" cy="0" r="30" fill="#FFFFFF"/>
</clipPath>
</defs>
<image x="0" y="0" width="100%" height="100%" xlink:href="/tenprint_template/image/{{ card_id }}/{{ t }}"></image>
<g id="tp_polygones"></g>
<line x1="{{ card_img_info[ 'right' ] }}" y1="0" x2="{{ card_img_info[ 'right' ] }}" y2="{{ svg_height }}" style="stroke:rgb(0,0,255); stroke-width: 2" />
<line x1="0" y1="{{ card_img_info[ 'bottom' ] }}" x2="{{ svg_width }}" y2="{{ card_img_info[ 'bottom' ] }}" style="stroke:rgb(0,0,255); stroke-width: 2" />
<svg id="template_svg_zoom" x="0" y="0" width="150" height="150" viewBox="0 0 150 150" visibility="hidden" clip-path="url( #zoom_circle_clipping )">
<image x="0" y="0" width="{{ svg_width }}" height="{{ svg_height }}" xlink:href="/tenprint_template/image/{{ card_id }}/{{ t }}" />
</svg>
<line id="helper" x1="0" y1="0" x2="0" y2="0" style="stroke:rgb(0,0,255); stroke-width: 2" />
<div>
<div class="icnml_box_fields">
<div>Tenprint id</div>
<div>{{ img_info[ 'id' ] }}</div>
<div>Country code</div>
<div>{{ img_info[ 'country_code' ] }}</div>
<div>Size</div>
<div>{{ img_info[ 'width' ] }} / {{ img_info[ 'height' ] }} [cm]</div>
<div>Format</div>
<div>{{ img_info[ 'size_display' ] }}</div>
</div>
<div id="tenprint_zones_table">
<div></div>
<div>Top left x</div>
<div>Top left y</div>
<div>Bottom right x</div>
<div>Bottom right y</div>
<div>Rotation</div>
{% for zone in zones %}
<div id="icnml_zone_{{ zone[ 'pc' ] }}_name" style="padding-right: 20px">{{ zone[ 'pc_name' ] }}</div>
<div id="icnml_zone_{{ zone[ 'pc' ] }}_tl_x">
<input class="tenprint_zones_table_input" value="{{ zone[ 'tl_x' ] }}">
</div>
<div id="icnml_zone_{{ zone[ 'pc' ] }}_tl_y">
<input class="tenprint_zones_table_input" value="{{ zone[ 'tl_y' ] }}">
</div>
<div id="icnml_zone_{{ zone[ 'pc' ] }}_br_x">
<input class="tenprint_zones_table_input" value="{{ zone[ 'br_x' ] }}">
</div>
<div id="icnml_zone_{{ zone[ 'pc' ] }}_br_y">
<input class="tenprint_zones_table_input" value="{{ zone[ 'br_y' ] }}">
</div>
<div id="icnml_zone_{{ zone[ 'pc' ] }}_angle">
<input class="tenprint_zones_table_input" value="{{ zone[ 'angle' ] }}">
</div>
{% endfor %}
</div>
<div style="margin-top: 20px">
<div>
<a class="ui-button ui-widget ui-state-default ui-corner-all ui-button-text-only" id="start_f1_f5_button" role="button" aria-disabled="false">
<span class="ui-button-text">Start F1-F5</span>
</a>
<a class="ui-button ui-widget ui-state-default ui-corner-all ui-button-text-only" id="start_hv_button" role="button" aria-disabled="false">
<span class="ui-button-text">Start HV</span>
</a>
</div>
<div>
<a class="ui-button ui-widget ui-state-default ui-corner-all ui-button-text-only" id="clear_button" role="button" aria-disabled="false">
<span class="ui-button-text">Clear</span>
</a>
</div>
</div>
</div>
</div>
</body>
<script type="text/javascript">
zoomed = false;
zoom_factor = 5;
$( '#template_svg' ).on( 'contextmenu', function( event )
$( '#helper' )
.attr( 'x1', 0 )
.attr( 'x2', 0 )
.attr( 'y1', 0 )
.attr( 'y2', 0 );
if( ! zoomed )
{
zoomed = true;
var x = event.offsetX - 15;
var y = event.offsetY - 15;
var tmp_zoom_size = 150 / zoom_factor;
$( '#template_svg_zoom' )
.attr( 'visibility', 'show' )
.attr( 'x', event.offsetX - 75 )
.attr( 'y', event.offsetY - 75 )
.attr( 'viewBox', x + " " + y + " " + tmp_zoom_size + " " + tmp_zoom_size )
$( '#zoom_circle_clipping > circle' )
.attr( "cx", event.offsetX )
.attr( "cy", event.offsetY )
} else {
zoomed = false;
$( '#template_svg_zoom' )
.attr( 'visibility', 'hidden' );
}
$( '#template_svg_zoom' ).on( 'click', function( event )
{
event.preventDefault();
if( zoomed )
{
var e = event.target;
var dim = e.getBoundingClientRect();
var x = event.clientX - dim.left;
var y = event.clientY - dim.top;
x = x / zoom_factor;
y = y / zoom_factor;
x = x / {{ card_img_info[ 'dpc' ] }};
y = y / {{ card_img_info[ 'dpc' ] }};
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
x = x.toFixed( 2 );
y = y.toFixed( 2 );
x = parseFloat( x );
y = parseFloat( y );
if( start_f1_f5_button )
{
points.push( { x: x, y: y } );
if( points.length == 2 )
{
var start = points[ 0 ];
var end = points[ 1 ];
if( end.x - start.x > 5.08 )
{
var dx = ( end.x - start.x ) / 5;
for( var f = 0; f < 5; f++ )
{
var a = start.x + f * dx;
var b = start.x + ( f + 1 ) * dx;
$( '#icnml_zone_' + ( f + 1 ) + '_tl_x > input' ).val( a );
$( '#icnml_zone_' + ( f + 1 ) + '_tl_y > input' ).val( start.y );
$( '#icnml_zone_' + ( f + 1 ) + '_br_x > input' ).val( b );
$( '#icnml_zone_' + ( f + 1 ) + '_br_y > input' ).val( end.y );
}
}
updateSVG();
points = [];
start_f1_f5_button = false;
}
} else if( start_hv )
{
points.push( { x: x, y: y } );
console.log( points );
if( points.length == 8 )
{
for( var i = 1; i <= 5; i++ )
$( '#icnml_zone_' + i + '_tl_y > input' ).val( points[ 0 ].y );
for( var i = 1; i <= 5; i++ )
$( '#icnml_zone_' + i + '_br_y > input' ).val( points[ 1 ].y );
for( var i = 1; i <= 5; i++ )
{
$( '#icnml_zone_' + i + '_tl_x > input' ).val( points[ i + 1 ].x );
$( '#icnml_zone_' + i + '_br_x > input' ).val( points[ i + 2 ].x );
}
updateSVG();
points = [];
start_hv = false;
}
}
zoomed = false;
$( '#template_svg_zoom' )
.attr( 'visibility', 'hidden' );
}
{% for zone in zones %}
$( '#icnml_zone_{{ zone[ 'pc' ] }}_name' )
.on( 'mouseover', function()
{
$( "#pc_{{ zone[ 'pc' ] }}" )
.attr( 'fill', 'rgb( 0, 0, 255 )' )
.attr( 'stroke', 'rgb( 0, 0, 255 )' )
} )
.on( 'mouseout', function()
{
$( "#pc_{{ zone[ 'pc' ] }}" )
.attr( 'fill', 'rgb( 255, 0, 0 )' )
.attr( 'stroke', 'rgb( 255, 0, 0 )' )
} )

Marco De Donno
committed
{% for d in datacolumns %}
$( "#icnml_zone_{{ zone[ 'pc' ] }}_{{ d }} > input" )
.on( 'change', function()
{
update_zone_coordinates( "{{ zone[ 'pc' ] }}", "{{ d }}", $( this ).val() );
} );
{% endfor %}
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
$( '#template_svg' ).on( 'mousemove', function( event )
{
if( start_hv && ! zoomed )
{
if( points.length < 2 )
{
$( '#helper' )
.attr( 'x1', 0 )
.attr( 'x2', svg_width )
.attr( 'y1', event.offsetY )
.attr( 'y2', event.offsetY );
} else {
$( '#helper' )
.attr( 'x1', event.offsetX )
.attr( 'x2', event.offsetX )
.attr( 'y1', 0 )
.attr( 'y2', svg_height );
}
}
} );
$( '#start_f1_f5_button' ).on( 'click', function()
{
clear();
start_f1_f5_button = true;
} );
$( '#start_hv_button' ).on( 'click', function()
{
clear();
start_hv = true;
} );
$( '#clear_button' ).on( 'click', clear );
updateSVG();