{% extends "itsapp/base.html" %}

{% block title %}
	Edit gallery
{% endblock %}

{% block content %}
	{% if user.is_authenticated %}
		<p class="form-message">{{ msg }}</p>
		{% if state %}
		{% else %}
			{% if permit %}
				<h2>Gallery name</h2>
				<form class="form" action="{% url gallery_permissions gallery.identificator  %}" method="post">
					{% csrf_token %}
					{{ form1.as_p }}
					<input type="hidden" name="formname" value="">
					<input type="submit" value="Submit" />
				</form>

				<h2>Add/edit gallery permissions</h2>
				<form class="form" action="{% url gallery_permissions gallery.identificator  %}" method="post">
					<table>
						<tr>
							<th>group</th>
							<th>permission</th>
							<th>delete</th>
						</tr>

						{% for permission in permissions %}
							<tr>
								<td>{{ permission.clan }}</td>
								<td>
									{% if permission.permission == 0 %}
										No permissions
									{% endif %}
									{% if permission.permission == 1 %}
										Write only
									{% endif %}
									{% if permission.permission == 2 %}
										Read only
									{% endif %}
									{% if permission.permission == 3 %}
										Read and write
									{% endif %}
								</td>
								<td><a href="{% url gallery_permissions_remove gallery.identificator permission.id %}">delete</a></td>
							</tr>
						{% endfor %}
					</table>

					{% csrf_token %}
					{{ form2.as_p }}
					<input type="hidden" name="formpermission" value="">
					<input type="submit" value="Submit" />
				</form>
			{% else %}
				<p class="form-message">Edit permission denied.</p>
			{% endif %}
		{% endif %}
	{% else %}
		<a href="/login">login</a>
	{% endif %}
{% endblock %}
