{% extends "entities/base.html" %}
{% load pagination_tags %}
{% load entity_tags %}
{% load base_tags %}
{% load base_filters %}
{% load perm_tags %}
{% load i18n %}

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

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

{% block body %}
<div class="t">

    {% entity_nav request.user %}

    <h1>{{ MODULE_ENTITIES_LABEL }} {% trans "Search" %}</h1>
	{% entity_search %}
    {% autopaginate entities 10 %}
	<div class="entities-wrap">
    {% for entity in entities %}

    	{% has_perm user entities.view_entity entity as can_view %}
    	{% if can_view %}

		<div class="entity-wrap-search">
			<div class="options">

                <div class="dropdown-options">
                    <div><a href="javascript:;">{% trans "More " %}<span>&#9660;</span></a></div>
                    <ul>
                        <li>{% trans "Review Reports" %}</li>
                        <li>{% trans "Optimize Meta Tags" %}</li>
                        <li>{% trans "Attach Files" %}</li>
                        <li>{% trans "View Revisions" %}</li>
                        <li>{% trans "Delete" %}</li>
                    </ul>
                </div>

                <div class="quick-options">
					{% entity_options request.user entity %} 	       
                </div>
			</div>


            <h2><a href="{% url entity entity.pk %}">{{ entity.entity_name|striptags|truncatewords:20|safe }}</a></h2>
			<div class="meta">
            	<div class="submitted">{% blocktrans with entity.create_dt|date:"long" as submit_date and entity.creator as entity_creator %} Submitted on {{ submit_date }} by {{ entity_creator }}{% endblocktrans %}</div>
            </div>

            <!-- delete-entity form -->
            <form name="entity-delete" method="POST" action="{% url entity.delete entity.pk %}">{% csrf_token %}
                <input type="hidden" name="action" value="delete">
            </form>

		</div>
		{% endif %}

	{% empty %}
		<div>{% trans "0 Results Found" %}</div>	
    {% endfor %}
	</div>

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

{% block extra_body %}
    {{ block.super }}
    <script type="text/javascript">
		$(document).ready(function(){

			// delete confirmation
			$('.delete').click(function(){
				var delete_entity = confirm('Permenantly delete {{ MODULE_ENTITIES_LABEL }} ?');	// confirm
				if(delete_entity) $(this).parents('.entity-wrap').find('form[name="entity-delete"]').submit() // delete: if OK
				return false;	// cancel
			});
		});
    </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 %}
