{% extends "files/base.html" %}
{% load pagination_tags %}
{% load file_tags %}
{% load base_tags %}
{% load perm_tags %}
{% load search_tags %}
{% load i18n %}

{% block title %}{{ block.super }}Search{% endblock %}

{% block extra_head %}
{{ block.super }}
<link rel="stylesheet" href="{{ STATIC_URL }}css/files.css">
{% endblock %}

{% block body %}
<div class="t">
    {% file_nav request.user %}

    <h1>{% firstof MODULE_FILES_LABEL_PLURAL 'Files' %}</h1>

    {% autopaginate files 10 %}
    {% file_search %}
    <div class="files-found">{{ paginator.count }} {% firstof MODULE_FILES_LABEL_PLURAL trans 'Files' %} {% trans "Found" %}</div>
    
    <div class="files-wrap">
    {% for file in files %}
        {% search_result file %}
    {% endfor %}
    </div>

    {% paginate %}
</div>
{% endblock %}

{% block extra_body %}
    {{ block.super }}
    <script type="text/javascript" src="{{ STATIC_URL }}js/jquery-1.4.2.min.js"></script>
    <script type="text/javascript">
        $(document).ready(function(){

            // url exists
            url_exists = function(url){
                var http = new XMLHttpRequest();
                http.open('HEAD', url, false);
                http.send();
                return http.status!=404;
            }

            // delete confirmation
            $('.delete').click(function(){
                var delete_file = confirm('Permenantly delete file?');  // confirm
                if(delete_file) $(this).parents('.file-wrap').find('form[name="file-delete"]').submit() // delete: if OK
                return false;   // cancel
            });

            // loop through files
            $('.t .file-wrap h2 a').each(function(){
                if(!url_exists(this.href)){
                    $(this).addClass('broken');
                }
            });

        });
    </script>
    <script type="text/javascript" src="{{ STATIC_URL }}js/global/dropdown.js"></script>
    <script type="text/javascript">
        var iconrow = new dropdown({
            container:  'more-options-wrap',
            trigger:    'more-options-trigger',
            target:     'more-options-target'
        });
    </script>     
{% endblock %}