{% extends "base.html" %}

{% block title %}
	EDI Viewer
{% endblock %}

{% block nav %}
	EDI Viewer
{% endblock %}

{% block content %}
	<form enctype="multipart/form-data" method="post" action="/edi_viewer">
		<fieldset>
			<legend>View EDI File</legend>	
			<input type="file" name="edi_file" size="45" value="{{request.values.edi_file}}">
			<input type="submit" value="View">
		</fieldset>
	</form>

	<form method="post" action="/edi_viewer">
		<fieldset>
			<legend>View EDI Fragment</legend>	
			<label>Fragment</label> {{input_textarea('edi_fragment', '', 10, 80)}}
			<input type="submit" value="View">
		</fieldset>
	</form>

	{% if segments %}
		<p>
			Parsed
			{% if file_name %}
				{{file_name}}
			{% else %}
				Fragment
			{% endif %}
		</p>
		{% for segment in segments %}
			<table>
				<caption>{{segment.name}} - {{segment.description}}</caption>
				<thead>
					<tr>
						{% for title in segment.titles_element %}
							<th colspan="{{title.colspan}}" rowspan="{{title.rowspan}}">
								{{title.code}} {{title.value}}
							</th>
						{% endfor %}
					</tr>
					<tr>
						{% for title in segment.titles_component %}
							<th>{{title}}</th>
						{% endfor %}
					</tr>
				</thead>
				<tbody>
					<tr>
						{% for val in segment.vals %}
							<td>{{val}}</td>
						{% endfor %}
					</tr>
				</tbody>
			</table>

			<pre>{{segment.raw_line}}</pre>

		{% endfor %}

	{% endif %}

{% endblock %}
