{% extends "bootstrapheader.html" %}

{% block body %}
<body>
<div class="container">
<h2>Home</h2>
Loged in as {{email}}


<div class=container>

{% for m in msg %}
	<div class="alert alert-{{m["type"]}}">
	<a href="#" class="close" data-dismiss="alert" aria-label="close">&times;</a>
	{{m["msg"]}}
</div>
{% endfor %}

	<h3>My Experiments:</h3>
	<div class="panel-group" id="accordion">

			{% if experiments %}
			{% for dict_item in experiments %}
			<div class="panel panel-default">
				<div class="panel-heading">
					<h4 class="panel-title">
						<a data-toggle="collapse" data-parent="#accordion" href="#collapse{{dict_item['eid']}}">{{dict_item['name']}}</a>
					</h4>
				</div>
				<div id="collapse{{dict_item['eid']}}" class="panel-collapse collapse">
					<div class="panel-body">
						<div class="container">
						<h4>Description:</h4>
						<p>
							{{dict_item['description']}}
						</p>
						<p>
							Experiment date: {{dict_item['date']}}
						</p>
						<form class="form-inline" name="options" role="form" action="#" method="post">
							<input type="hidden" name="deid" value="{{dict_item['eid']}}">
							<button type="submit" class="btn btn-primary" name="eid" value="{{dict_item['eid']}}" OnClick="SetDestView(this)">View</button>
							<button type="submit" class="btn btn-danger" name="deid" value="{{dict_item['eid']}}">Delete</button>
						</form>
						</div>
					</div>
				</div>
			</div>
			{% endfor %}
			{% endif %}

	</div>

	<form class="form-inline" role="form" action="/experiment" method="post">
		<div class="form-group">
		<label for="expname">Name: </label>
		<input type="text" class="form-control" id="expname" name="expname" placeholder="New experiment name" required>
		</div>
		<div class="form-group">
		<label for="inpeaks">Peaks: </label>
		<input type="text" class="form-control" id="inpeaks" name="inpeaks" placeholder="Experiment Peaks" value = "1257.4,1419.5,1581.5,1743.6,1809.7,1905.6" required>
		</div>
		<button type="submit" class="btn btn-primary">New Experiment</button>
	</form>

</div> <!-- /container -->

<div id="confirm" class="modal fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
	<div class="modal-dialog">
		<div class="modal-content">
            <div class="modal-header">
            	Confirm Submit
            </div>
  			<div class="modal-body">
    		Are you sure you want to delete the experiment?
  			</div>
  			<div class="modal-footer">
    			<button type="button" data-dismiss="modal" class="btn btn-primary" id="delete">Delete</button>
   				 <button type="button" data-dismiss="modal" class="btn">Cancel</button>
  			</div>
  		</div>
  	</div>
</div>

<div class=container>

{% if col_experiments %}
	<h3>Collaborations:</h3>
	<div class="panel-group" id="accordion">

			{% for dict_item in col_experiments %}
			<div class="panel panel-default">
				<div class="panel-heading">
					<h4 class="panel-title">
						<a data-toggle="collapse" data-parent="#accordion" href="#collapse{{dict_item['eid']}}">{{dict_item['name']}}</a>
					</h4>
				</div>
				<div id="collapse{{dict_item['eid']}}" class="panel-collapse collapse">
					<div class="panel-body">
						<div class="container">
						<h4>Description:</h4>
						<p>
							{{dict_item['description']}}
						</p>
						<p>
							Experiment date: {{dict_item['date']}}
						</p>
						<form class="form-inline" name="options" role="form" action="" method="post">
							<button type="submit" class="btn btn-primary" name="eid" value="{{dict_item['eid']}}" OnClick="SetDestView(this)">View</button>
						</form>
						</div>
					</div>
				</div>
			</div>
			{% endfor %}
{% endif %}

	</div>
</div> <!-- /container -->

<SCRIPT LANGUAGE="JavaScript">
        function SetDestView(element) {
            element.form.action = "/experiment";
        }

        function SetDestDelete(element) {
            element.form.action = "/";
        }

	$('button[name="deid"]').on('click', function(e){
	    e.preventDefault();
	    var $form=$(this).closest('form');
	    $('#confirm').modal({ backdrop: 'static', keyboard: false })
	        .one('click', '#delete', function (e) {
	           $form.action = "/"
	           $form.submit();
	        });
	});

</script> 

</body>

{% endblock %}