{% extends "layout.html" %}

{% block title %}manage instances{% endblock %}

{% load bootstrap3 %}
{% block content %}
<div class="container-fluid">
    <div class="row">

  	<div class="col-md-2"></div>

  	<div class="col-md-8">
		
  	    {% if formset.total_form_count > 0 %}

			<form id='instancesform' action="/instances/" method="post" class="form">
			{{ formset.management_form }}
	    	<table class="table table-striped">
		    	<thead>
		    		<tr>
		    		{% for column_name in columns %}
		    		<th>{{ column_name }}</th>
		    		{% endfor %}
		    		<th></th>
		    		</tr>
		    	</thead>
		    	<tbody>
		        {% for form in formset %}

				    {{ form.id }}
		        		        	
				    {% csrf_token %}  

		        	<tr>
				    {% for field in form.visible_fields %}					
		            	<td> {{ field }} </td>
		        	{% endfor %}
		        		<td>
		        			<button name="_save" type="submit" class="btn btn-default" value="save-{{ form.id.value }}">
					            Save
					        </button>
					        <button name="_start" type="submit" class="btn btn-primary" value="start-{{ form.id.value }}">
					            Start
					        </button>
							<button name="_stop" type="submit" class="btn btn-warning" value="stop-{{ form.id.value }}">
					            Stop
					        </button>				        
					        <button name="_trash" type="submit" class="btn btn-danger" value="trash-{{ form.id.value }}">
					            Trash
					        </button>
				        </td>
					</tr>

		        {% endfor %}
		        </tbody>
	    	</table>
			</form>

	
			



		{% else %}

			<h4> There were no instances found. Consider cloning a new one.</h4>
		
		{% endif %}
	</div>

	<div class="col-md-2"></div>

	</div>
</div>

{% endblock %}


{% block bottomjs %}
<script type="text/javascript"> <!--
	// jQuery( document ).ready(function( $ ) {
	//    $('#instancesform tbody tr').formset();
	// });
	// refresh page every 10 sec.
	setInterval(function(){
		location.reload();
	}, 4000);
--></script>
{% endblock %}
