{% extends request.is_ajax|yesno:'nullcont.htm,devapp/ext.htm' %}
{% load i18n bootstrap3 %}

{% block title %}{{ form.comment.value }}{% endblock %}

{% block content %}

<div class="panel panel-default">
    <div class="panel-heading">
        <h3 class="panel-title">{% trans 'Device info' %}</h3>
    </div>
    <div class="panel-body">

        <form autocomplete="off" action="{% url 'devapp:edit' group.pk|default:0 dev.pk %}" method="post">{% csrf_token %}

            {% bootstrap_icon 'globe' as ic %}
            {% bootstrap_field form.ip_address addon_before=ic %}

            {% bootstrap_icon 'globe' as ic %}
            {% bootstrap_field form.mac_addr addon_before=ic %}

            {% bootstrap_icon 'comment' as ic %}
            {% bootstrap_field form.comment addon_before=ic %}

            {% bootstrap_icon 'hdd' as ic %}
            {% bootstrap_field form.devtype addon_before=ic %}

            {% bootstrap_icon 'lock' as ic %}
            {% bootstrap_field form.man_passw addon_before=ic %}

            {% bootstrap_icon 'subscript' as ic %}
            {% bootstrap_field form.group addon_before=ic %}

            <div class="form-group">
                <label for="id_parent_dev">{% trans 'Parent device' %}</label>

                <div class="input-group selectajax" data-dst="/dev/search_dev">
                    <span class="input-group-addon"><span class="glyphicon glyphicon-hdd"></span></span>
                    <input type="hidden" name="parent_dev" class="selectajax-hid" {% if selected_parent_dev %}
                           value="{{ selected_parent_dev.pk }}" {% endif %}>
                    {% if selected_parent_dev %}
                    <button class="selectajax-btn form-control btn btn-default">{{ selected_parent_dev.comment }}
                    </button>
                    <input type="text" class="form-control dropdown-toggle selectajax-inp hidden" data-toggle="dropdown"
                           id="id_parent_dev" placeholder="{% trans 'Find the device' %}">
                    {% else %}
                    <button class="selectajax-btn form-control btn btn-default hidden"></button>
                    <input type="text" class="form-control dropdown-toggle selectajax-inp" data-toggle="dropdown"
                           id="id_parent_dev" placeholder="{% trans 'Find the device' %}">
                    {% endif %}
                    <ul class="dropdown-menu selectajax-ul"></ul>
                    {{ form.parent_dev.errors }}
                </div>
            </div>

            {% bootstrap_icon 'list-alt' as ic %}
            {% bootstrap_field form.snmp_extra addon_before=ic %}

            {% bootstrap_field form.is_noticeable %}

            {% with grp_id=group.pk|default:0 %}
            <div class="btn-group btn-group-sm">
                <button type="submit" class="btn btn-primary">
                    <span class="glyphicon glyphicon-save"></span> {% trans 'Save' %}
                </button>
                {% if perms.devapp.delete_device %}
                    <a href="{% url 'devapp:del' grp_id dev.pk %}" class="btn btn-danger btn-modal">
                        <span class="glyphicon glyphicon-remove"></span> {% trans 'Delete' %}
                    </a>
                {% else %}
                    <a href="#" class="btn btn-danger disabled" title="{% trans 'Permission denied' %}" data-toggle="tooltip">
                        <span class="glyphicon glyphicon-remove"></span> {% trans 'Delete' %}
                    </a>
                {% endif %}
                {% if perms.devapp.change_device %}
                    <a href="{% url 'devapp:dev_register' grp_id dev.pk %}" class="btn btn-default btn-cmd" data-form-val="#{{ form.snmp_extra.id_for_label }}">
                        <span class="glyphicon glyphicon-fire"></span> {% trans 'Register device' %}
                    </a>
                    <a href="{% url 'devapp:reboot' dev.pk %}" class="btn btn-default btn-modal">
                        <span class="glyphicon glyphicon-refresh"></span> {% trans 'Reboot' %}
                    </a>
                    <a href="{% url 'devapp:extra_data_edit' grp_id dev.pk %}" class="btn btn-default btn-modal">
                        <span class="glyphicon glyphicon-cog"></span> <span class="hidden-xs">{% trans 'Tech date' %}</span>
                    </a>
                {% endif %}
            </div>
            {% endwith %}

        </form>
    </div>
</div>

{% endblock %}
