{% load bob %}
{% load icons %}
<div>
    <div class='alert alert-info'>{{ label }}</div>
    <table class='table table-striped table-bordered table-condensed'>
        {% if relations %}
            <tr>
                <th>CI UID</th>
                <th>CI Name</th>
                <th>CI Type</th>
                <th>Editable</th>

                {% if editable %}
                    <th>Operations</th>
                {% endif %}
            </tr>
            {% else %}
                No relations.
            {% endif %}
        {% for rel in relations %}
        <tr>
            <td> 
                {% if editable and not rel.0.readonly %}
                    <a target="{{target}}" href="/cmdb/ci/edit/{{rel.1.id}}">{{ rel.1.uid}}</a>
                {% else %}
                    <a target="{{target}}" href="/cmdb/ci/view/{{rel.1.id}}">{{ rel.1.uid}}</a>
                {% endif %}
            </td>
            <td>
                <i class='fugue-icon {{ rel.2 }}'></i>
                {% if editable and not rel.0.readonly %}
                    <a target="{{target}}" href="/cmdb/ci/edit/{{rel.1.id}}">{{ rel.1.name}}</a>
                {% else %}
                    <a target="{{target}}" href="/cmdb/ci/view/{{rel.1.id}}">{{ rel.1.name}}</a>
                {% endif %}
            </td>
            <td> 
                {{ rel.1.type }}
            </td>
            <td>
                {% if rel.0.readonly %}
                    {% icon 'fugue-ui-check-box-uncheck'  %}
                {% else %}
                    {% icon 'fugue-ui-check-box' %}
                {% endif %}
            </td>

            {% if editable %}
            <td>
                {% if rel.0.readonly %}
                -
                {% else %}
                    <a target="{{target}}" href="/cmdb/relation/edit/{{rel.0.id}}">Edit</a>
                    <a 
                        onclick="if (confirm('Remove relation?')){
                            $.post('/cmdb/relation/delete/{{rel.0.id}}/{{ci.id}}', function(ready){
                                window.location.href = '/cmdb/ci/edit/{{ci.id}}';
                            }).error(function(x){ alert('Error removing relation.')} )}"
                        href="#">Remove</a>
                {% endif %}
            </td>
            {% endif %}
        </tr>
        {% endfor %}
    </table>
</div>
