{% extends "layout.html" %}
{% block content %}
	<div class="table-responsive">
		<table class="table table-striped table-bordered table-hover model-list">
			<thead>
				<tr class="info">
					<th class="col-md-1">&nbsp;</th>
          <th class="column-header">Institution/Funding Agency</th>
          <th class="column-header">Title</th>
          <th class="column-header">Translated Title</th>
          <th class="column-header">Language</th>
          <th class="column-header">Funding Type</th>
          <th class="column-header">City</th>
					<th class="column-header">State/region</th>
					<th class="column-header">Country</th>
					<th class="column-header"></th>
					<th class="column-header">Put-code</th>
				</tr>
			</thead>

			<tbody>
				{% if not records %}
					<tr>
						<td colspan="999">
							<div class="text-center">
								There are no records.
							</div>
						</td>
					</tr>
				{% endif %}
				{% for r in records %}
					<tr>
						{% if org_client_id in r["source"]["source_client_id"]["path"] %}
							<td class="list-buttons-column">
								<a class="icon"
					 href="{{url_for('edit_record', user_id=user_id, section_type=section_type, put_code=r['put_code']) }}?url={{url_for('section', user_id=user_id, section_type=section_type)}}"
			title="Edit Record">
									<span class="fa fa-pencil glyphicon glyphicon-pencil"></span>
								</a>
								<form class="icon" method="POST"
													 action="{{url_for('delete_record', user_id=user_id, section_type=section_type, put_code=r['put_code'])}}">
									<input id="put-code" name="put_code" type="hidden" value="{{r['put_code']}}">
									<input id="section-type" name="section_type" type="hidden" value="{{section_type}}">
									<button onclick="return safeConfirm('Are you sure you want to delete this record?');"
								 title="Delete record">
										<span class="fa fa-trash glyphicon glyphicon-trash"></span>
									</button>
								</form>
							</td>
						{% else %}
							<td class="list-buttons-column"></td>
						{% endif %}

						<td>
							{{r["organization"]["name"]}}<br/>
							<span class="small">
								Source: {{r["source"]["source_name"]["value"]}}
							</span>
						</td>
            <td>{{r["title"]["title"].get("value")|default("", True)}}</td>
            {% if r["title"]["translated_title"] %}
              <td>{{r["title"]["translated_title"].get("value")|default("", True)}}</td>
              <td>{{r["title"]["translated_title"].get("language_code")|default("", True)}}</td>
						{% else %}
              <td>{{r["title"]["translated_title"]|default("", True)}}</td>
              <td>{{r["title"]["translated_title"]|default("", True)}}</td>
						{% endif %}
            <td>{{r.get("type", "")|default("", True)}}</td>
            <td>{{r["organization"]["address"].get("city")|default("", True)}}</td>
						<td>{{r["organization"]["address"].get("region", "")|default("", True)}}</td>
						<td>{{r["organization"]["address"].get("country", "")}}</td>
						<td>{{r|year_range}}</td>
						<td>{{r.get("put_code")}}</td>
					</tr>
				{% endfor %}
			</tbody>
		</table>
		<div style="text-align:right;">
      <a role="button" class="btn btn-danger" href="{{ url_for('viewmembers.index_view')}}">Back to View/Export People</a>
			<a role="button" class="btn btn-primary" href="{{url_for('edit_record', user_id=user_id, section_type=section_type)}}">New...</a>
		</div>
	</div>
{% endblock %}
