{% extends "base.html" %}
{% load package_extras %}
{% block title %}Arch Linux - Package Database{% endblock %}
{% block navbarclass %}anb-packages{% endblock %}

{% block head %}
<link rel="stylesheet" type="text/css" href="/media/admin_media/css/widgets.css" />
{% endblock %}

{% block content %}
<div id="pkglist-search" class="box">

    <h2>Package Database</h2>

    <h3>Package Search</h3>

	<form id="pkg-search" method="get" action="/packages/">
		<p><input type="hidden" name="sort" value='{{sort}}' /></p>
		<fieldset>
			<legend>Enter search criteria</legend>
			<div><label title="Limit results a specific CPU architecture">
					Arch</label>{{ search_form.arch }}</div>
			<div><label title="Limit results to a specific respository">
					Repository</label>{{ search_form.repo }}</div>
			<div><label title="Enter keywords as desired">
					Keywords</label>{{ search_form.q }}</div>
			<div><label title="Limit results to a specific maintainer">
					Maintainer</label>{{ search_form.maintainer}}</div>
			<div><label title="Limit results to a date after the date entered">
					Last Update</label>{{ search_form.last_update }}</div>
			<div><label title="Limit results based on out-of-date status">
					Flagged</label>{{ search_form.flagged }}</div>
			<div><label title="Select the number of results to display per page">
					Per Page</label>{{ search_form.limit }}</div>
			<div ><label>&nbsp;</label><input title="Search for packages using this criteria"
				type="submit" value="Search" /></div>
		</fieldset>
	</form>

</div><!-- #pkglist-search -->

{% if package_list %}
<div id="pkglist-results" class="box">

    {% if paginator %}
    <div id="pkglist-stats-top">

        <p>{{paginator.count}} packages found.
        Page {{page_obj.number}} of {{paginator.num_pages}}.</p>

        <p class="pkglist-nav">
            {% if page_obj.has_previous %}
            <a class="prev" href="/packages/{{page_obj.previous_page_number}}/{{current_query}}"
                title="Go to previous page">&lt; Prev</a>
            {% else %}
            <span class="prev">&lt; Prev</span>
            {% endif %}
            {% if page_obj.has_next %}
            <a class="next" href="/packages/{{page_obj.next_page_number}}/{{current_query}}"
                title="Go to next page">Next &gt;</a>
            {% else %}
            <span class="next">Next &gt;</span>
            {% endif %}
        </p>

    </div>
    {% endif %}

    <form id="pkglist-results-form" method="post" action="/packages/update/">{% csrf_token %}

        <table class="results">
            <thead>
                <tr>
                    {% if user.is_authenticated %}
                    <th>&nbsp;</th>
                    {% endif %}
                    <th><a href="/packages/{% buildsortqs "arch" %}"
                            title="Sort packages by architecture">Arch</a></th>
                    <th><a href="/packages/{% buildsortqs "repo" %}"
                            title="Sort packages by repository">Repo</a></th>
                    <th><a href="/packages/{% buildsortqs "pkgname" %}"
                            title="Sort packages by package name">Name</a></th>
                    <th>Version</th>
                    <th>Description</th>
                    <th><a href="/packages/{% buildsortqs "-last_update" %}"
                            title="Sort packages by last update">Last Updated</a></th>
                </tr>
            </thead>
            <tbody>
            {% for pkg in package_list %}
                <tr class="{% cycle 'odd' 'even' %}">
                    {% if user.is_authenticated %}
                    <td><input type="checkbox" name="pkgid" value="{{ pkg.id }}" /></td>
                    {% endif %}
                    <td>{{ pkg.arch.name }}</td>
                    <td>{{ pkg.repo.name|capfirst }}</td>
                    <td><a href="{{ pkg.get_absolute_url }}"
                            title="View package details for {{ pkg.pkgname }}">{{ pkg.pkgname }}</a></td>
                    {% if pkg.needupdate %}
                    <td><span class="flagged">{{ pkg.pkgver }}-{{ pkg.pkgrel }}</span></td>
                    {% else %}
                    <td>{{ pkg.pkgver }}-{{ pkg.pkgrel }}</td>
                    {% endif %}
                    <td class="wrap">{{ pkg.pkgdesc }}</td>
                    <td>{{ pkg.last_update|date:"Y-m-d" }}</td>
                </tr>
            {% endfor %}
            </tbody>
        </table>

        {% if paginator %}
        <div id="pkglist-stats-bottom">

            <p>{{paginator.count}} packages found. Page {{page_obj.number}} of {{paginator.num_pages}}.</p>

                <p class="pkglist-nav">
                    {% if page_obj.has_previous %}
                    <a class="prev" href="/packages/{{page_obj.previous_page_number}}/{{current_query}}"
                        title="Go to previous page">&lt; Prev</a>
                    {% else %}
                    <span class="prev">&lt; Prev</span>
                    {% endif %}
                    {% if page_obj.has_next %}
                    <a class="next" href="/packages/{{page_obj.next_page_number}}/{{current_query}}"
                        title="Go to next page">Next &gt;</a>
                    {% else %}
                    <span class="next">Next &gt;</span>
                    {% endif %}
                </p>

        </div>
        {% endif %}

        {% if user.is_authenticated %}
        <p><input title="Adopt selected packages" type="submit" id="adopt-btn"
        name="adopt" value="Adopt Packages" />
        <input title="Orphan selected packages" type="submit" id="disown-btn"
        name="disown" value="Disown Packages" /></p>
        {% endif %}

    </form>

</div><!-- #pkglist-results -->
{% else %}
<div class="box">
	<p>We couldn't find any packages matching your query. Try searching again
	using different criteria, or try
	<a href="http://aur.archlinux.org/packages.php?K={{ search_form.q.data }}">searching the AUR</a>
	to see if the package can be found there.</p>
</div>
{% endif %}

<div id="pkglist-about" class="box">
    <p>You are browsing the Arch Linux package database. From here you can find
    detailed information about packages located in the official supported repositories.
    For unsupported packages, browse the <a href="http://aur.archlinux.org/"
        title="AUR package database">Arch User Repository (AUR).</a></p>
</div>

<script type="text/javascript" src="/jsi18n/"></script>
{% load adminmedia %}<script type="text/javascript" src="{% admin_media_prefix %}js/core.js"></script>
<script type="text/javascript">window.__admin_media_prefix__ = "{% filter escapejs %}{% admin_media_prefix %}{% endfilter %}";</script>
{{search_form.media}}
{% endblock %}