{% extends "formunculous/base.html" %}
{% load i18n widget_type %}
{% block css %}{{ block.super }}
{{ review_form.media }}
<link href="{{ MEDIA_URL }}formunculous/css/formunculous.css" rel="stylesheet" type="text/css" />
<link href="{{ MEDIA_URL }}formunculous/css/apply.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 = {{ app.id }}
jQuery(document).ready(function($)
{
$('#del_dialog').dialog({
       autoOpen: false,
       modal: true,
       width: 400,
       buttons: {
             "OK": function() {
                 $.ajax( { url: delete_url,
                           type: "POST",
                           data: {id: app_id},
                           datatype: "html",
                           success: function() {
                                     window.location = '{% url reviewer-index ad.slug %}';
                           },
                           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
});
jQuery('.formunculous_deletelink').click(function() { jQuery('#del_dialog').dialog('open');}); 
});
	
</script>
{% endblock %}
{% block title %}
{% trans "Reviewing" %} {{ ad.name }} {% trans " Submitted on " %}
{{ app.submission_date|date:"D d M Y" }} {{ app.submission_date|time:"g:i A" }} 
{% 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>

<h1>{% trans "Responses" %}</h1>
<div class="formunculous_container">
  <div class="fr" style="margin-right: 2em;">
	<a href="javascript:window.print()" class="formunculous_printlink">{% trans "Print" %}</a>
  </div>

<div class="formunculous_confirmation_info">
  <ul class="formunculous_form_info">
	{% if app.user %}
	<li>
	  <span class="formunculous_field_label">{% trans "Username" %}:</span>
	  <span class="formunculous_field_data">{{ app.user }}</span>
	</li>
		
	{% endif %}
	{% for field in app_fields %}
	   <li>
	      <span class="formunculous_field_label">{{ field.label }}:</span>
		  <span class="formunculous_field_data">
			{% ifequal field.type "BooleanField" %}
			  <span class="
				{{ field.data|yesno:"formunculous_yes\">Yes, formunculous_no\">No"|safe }}
			  </span>
			{% else %}

			  {% if field.data %}

			    {% if field.data.url %}
			      <a target="_blank" href="{{ field.data.url }}">
			    {% endif %}

			   {{ field.data }}

			   {% if field.data.url %}
			     </a>
			   {% endif %}
			 {% endif %}
		    {% endifequal %}
		  </span>
	   </li>
    {% endfor %}
	   <li>
	      <span class="formunculous_field_label">{% trans "Submission Date" %}:</span>
		  <span class="formunculous_field_data">
			{{ app.submission_date|date:"D d M Y" }}
			{{ app.submission_date|time:"g:i A" }}
		  </span>
	   </li>	 
  </ul>
  {% if sub_apps %}
  {% for sub_app_group in sub_apps %}
    <h3 class="formunculous_sub_ad_title">{{ sub_app_group.sub_ad.name }}</h3>
	{% for sub_app in sub_app_group.sub_apps %}
	  <ul class="formunculous_form_info formunculous_sub_form_info">
		{% for field in sub_app.fields %}
		  <li>
			<span class="formunculous_field_label">{{ field.label }}:</span>
			<span class="formunculous_field_data">
			  {% if field.data.url %}
			  <a target="_blank" href="{{ field.data.url }}">
				{% endif %}
				{{ field.data }}
				{% if field.data.url %}
			  </a>
			  {% endif %}
			</span>
		  </li>
		{% endfor %}
	  </ul>
	{% endfor %}
  {% endfor %}
  {% endif %}

<div class="fr" style="margin-right:2em">
  {% if perms.formunculous.can_delete_applications %}
  <span class="formunculous_deletelink" style="cursor:pointer">{% trans "Delete Form" %}</span>
  {% endif %}
</div>

</div>
<div style="clear:both;"></div>

{% if fields %}
<hr>
<h1>{% trans "Reviewer Fields" %}</h1>
{% if message %}
  <div class="apply_messages">{{ message }}</div>
{% endif %}

  <form method="post" action="{% url reviewer-application ad.slug app.id %}"{% if review_form.is_multipart %} enctype="multipart/form-data"{% endif %}>{% csrf_token %}
	{% if review_form.errors %}
	<div class="apply_field_errors">{% trans "There are errors in your form, please correct them" %}</div>
	{% endif %}
	<fieldset class="apply_fieldset">
	{% for field in fields %}
  	  {% if field.field.is_hidden %}
	    {{ field.field }}
	  {% else %}
	  
	    {% ifchanged field.group %}
	      {% if field.group %}
	        <div class="apply_form_group">
	      {% else %}
	        {% if not forloop.first %}
	          </div>
		    {% endif %}
	      {% endif %}
		{% endifchanged %}
	    <div class="apply_field_row {% cycle 'odd' 'even' %} ">
	      <div class="apply_field_errors">{{ field.field.errors }}</div>
	      <div class="apply_field{% if field.required %} apply_required{% endif %}">
			{% widget_type field.field.field.widget as widget %}
			{%  ifequal widget "CheckboxInput" %}
			  {{ field.field }}
			  {% if field.field.label %}
			    <label for="{{ field.field.auto_id}}" class="apply_cb_label">
				  {{field.field.label}}
				</label>
			  {% endif %}
			{% else %}
  			  {% if field.field.label %}
 			    {{ field.field.label_tag }}
			  {% endif %}
			  {{ field.field }}
			{% endifequal %}
	      </div>
		  <div style="clear:both;"></div>
		  {% if field.field.help_text %}
		  <div class="apply-info-box">
			{{ field.field.help_text }}
		  </div>
		  {% endif %}
		  </div>
	      {% if forloop.last and field.group %}
            </div>
          {% endif %}
	      {{ field.post_text }}
	  {% endif %}
	{% endfor %}
    </fieldset>

    <div class="apply_submit">
	  <input type="submit" name="save" value="Save" />
	</div>
  </form>
{% endif %}
  <hr>
  <h1>{% trans "Comments" %}</h1>
  {% load comments %}

  {% get_comment_count for app as comment_count %}

  {% get_comment_list for app as comments %}
  <div class="formunculous_comment_container">
  <strong>{{ comment_count }} Comments</strong>
  {% for comment in comments %}
    <div class="formunculous_comment_box">
	  <div class="formunculous_comment_header">
		{{ comment.user_name }} : {{ comment.submit_date|date:"D d M Y" }} {{ comment.submit_date|time:"g:i A" }}
	  </div>
	  <div class="formunculous_comment_comment">
		{{ comment.comment }}
	  </div>
	</div>
  {% endfor %}
  </div>
  
  {% get_comment_form for app as form %}
	<form action="{% comment_form_target %}" method="POST">{% csrf_token %}
	  <p>
		<label for="id_comment" style="font-weight: bold;">{{ form.comment.label}}</label><br /> {{ form.comment }}
	  <p style="display:none;">
		<label for="id_honeypot">{{ form.honeypot.label }}</label>: {{ form.honeypot }}
	  </p>
	  {{ form.content_type }}
	  {{ form.object_pk }} {{ form.timestamp }} {{ form.security_hash }}
	  <input type="hidden" name="next" value="{% url reviewer-application ad.slug app.id %}" />
	  <input type="submit" value="Add comment" id="id_submit" />
	</form>
</div>
{% endblock %}
