{% extends "base.html" %}
{% load fqdn_url from fqdn_url %}
{% block head %}
    {% if app.vendor == 10000 %}
        {% include "apps/details.dojo" %}
    {% endif %}
{% endblock %}
{% block title %}Details for {{ app.name }}{% endblock %}

{% block content-top %}
<div id="content_top" style="min-height:130px;">
    <div class="toplevel">
        <div style="float: left; width: 100%;">
<table style="margin-bottom: 10px;">
    <tr><th class="vertical">Name</th>
        <td>
        {% if app.vendor == 10000 %}
        <div style="width:100%;display:block">
            <div id="userId" style="display:none;visibility:hidden;">{{ user.id }}</div>
            <div id="appId" style="display:none;visibility:hidden;">{{ app.id }}</div>

            <div id="appName" data-dojo-type="dijit.InlineEditBox"
                 data-dojo-props="editor:'dijit.form.TextBox',trim:true,width:250"
                 onChange="updateAppName('{% fqdn_url 'ajax_update_app_name' %}', '{{ STATIC_URL }}i/s/')"
                 style="auto;float:left;display:inline">{{ app.name }}
            </div>
            <img id="nameStatus" src="{{ STATIC_URL }}i/transparent.png" alt="" style="width:16px;height:16px;float:right;display:inline-block;"/>
        </div>
        {% else %}
            {{ app.name }}
        {% endif %}
        </td>
    </tr>
    <tr><th class="vertical">URL</th>
        <td>
        {% if app.vendor == 10000 %}
        <div style="width:100%;display:block">
            <a href="{{ app.url|safe }}" id="appUrl" data-dojo-type="dijit.InlineEditBox"
                 data-dojo-props="editor:'dijit.form.TextBox',trim:true,width:250"
                 onChange="updateAppUrl('{% fqdn_url 'ajax_update_app_url' %}', '{{ STATIC_URL }}i/s/')"
                 style="float:left;display:inline">{{ app.url|safe }}
            </a>
            <img id="urlStatus" src="{{ STATIC_URL }}i/transparent.png" alt="" style="width:16px;height:16px;float:right;display:inline;"/>
        </div>
        {% else %}
            <a href="{{ app.url|safe }}">{{ app.url|safe }}
        {% endif %}
        </td>
    </tr>
    <tr><th class="vertical">UUID</th><td>{{ app.uuid }}</td></tr>
    <tr>
        <th class="vertical">Last Check-in</th>
        <td>
<a href="{% fqdn_url 'app_history' app.pk %}" title="Show history. Updated when package list changes">
{{ app.last_checkin|date:'Y-m-d H:i' }}
</a>

{% if app.vendor == 10000 %}
<a href="#" onclick='dijit.byId("dlgRegister").show()' style="float: right" class="button light_blue small" title="Update Package List">Update Package List</a>
{% endif %}
        </td>
    </tr>
    {% if app.status == 5 %}
    <tr>
        <th class="vertical red">SUSPENDED</th>
        <td>
            <em>Update Package List</em> to resolve this!
        </td>
    </tr>
    {% endif %}
</table>

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

{% endblock %}

{% block content %}
<table class="fullwidth">
    <tr>
        <th></th>
        <th>Installed Package</th>
        <th>Available Updates</th>
        <th></th>
    </tr>
{% for p in page_context.object_list %}
    <tr id="i{{ p.installed_id }}">
        <td class="dots center">
        {% if p.in_progress %}
            <img src="{{ STATIC_URL }}i/loading_horiz.gif"
                 title="Package analytics is in progress"
                 alt="Analytics in progress"
            />
        {% else %}
            {{ page_context.start_index|add:forloop.counter0 }}
        {% endif %}
        </td>
        <td class="dots">
        {% if p.previous %}
            <a href="{% fqdn_url 'previous_analytics' p.name p.package_pk %}" title="Click here to see previous analytics">{{ p.installed }}</a>
        {% else %}
            {{ p.installed }}
        {% endif %}
        </td>

        <td class="dots">
            {% for adv in p.advisories %}
            <a class="{{ adv.freshness }} button micro_plus" title="Released on {{ adv.date|date:'d N Y' }}" href="{{ adv.url }}">{{ adv.new }}</a>&nbsp;
            {% endfor %}
        </td>
        <td class="dots center">
        {% if app.vendor == 10000 %}
            <div class="button micro dark_blue following" title="delete" onclick="deleteInstalledPackage({{ p.installed_id }}, '{% fqdn_url 'ajax_delete_inst_pkg' %}')">x</div>
        {% endif %}
        </td>
    </tr>
{% endfor %}
    <tr>
        <td colspan="4" class="center" style="border: none;">
            {% if page_context.has_previous %}
                <a href="{% fqdn_url 'appdetails' app.id %}?page={{ page_context.previous_page_number }}{% if show_all %}&all=1{% endif %}">&lt;&lt;</a>
            {% endif %}

            &nbsp;{{ page_context.number }}/{{ page_context.paginator.num_pages }}&nbsp;

            {% if page_context.has_next %}
                <a href="{% fqdn_url 'appdetails' app.id %}?page={{ page_context.next_page_number }}{% if show_all %}&all=1{% endif %}">&gt;&gt;</a>
            {% endif %}
        </td>
    </tr>
</table>

{% endblock %}
