{% extends '_base.html' %}
{% load static from staticfiles %}
{% load form_helpers %}

{% block title %}{% if secret.pk %}Editing Secret: {{ secret }}{% else %}Add a Secret{% endif %}{% endblock %}

{% block content %}
{% if secret.pk %}
	<h1>Editing Secret: {{ secret }}</h1>
{% else %}
	<h1>Add a Secret</h1>
{% endif %}
<form action="." method="post" class="form form-horizontal requires-private-key">
    {% csrf_token %}
    {{ form.private_key }}
    <div class="row">
        <div class="col-md-6 col-md-offset-3">
            {% if form.non_field_errors %}
                <div class="panel panel-danger">
                    <div class="panel-heading"><strong>Errors</strong></div>
                    <div class="panel-body">
                        {{ form.non_field_errors }}
                    </div>
                </div>
            {% endif %}
        </div>
    </div>
    <div class="row">
        <div class="col-md-6">
            <div class="panel panel-default">
                <div class="panel-heading"><strong>Secret Attributes</strong></div>
                <div class="panel-body">
                    <div class="form-group">
                        <label class="col-md-3 control-label required">Device</label>
                        <div class="col-md-9">
                            <p class="form-control-static">{{ secret.device }}</p>
                        </div>
                    </div>
                    {% render_field form.role %}
                    {% render_field form.name %}
                    {% render_field form.userkeys %}
                </div>
            </div>
        </div>
        <div class="col-md-6">
            <div class="panel panel-default">
                <div class="panel-heading"><strong>Secret Data</strong></div>
                <div class="panel-body">
                    {% if secret.pk %}
                        <div class="form-group">
                            <label class="col-md-3 control-label required">Current Plaintext</label>
                            <div class="col-md-9">
                                <p class="form-control-static">********</p>
                            </div>
                        </div>
                    {% endif %}
                    {% render_field form.plaintext %}
                    {% render_field form.plaintext2 %}
                </div>
            </div>
        </div>
    </div>
    <div class="row">
        <div class="form-group">
            <div class="col-md-12 text-center">
                {% if secret.pk %}
                    <button type="submit" name="_update" class="btn btn-primary">Update</button>
                    <a href="{% url 'secrets:secret' pk=secret.pk %}" class="btn btn-default">Cancel</a>
                {% else %}
                    <button type="submit" name="_create" class="btn btn-primary">Create</button>
                    <button type="submit" name="_addanother" class="btn btn-primary">Create and Add Another</button>
                    <a href="{{ cancel_url }}" class="btn btn-default">Cancel</a>
                {% endif %}
		    </div>
        </div>
    </div>
</form>

{% include 'secrets/inc/private_key_modal.html' %}
{% endblock %}

{% block javascript %}
<script src="{% static 'js/secrets.js' %}"></script>
{% endblock %}
