{% extends "formunculous/base.html" %}
{% load i18n %}
{% block css %}{{ block.super }}
<link href="{{ MEDIA_URL }}formunculous/css/formunculous.css" rel="stylesheet" type="text/css" />
<link href="{{ MEDIA_URL }}formunculous/css/smoothness/jquery-ui-1.7.2.custom.css" rel="stylesheet" type="text/css">
{% endblock %}

{% block js %}{{ block.super }}
<script type="text/javascript" src="{{ MEDIA_URL }}formunculous/js/jquery-1.3.2.min.js"></script>
<script type="text/javascript" src="{{ MEDIA_URL }}formunculous/js/jquery-ui-1.7.2.custom.min.js"></script>
<script type="text/javascript">
var delete_url = "{% url reviewer-delete ad.slug %}";
var app_id = 0

jQuery(document).ready(function($)
{
$('#del_dialog').dialog({
       autoOpen: false,
       modal: true,
       width: 400,
       buttons: {
             "OK": function() {
                 $.ajax( { url: delete_url,
                           type: "POST",
                           datatype: "html",
                           data: { id: app_id },
                           success: function() {
                                   $('#del_dialog').dialog('close');
                                   $('#ajax_results').html("<p>Form Successfully Deleted</p>");
                                   $('#ajax_results').effect('highlight',{},1500);
                                   $('#app_' + app_id).parent('tr').fadeOut(1000, function() {$(this).remove();});
                           },
                           error: function() {
                                   $('#del_dialog').dialog('close');
                                   $('#ajax_results').html("<p>Unable to delete the form</p>");
                                   $('#ajax_results').effect('highlight',{},1500);
                                   }
                        });

              },
             "Cancel": function() {
                 $(this).dialog("close");
             }
       },
       show: 'drop',
       bgiframe: true
});

});
function deleteApp(id) {
	app_id = id;
	jQuery('#del_dialog').dialog('open');
}

</script>
{% endblock %}

{% block title %}
{{ ad.name }} {% trans "Submissions" %}
{% endblock %}

{% block content_title %}
{{ ad.name }} {% trans "Submissions" %}
{% endblock %}

{% block content %}
<div id="del_dialog" title="{% trans "Confirm Form Deletion" %}">
  <p>
	Deleting the selected form cannot be undone.  Are you sure
	you want to delete this form?
  </p>
</div>
<div id="ajax_results">
</div>

{% if partials %}
<div class="formunculous_tab_bar">
  <ul>
	<li class="here">
	  <a href="{% url reviewer-index ad.slug %}" class="formunculous_completelink">{% trans "Completed" %}</a>
	</li>
	<li>
	  <a href="{% url reviewer-index-incomplete ad.slug %}" class="formunculous_incompletelink">{% trans "In Progress" %}</a>
	</li>
  </ul>
</div>
{% endif %}

{% if status %}
<div class="formunculous_messages">
  {{ status }}
</div>
{% endif %}

<div class="fr" id="formunculous-review-search">
  <form method="get" action="">{% csrf_token %}
	<input type="text" name="q" id="q" value="{{ query }}"/>
	<input type="hidden" name="s" id="s" value="{{ sort }}" />
	<input type="hidden" name="page" id="page" value="{{ page.number }}" />
	<input type="submit" name="submit" value="&nbsp;" />
  </form>
</div>
<div class="fr" style="margin: 5px 2em 0 0;">
  <a href="{% url reviewer-export ad.slug %}" class="formunculous_csvlink">
	{% trans "Spreadsheet" %}
  </a>
  <a href="{% url reviewer-export-zip ad.slug %}" class="formunculous_downloadlink">
	{% trans "Download Files" %}
  </a>
  <a href="{% url reviewer-statistics ad.slug %}" class="formunculous_statslink">
	{% trans "Statistics" %}
  </a>

</div>
<div style="clear:both"></div>
<table class="formunculous_table formunculous_review_table">
<thead>
<tr>
  {% for header in headers %}
  <th class="{% if header.sorted %}sort {% endif %}{% if header.rev_sorted %}sort-reverse{% endif %}">
	<a href="{{ header.url }}&q={{ query }}&page={{ page.number }}">{{ header.name }}</a>
  </th>
  {% if forloop.last %}
    <th>
	  {% trans "Actions" %}
	</th>
  {% endif %}
  {% endfor %}
</tr>
</thead>
<tbody>
  {% for row in data %}
  <tr class="{% cycle 'odd' 'even' %}">
	{% for col in row %}

	{% if not forloop.last %}
	<td>
	  {% if col.url %}
	  <a href="{{ col.url }}">
	  {% endif %}
	  
	  {% ifequal col.type "BooleanField" %}
			  <span class="
				{{ col.value|yesno:"formunculous_yes\">Yes, formunculous_no\">No"|safe }}
			  </span>        
	  {% else %}
	    {{ col.value }}
	  {% endifequal %}

	  {% if col.url %}
	  </a>
	  {% endif %}
	</td>
	{% else %}
	<td><a href="{{ col.url }}">{{ col.value|date:"D d M Y" }} {{ col.value|time:"g:i A" }}</a></td>
	<td id="app_{{ col.id }}">
	  {% if perms.formunculous.can_delete_applications %}
	  <a href="#" class="formunculous_deletelink" style="padding-left: 20px;" onclick="deleteApp({{ col.id }});">{% trans "Delete" %}</a></td>
	  {% endif %}
	{% endif %}

	{% endfor %}
  </tr>
  {% endfor %}
</tbody>
</table>

{% if page.has_other_pages %}
<div class="formunculous_pagination">
  <ul>
	<li>
	  {% if page.has_previous %}
	  <a href="?page=1&s={{ sort }}&q={{ query }}" class="direction">
		{% endif %}
		&#171;{% trans "first" %}
		{% if page.has_previous %}</a>{% endif %}
	</li>

	{% for num in page.page_range %}
	<li{% ifequal page.number num%} class="current"{% endifequal %}>
	  {% if not num %} <span class="break">...</span>
	  {% else %} 
	  {% ifequal page.number num %}
	  {{ num }}
	  {% else %}
	  <a href="?page={{ num }}&s={{ sort }}&q={{ query }}">{{ num }}</a> 
	  {% endifequal %}
	  {% endif %}
	</li>
	{% endfor %}
	<li>
	  {% if page.has_next %}
	  <a href="?page={{ page.paginator.num_pages }}&s={{ sort }}&q={{ query }}" class="last" class="direction">
		{% endif %}
		{% trans "last" %}&#187;
		{% if page.has_next %}</a>{% endif %}
	</li>
  </ul>
</div>
{% endif %}

{% endblock %}
