{% extends "template.html" %}
{% block head %}
	{{ super() }}
	<script type=text/javascript>
		$SCRIPT_ROOT = {{ request.script_root|tojson|safe }};
	</script>
	<script type=text/javascript>
	  $(function() {
		$('a#exec').bind('click', function() {
		  $.getJSON($SCRIPT_ROOT + '/_background_exec', {
			cmd: $('select[name="command"]').val(),
		  }, function(data) {
			$("#exec_txt").text(data.exec_txt);
		  });
		});
	  });
	</script>
	<script type="text/javascript">
		$(function() {
			$('#gobtn').bind('click', function() {
				$('#select_project').submit();
				$("#gobtn").attr("disabled", true);
				$('#gobtn').html('LOADING PROJECT DATA <i class="fa fa-spinner fa-pulse fa-fw"></i>');
			});
		});
	</script>
{% endblock %}
{% block title %}Index{% endblock %}
{% block content %}
	<div class="container px-lg-3 mt-3">
		<div class="row">
			<div class="col">
				<div class="card">
					<div class="card-header"><b>Select a project</b></div>
					<div class="card-body">
						<form id="select_project" class="form" method="POST" action="{{ url_for('process') }}">
							<div class="form-group row">
								<input name="_csrf_token" type="hidden" value="{{ csrf_token() }}">
								<div class="col-xl-12">
									<div class="list-group">
										{% if reset_btn is not none %}
											<div class="alert alert-secondary" role="alert">
												<button type="button" class="close" data-dismiss="alert">&times;</button>
												Reset currently activated project to select other ones
											</div>
										{% endif %}
										{% if selected is none %}
											{% set cls = "list-group-item list-group-item-action" %}
										{% else %}
											{% set cls = "list-group-item list-group-item-action disabled" %}
										{% endif %}
										{% for p in projects %}
											{% if loop.index == selected_id | int  %}
												{% set cls = "list-group-item list-group-item-action list-group-item-secondary" %}
											{% endif %}
											<button type="submit" name="select_project" class="{{ cls }}" value="{{ p }};{{ loop.index }}">
												{{ p }}
											</button>
										{% endfor %}
									</div>
								</div>
							</div>
						</form>
					</div>
					<div class="card-footer text-muted">
					{% if reset_btn is not none %}
						<a href="{{ url_for('index', reset=True) }}" class="btn btn-outline-danger" role="button" aria-disabled="false">
							RESET PROJECT <i class="fa fa-undo"></i>
						</a>
					{% else %}
						<a href="{{ url_for('index', reset=True) }}" class="btn btn-outline-danger disabled" role="button" aria-disabled="true">
							RESET PROJECT <i class="fa fa-undo"></i>
						</a>
					{% endif %}
					<a href="/preferences" role="button" class="btn btn-outline-dark ml-2">PREFERENCES <i class="fa fa-cog"></i></a>
					</div>
				</div>
			</div>
		</div>
	</div>
{% endblock %}
