{% load url from future %}
{% load icons %}
{% load query %}
{% load formats %}
<form 
    method="POST" 
    class="form form-inline" 
    action="../bulkedit/?{{ url_query.urlencode }}"
>
<table class="table table-striped table-bordered table-condensed table-list device-list">
    <thead><tr>
        {% spaceless %}
        {% if show_bulk %}
        <th width="16"><div class="dropdown">
            <a href="#" data-toggle="dropdown" class="dropdown-toggle">{% icon 'fugue-ui-check-boxes-series' %}</a>
            <ul class="dropdown-menu">
                <li><a href="#" class="select-all">{% icon 'fugue-ui-check-box' %}&nbsp;Select all on this page</a></li>
            {% if False and items.has_other_pages %}
                <li><a href="#" class="select-pages">{% icon 'fugue-ui-check-boxes' %}&nbsp;Select all on all pages</a></li>
            {% endif %}
                <li><a href="#" class="select-toggle">{% icon 'fugue-ui-check-box-mix' %}&nbsp;Reverse selection</a></li>
                <li><a href="#" class="select-none">{% icon 'fugue-ui-check-box-uncheck' %}&nbsp;Deselect all</a></li>
            </ul>
        </div></th>
        {% endif %}
        {% include 'ui/column-header.html' with label='Name' name='name' always=1 %}
        {% include 'ui/column-header.html' with label='Venture/Role' name='venture' %}
        {% include 'ui/column-header.html' with label='Model' name='model' %}
        {% include 'ui/column-header.html' with label='Margin' name='margin' type='quantity' %}
        {% include 'ui/column-header.html' with label='Deprecation' name='deprecation' type='quantity' %}
        {% include 'ui/column-header.html' with label='Price' name='price' type='price' %}
        {% include 'ui/column-header.html' with label='Monthly Cost' name='cost' type='price' %}
        {% include 'ui/column-header.html' with label='Barcode' name='barcode' %}
        {% include 'ui/column-header.html' with label='Position' name='position' type='number' %}
        {% include 'ui/column-header.html' with label='IP Addresses' name='ips' %}
        {% include 'ui/column-header.html' with label='Management' name='management' %}
        {% include 'ui/column-header.html' with label='Created' name='created' type='date' %}
        {% include 'ui/column-header.html' with label='Last Seen' name='lastseen' type='date' %}
        {% include 'ui/column-header.html' with label='Reports' name='reports' %}
        {% include 'ui/column-header.html' with label='Remarks' name='remarks' %}
        {% include 'ui/column-header.html' with label='Purchase Date' name='purchase' type='date' %}
        {% include 'ui/column-header.html' with label='Warranty Expiration' name='warranty' type='date' %}
        {% include 'ui/column-header.html' with label='Support Expiration' name='support' type='date' %}
        {% endspaceless %}
    </tr></thead>
    <tbody>
        {% for d in items.object_list %}
        <tr
            {% if d == device %}
                class="active"
            {% endif %}
            >
            {% if show_bulk %}
            <td class="column-checkbox"><input type="checkbox" name="select" value="{{ d.id }}"></td>
            {% endif %}
            <td class="column-name"><a
                    href="{{ d.id|default:'' }}?{{ url_query.urlencode }}"
                >{%  for i in d.padding %}&nbsp;&nbsp;&nbsp;&nbsp;{%  endfor %}{{ d|device_icon }}&nbsp;{{ d.get_name|default:'unknown' }}
            </a>
            </td>
            {% if 'venture' in columns %}
            <td>
                {% if d.venture %}
                    <a href="{% url 'ventures' d.venture.symbol details '' %}"
                        >{{ d.venture.name }}</a>{% endif %}{% if d.venture_role %}/{{ d.venture_role.full_name }}{% endif %}
            </td>
            {% endif %}
            {% if 'model' in columns %}
            <td>
                {% if d.model.group %}
                <a 
                    href="{% url 'search' 'components' '' %}?device_group={{ d.model.group.id }}"
                >{{ d.get_model_name }}</a>
                {% else %}
                    {{ d.get_model_name }}
                {% endif %} 
            </td>
            {% endif %}
            {% if 'margin' in columns %}
            <td>{{ d.get_margin|default:'0' }}%</td>
            {% endif %}
            {% if 'deprecation' in columns %}
            <td>{{ d.deprecation_kind|default:'' }}</td>
            {% endif %}
            {% if 'price' in columns %}
            <td class="currency">{{ d.cached_price|currency }}</td>
            {% endif %}
            {% if 'cost' in columns %}
            <td class="currency">{{ d.cached_cost|currency }}</td>
            {% endif %}
            {% if 'barcode' in columns %}
            <td>{{ d.barcode|default:'' }}</td>
            {% endif %}
            {% if 'position' in columns %}
            <td>
                {% if d.dc %}<a href="{% url 'racks' d.dc|slugify details '' %}">{{ d.dc }}</a>/{% endif %}{% if d.rack %}<a href="{% url 'racks' d.rack|slugify details '' %}">{{ d.rack }}</a>/{% endif %}<b>{{ d.position|default:d.chassis_position|default:'-' }}</b>
            </td>
            {% endif %}
            {% if 'ips' in columns %}
            <td class="column-ips">
                {% for ip in d.ipaddress_set.all %}
                {% if ip in network %}
                    <b>{{ ip.address }}</b>
                {% else %}
                    {{ ip.address }}
                {% endif %}
                {% endfor %}
            </td>
            {% endif %}
            {% if 'management' in columns %}
            {%  if d.management %}
            <td><a href="https://{{ d.management.address }}">{{ d.management.hostname|default:d.management.address }}</a></td>
            {%  else %}
            <td></td>
            {%  endif %}
            {% endif %}
            {% if 'created' in columns %}
            <td>{{ d.created|date:'Y-m-d H:i' }}</td>
            {% endif %}
            {% if 'lastseen' in columns %}
            <td>{{ d.last_seen|date:'Y-m-d H:i' }}</td>
            {% endif %}
            {% if 'reports' in columns %}
            <td>{%icon 'fugue-fingerprint'%}</td>
            {% endif %}
            {% if 'remarks' in columns %}
            <td class="column-remarks">{{ d.remarks }}</td>
            {% endif %}
            {% if 'purchase' in columns %}
            <td>{{ d.purchase_date|date:'Y-m-d H:i'|default:'' }}</td>
            {% endif %}
            {% if 'warranty' in columns %}
            <td>{{ d.warranty_expiration_date|date:'Y-m-d H:i'|default:'' }}</td>
            {% endif %}
            {% if 'support' in columns %}
            <td>{{ d.support_expiration_date|date:'Y-m-d H:i'|default:'' }}</td>
            {% endif %}
        </tr>
        {% endfor %}
    </tbody>
</table>
{% include 'ui/pagination.html' with page=items pages=pages %}
{% if show_bulk %}
<div class="form-actions bulk-edit">
    {% csrf_token %}
    <div class="controls">
        {% if False and items.has_other_pages %}
        <label class="checkbox">
            <input type="checkbox" name="selectall">
            Include items from all pages
        </label>
        {% endif %}
        <button type="submit" class="btn pull-right" name="bulk">
            {% icon 'fugue-pencil-field' %} Bulk edit
        </button>
    </div>
</div>
{% endif %}
</form>

