{% extends "base.html" %}
{% load i18n %}
{% load bootstrap_tags %}

{% block main_content %}
<div id="dialog-add-group" class="modal hide" tabindex="-1" role="dialog" aria-labelledby="dialog-key-label" aria-hidden="true">
    <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
        <h3 id="dialog-key-label">{% trans 'Add Group' %}</h3>
    </div>
    <div class="modal-body">
        <form id="form-add-group" class="form-horizontal">
            <div class="control-group">
                 <label class="control-label" for="inputName">{% trans 'Name' %}</label>
                 <div class="controls">
                   <input type="text" id="inputName" name="name" class="required" />
                 </div>
            </div>
            <div class="control-group">
                 <label class="control-label" for="description">{% trans 'Description' %}</label>
                 <div class="controls">
                   <textarea id="description" name="description"></textarea>
                 </div>
            </div>
        </form>
    </div>
    <div class="modal-footer">
        <a href="#" id="btn-create-group" class="btn btn-primary">{% trans 'Create' %}</a>
    </div>
</div>

<div class="toolbar pull-right">
    <a href="#dialog-add-group" class="btn" role="button" data-toggle="modal"><i class="icon icon-plus"></i> {% trans 'Add Group' %}</a>
</div>
<div class="credential-groups">
    {% if credential_groups.all %}
    <ul class="thumbnails">
        {% for group in credential_groups.all %}
        <li class="span3 group">
            <a href="{% url "vault.group" uuid=group.uuid %}" class="thumbnail">
                <div class="entypo large">&#128196;</div>
                <div class="caption">
                    <h3>{{group.name|truncatechars:"15"}}</h3>
                </div>
            </a>
        </li>
        {% endfor %}
    </ul>
    {% else %}
    <p class="lead muted">{% trans 'No groups' %}</p>
    {% endif %}
</div>
<script type="text/javascript">
    function createGroup() {
        var data = $("#form-add-group").serializeObject();
        if ($("#form-add-group").valid()) {
            createCredentialGroup(data, function(res) {
                redirect("{% url "index" %}");
                return false;
            });
        }
    }
    $("#form-add-group input").keypress(function(e) {
        if (e.keyCode == 13) {
            createGroup();
            return false;
        }
    });
    $("#btn-create-group").click(function() {
        createGroup();
        return false;
    });
    $(function() {
        $("#form-add-group").validate();
    });
</script>
{% endblock %}
