{% extends "corporate_memberships/base.html" %}
{% load base_tags %}
{% load base_filters %}
{% load perm_tags %}
{% load corporate_memberships_tags %}
{% load i18n %}

{% block title %}{{ corporate_membership.name|safe }}{% endblock %}
{% block meta_description %}{{ corporate_membership.name|safe }}{% endblock %}
{% block meta_keywords %}{{ corporate_membership.name|safe}}{% endblock %}

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

{% block body %}
 {% has_perm request.user corporate_memberships.change_corpapp corporate_membership.corp_app as can_change_app %}
 {% has_perm request.user corporate_memberships.change_corporatemembership corporate_membership as can_change %}
 
<div class="t">
    {% corpmemb_nav request.user corporate_membership %} 

    <div class="corpmemb-view">

        <h1>{% trans "View Corporate Membership Information" %}</h1>

		<div class="options" align="right">
             <div class="quick-options">
				{% corpmemb_options request.user corporate_membership %}        
             </div>
		</div>
		
		<!-- delete-corp_memb form -->
	    <form name="corp-memb-delete" method="POST" action="{% url corp_memb.delete corporate_membership.pk %}">{% csrf_token %}
	        <input type="hidden" name="action" value="delete">
	    </form>

		<div class="content">
			
			<div style="float: right;">
				{% if corporate_membership.real_time_status_detail == 'active' %}
				<a href="{% url membership.application_details_corp_pre corporate_membership.corp_app.memb_app.slug corporate_membership.pk %}" title="Join under this corporation">{% trans "Join under this corporation" %}</a>
				{% endif %}
				
	    		
			</div>
				
  		
    		<div class="corp-app-name">
			 {% if can_change_app %}
			 	{% trans "App: " %}<a href="{% url admin:corporate_memberships_corpmembershipapp_change corporate_membership.corp_app.id %}">{{ corporate_membership.corp_app.name }}</a>
			 {% else %}
			 	{% trans "App: " %}{{ corporate_membership.corp_app.name }}
			 {% endif %}
			 </div>
			   
			 
			 <div style="clear:right;"></div>
			 {% for field_obj in field_objs %}
			 	{% if field_obj.field_type == 'section_break' or field_obj.field_type == 'page_break' %}
			 		<div class="section-break{% if field_obj.admin_only %} admin-only{% endif %}">
			 			<h2>{{ field_obj.label }}</h2>
			 		</div>
			 		
			 	{% else %}
			 		<div>
			 			{% if field_obj.field_name == 'reps' %}
			 				{% if field_obj.value %}
				 				<table width="70%">
						     	<tr>
						     		<td class="header" width="55%">{% trans "Name" %}</td>
						     		<td class="header" width="20%">{% trans "Is Dues Rep." %}</td>
						     		<td class="header" width="20%">{% trans "Is Member Rep." %}</td>
						     	</tr>
						     	{% for rep in field_obj.value %}
						     		<tr class="corp-rep">
						     		<td><a href="{% url profile rep.user.username %}">
						     			{{ rep.user.get_full_name }} ({{ rep.user.email  }})</a>
							     		
						            </td>
						     		<td>
						     			{% if rep.is_dues_rep %}
						     				{% trans "True" %}
						     			{% endif %}
						     		</td>
						     		<td>
						     		{% if rep.is_member_rep %}
						     				{% trans "True" %}
						     			{% endif %}
						     		</td>
						     		</tr>
						     	{% endfor %}
						     	</table>
						     	<div>&nbsp;</div>
			 					<div><a href="{% url corp_memb.edit_reps corporate_membership.pk %}">{% trans "Add/Edit Representatives" %}</a></div>
						    {% else %}
						    	<div>{% trans "No representatives available" %}</div>
						    	<div>&nbsp;</div>
			 					<div><a href="{% url corp_memb.edit_reps corporate_membership.pk %}">{% trans "Add Representatives" %}</a></div>
						    {% endif %} 
			 				
			 			{% else %}
			 				<span class="label">{{ field_obj.label }}</span>: 
			 				<span{% if field_obj.required %} class="bolded-content"{% endif %}>
				 			{% if  field_obj.is_date %}
				 				{{ field_obj.value|date:'long' }}
				 			{% else %}
				 				{% if field_obj.field_type == 'FileField' %}
				 					<a href="{{ MEDIA_URL }}{{ field_obj.value }}">{{ field_obj.value|basename }}</a>
				 				{% else %}
				 					{% if field_obj.value %}
                                        {% if field_obj.field_name  == 'phone' %}
                                        {{ field_obj.value|phonenumber }}
                                        {% else %}
				 						{{ field_obj.value|safe|urlize }}
                                        {% endif %}
				 					{% endif %}
				 				{% endif %}
				 			{% endif %}
				 			</span>
				 			
				 			{% if field_obj.field_name == 'corporate_membership_type' %}
				 				{% if corporate_membership.corp_app.authentication_method == "secret_code" %}
				 				<div>
				 				<span class="label">{% trans "Secret Code:" %}</span>: 
				 				<span><b>{{ corporate_membership.secret_code }}</b></span>
				 				</div>
				 				{% endif %}
				 			{% endif %}
				 			
				 			{% if field_obj.field_name == 'payment_method' %}
				 				{% if corporate_membership.invoice %}
				 					{% if request.user.is_superuser %}
				 					<div>&nbsp;</div>
				 					<div>
				 					<a href="{{ corporate_membership.invoice.get_absolute_url }}">{% trans "View Invoice" %}</a>
				 					</div>
				 					{% endif %}
				 				{% endif %}
				 			{% endif %}
				 			
				 		{% endif %}
			 		</div>
			 	{% endif %}
			 {% endfor %}
		</div>
    </div>

	
</div>

{% endblock %}

{% block extra_body %}
{{ block.super }}
<script>
	var filename = "{{ STATIC_URL }}js/global/dropdown.js";

	if (typeof dropdown == "undefined")
	{
		var fileref=document.createElement('script');
		fileref.setAttribute("type","text/javascript");
		fileref.setAttribute("src", filename);
		var head = document.getElementsByTagName('head')[0];
		head.appendChild(fileref);
	}
</script>
 <script type="text/javascript">
	$(document).ready(function(){

		// delete confirmation
		$('.delete').click(function(){
			var delete_corp_memb = confirm('Permenantly delete {% firstof MODULE_CORPORATEMEMBERSHIPS_LABEL 'Corporate Membership' %}?');	// confirm
			if(delete_corp_memb) $(this).parents('.corpmemb-view').find('form[name="corp-memb-delete"]').submit() // delete: if OK
			return false;	// cancel
		});
		
		var iconrow = new dropdown({
			container:	'more-options-wrap',
			trigger:	'more-options-trigger',
			target:		'more-options-target'
		});
		
	});
   </script>
	
{% endblock %}
