{% extends 'base.html' %}
{% load buttons %}
{% load static %}
{% load helpers %}
{% load custom_links %}
{% load plugins %}

{% block title %}{{ service }}{% endblock %}

{% block header %}
    {% include 'config_officer/navi_panel.html' %}
    <div class="col-md-10">
        <div class="row noprint">
            <ol class="breadcrumb">
                <li><a href="{% url 'plugins:config_officer:service_list' %}">services</a></li>
                <li>{{ service }}</li>
            </ol>
        </div>

        <div class="pull-right noprint">
            <a href="{% url 'plugins:config_officer:service_edit' pk=service.pk %}" class="btn btn-warning">
                <span class="glyphicon glyphicon-pencil" aria-hidden="true"></span> Edit
            </a>   
            <a href="{% url 'plugins:config_officer:service_delete' pk=service.pk %}" class="btn btn-danger">
                <span class="glyphicon glyphicon-trash" aria-hidden="true"></span> Delete
            </a>                                      
        </div>
        <h1>{{ service.name }}</h1>    
    </div>
{% endblock %}

{% block content %}
    <div class="row">
        <div class="col-md-10">
            <div class="panel panel-default">
                <table class="table table-hover panel-body attr-table">
                    <tr>
                        <td>Name</td>
                        <td><span>{{ service.name|placeholder }}</span></td>
                    </tr>                   
                    <tr>
                        <td>Description</td>
                        <td><span>{{ service.description|placeholder }}</span></td>
                    </tr>
                </table>                      
            </div>
        </div>
    </div>
    <div class="row">
        <div class="col-md-10">    
            <div class="panel panel-default">
                <div class="panel-heading">                    
                        <strong>Rules</strong>
                    <span class="pull-right">
                        <a href="{% url 'plugins:config_officer:service_rule_add' %}?service={{ service.pk }}&return_url={{ service.get_absolute_url }}" class="btn btn-primary btn-xs">
                            <span class="glyphicon glyphicon-plus" aria-hidden="true"></span>
                            Add a rule
                        </a>               
                    </span>     
                </div>
                {% if service_rules %}
                    <table class="table table-hover panel-body">
                        <tr>
                            <th>Device role</th>
                            <th>Device type</th>
                            <th>Template</th>
                            <th>Description</th>
                            <th></th>
                        </tr>
                        {% for rule in service_rules %}
                            <tr>
                                <td>
                                    {% if rule.device_role.all %}
                                        <ul class="list-unstyled">
                                            {% for d_role in rule.device_role.all %}
                                                <li><a href="{{ d_type.get_absolute_url }}">{{ d_role }}</a></li>
                                            {% endfor %}
                                        </ul>
                                    {% else %}
                                        <span class="text-muted">None</span>
                                    {% endif %} 
                                </td>
                                <td>
                                    {% if rule.device_type.all %}
                                        <ul class="list-unstyled">
                                            {% for d_type in rule.device_type.all %}
                                                <li><a href="{{ d_type.get_absolute_url }}">{{ d_type }}</a></li>
                                            {% endfor %}
                                        </ul>
                                    {% else %}
                                        <span class="text-muted">None</span>
                                    {% endif %}                                    
                                </td>                            
                                <td>
                                    {% if rule.template %}
                                        <a href="{{ rule.template.get_absolute_url }}">{{ rule.template }}</a>
                                    {% else %}
                                        <span class="text-muted">None</span>
                                    {% endif %}
                                </td>
                                <td>
                                    {{ rule.description }}<br />
                                </td>
                                <td class="text-right noprint">
                                    <a href="{% url 'plugins:config_officer:service_rule_edit' pk=rule.pk %}?return_url={{ service.get_absolute_url }}" class="btn btn-warning btn-xs" title="Edit rule">
                                        <i class="glyphicon glyphicon-pencil" aria-hidden="true"></i>
                                    </a>
                                    <a href="{% url 'plugins:config_officer:service_rule_delete' pk=rule.pk %}?return_url={{ service.get_absolute_url }}" class="btn btn-danger btn-xs" title="Delete rule">
                                        <i class="glyphicon glyphicon-trash" aria-hidden="true"></i>
                                    </a>
                                </td>
                            </tr>
                        {% endfor %}
                    </table>
                {% else %}
                    <div class="panel-body text-muted">None</div>
                {% endif %}
                <div class="panel-footer text-right noprint">
                    <a href="{% url 'plugins:config_officer:service_rule_add' %}?service={{ service.pk }}&return_url={{ service.get_absolute_url }}" class="btn btn-primary btn-xs">
                        <span class="glyphicon glyphicon-plus" aria-hidden="true"></span>
                        Add a rule
                    </a>
                </div>
            </div>    
        </div>
    </div>    
{% endblock %}

