{% extends "template/template.html" %}
{% block title%}IP: {{prefix.prefix}}{% endblock %}
{% block breadcrumbs %}<div class="breadcrumbs"><A HREF="/">Home</A> &rsaquo; <A HREF="/ip/">ip</A> &rsaquo; 
    <a href='/ip/{{vrf.id}}/'>VRF: {{vrf.name}}</A> &rsaquo;
        {% for p in parents %}
            <a href="/ip/{{vrf.id}}/{{p.prefix}}/" title="{{p.description}}">{{p.prefix}}</a> &rsaquo;
        {% endfor %}
        <a href='/ip/{{vrf.id}}/{{prefix.prefix}}/' title="{{prefix.description}}">{{prefix.prefix}}</a> &rsaquo;
</div>
{% endblock %}
{% block content %}
{% if can_allocate %}
    <ul class="object-tools">
        {% if prefix.has_children %}{%else%}
        <li><A HREF="#" ONCLICK="toggle_free();" CLASS="changelink" id="free_ip_toggle_button">Show Free</A></li>
        {% endif %}
        <li><A HREF="/ip/{{vrf.id}}/{{prefix}}/tools/" CLASS="changelink">Tools</A></li>
        <li><A HREF="/ip/{{vrf.id}}/allocate_block/" CLASS="addlink">Allocate new block</A></li>
        <li><A HREF="/ip/{{vrf.id}}/assign_address/" CLASS="addlink">Assign address</A></li>
    </ul>
{% endif %}
<SCRIPT TYPE="text/javascript">
    <!--
    function confirm_delete(msg)
    {
        var agree=confirm(msg);
        if (agree)
            return true;
        else
            return false;
    }
    // -->
</SCRIPT>
<DIV CLASS="module">
    <TABLE SUMMARY="Allocated blocks within {{prefix.prefix}}" WIDTH="100%">
        <caption>Allocated blocks within {{vrf.name}}::{{prefix.prefix}} ({{prefix.description}})</caption>
        <THEAD>
            <TR><TH>Prefix</TH><TH>VRF</TH><TH>Description</TH><TH>VC</TH><TH>TT</TH><TH></TH></TR>
        </THEAD>
        {%for p in prefixes %}
        <TR class="{%cycle 'row1' 'row2'%}">
            <TD><A HREF="/ip/{{p.vrf.id}}/{{p.prefix}}/">{{p.prefix}}</A></TD>
            <TD><A HREF="/ip/{{p.vrf.id}}/">{{p.vrf.name}}</A></TD>
            <TD>{{p.description}}</TD>
            <TD>{% if p.vc %}{{p.vc}}{% endif %}</TD>
            <TD>{%if p.tt %}<A HREF="{{p.tt_url}}">#{{p.tt}}</A>{%endif%}</TD>
            <TD> 
                <A HREF="/ip/{{p.vrf.id}}/{{p.prefix}}/allocate_block/" CLASS="changelink">Change</A>
                <A HREF="/ip/{{p.vrf.id}}/{{p.prefix}}/deallocate_block/"
                    CLASS="deletelink" ONCLICK="return confirm_delete('Deallocate block?')">Delete</A>
            </TD>
        </TR>
        {%endfor%}
    </TABLE>
</DIV>

{% if has_children %}
{% else %}
<STYLE>
.freeip {
    font-style: italic;
    background-color: #CCCCCC;
    display: none;
}
</STYLE>

<SCRIPT TYPE="text/javascript">
var _ft_shown=false;

function toggle_free() {
    if(_ft_shown) {
        $(".freeip").each(function (i){this.style.display="none";});
        $("#free_ip_toggle_button").text("Show Free");
        _ft_shown=false;
    } else {
        $(".freeip").each(function (i){this.style.display="table-row";});
        $("#free_ip_toggle_button").text("Hide Free");
        _ft_shown=true;
    }
}
</SCRIPT>
<DIV CLASS="module">
    <TABLE SUMMARY="Allocated addresses within {{prefix.prefix}}" WIDTH="100%">
        <THEAD>
            <TR><TH STYLE="width: 10px"></TH><TH>IP</TH><TH>FQDN</TH><TH>Description</TH><TH>TT</TH></TR>
        </THEAD>
        {% for c,a in all_addresses %}
            {% if a.ip %}
                <TR class="{%cycle 'row1' 'row2'%}">
                <TD {%if c%}STYLE="background-color: {{c}}"{%endif%}></TD>
                <TD>{% if can_allocate %}<A HREF="/ip/{{vrf.id}}/{{a.ip}}/assign_address/">{{a.ip}}</A>{%else%}{{a.ip}}{%endif%}</TD>
                <TD>{{a.fqdn}}</TD>
                <TD>{{a.description}}</TD>
                <TD>{%if a.tt %}<A HREF="{{a.tt_url}}">#{{a.tt}}</A>{%endif%}</TD>
                </TR>
            {% else %}
                <TR CLASS="freeip">
                <TD {%if c%}STYLE="background-color: {{c}}"{%endif%}></TD>
                <TD COLSPAN=2>{% if can_allocate %}<A HREF="/ip/{{vrf.id}}/{{a}}/assign_address/new/">{{a}}</A>{%else%}{{a}}{% endif %}</TD>
                <TD>Free</TD>
                <TD></TD>
                </TR>
            {% endif %}
        {% endfor %}
    </TABLE>
</DIV>
{% if ranges %}
    <DIV CLASS="module">
        <TABLE SUMMARY="Address Ranges" WIDTH="100%">
            <CAPTION>Address Ranges</CAPTION>
            <THEAD>
                <TR><TH></TH><TH>Name</TH><TH>From IP</TH><TH>To IP</TH><TH>Locked</TH><TH>Description</TH></TR>
            </THEAD>
            {% for r in ranges %}
            <TR class="{%cycle 'row1' 'row2'%}">
                <TD STYLE="width: 10px; background-color: {{r.color}}"></TD>
                <TD>{{r.name}}</TD>
                <TD>{{r.from_ip}}</TD>
                <TD>{{r.to_ip}}</TD>
                <TD><img src="/media/img/admin/icon-{%if r.is_locked%}yes{%else%}no{%endif%}.gif"></TD>
                <TD>{{r.description}}</TD>
            </TR>
            {% endfor %}
        </TABLE>
    </DIV>
{% endif %}
{% endif %}

<DIV CLASS="module">
    <TABLE SUMMARY="Block info" WIDTH="100%">
        <CAPTION>{{prefix.prefix}} info</CAPTION>
        <TR class="row1">
            <TD><b>VC</b></TD>
            <TD>
                {% if prefix.vc %}{{prefix.vc}}{% endif %}
                {% if can_allocate %}
                <a href="/ip/{{vrf.id}}/{{prefix}}/vc/bind/"><b>{%if prefix.vc%}Change{%else%}Bind{%endif%}...</b></a>
                {% endif %}
            </TD>
        </TR>
        <TR class="row2">
            <TD><b>Maintainers</b></TD>
            <TD>{{prefix.maintainers|join:", "}} {%if can_allocate%}<a href="/admin/ip/ipv4blockaccess/add/?vrf={{vrf.id}}&prefix={{prefix}}"><b>Add...<b></a>{%endif%}</TD>
        </TR>
        {% for k,v in block_info %}
            <TR class="{%cycle 'row1' 'row2'%}"><TD STYLE="width: 10pt"><b>{{k}}</b></TD><TD>{{v}}</TD></TR>
        {% endfor %}
    </TABLE>
</DIV>
{% endblock %}
