{% extends "cosinnus/base.html" %}
{% load i18n cosinnus_tags cosinnus_map_tags static %}

{% block page_title %}
  {% blocktrans with team_name=object.name %}{{ team_name }} - Members{% endblocktrans %}
{% endblock %}

{% block extrahead %}
	{% include 'cosinnus/map/static_dependencies.html' %}
{% endblock extrahead %}

{% block og_meta_attributes %}
	{% include 'cosinnus/group/group_og_meta_attributes.html' with group=group %}
{% endblock og_meta_attributes %}


{% block leftnav %}
    {% include "cosinnus/group/leftnav_group.html"  with current_page="groupdetails" %}
    
    {% if object.type == 0 %}
        {% include 'cosinnus/common/help_button_leftnav_for_popup.html' with help_text_id="helptext_12_projectadministration" %}
    {% else %}
        {% include 'cosinnus/common/help_button_leftnav_for_popup.html' with help_text_id="helptext_13_groupadministration" %}
    {% endif %}
{% endblock leftnav %}

{% block breadcrumb %}
        {{ block.super }}
        <li class="active">{% trans "Members" %}</li>
{% endblock %}


{% block content %}

    <!-- a box with semi transparent background -->
    <div class="content-box">
    	{% include 'cosinnus/common/internet_explorer_not_supported.html' %}
    
		<div class="map-root"></div>
		{% captureas map_settings %}{"filterGroup": {{ group.id }}, "controlsEnabled": false, "activeFilters": {"groups": false, "events": false, "projects": {% if group.type == 1 %}true{% else %}false{% endif %}, "people": true}, "availableFilters": {"groups": true, "events": true, "projects": true, "people": true}, "markerIcons": {% render_map_marker_icon_json %}}{% endcaptureas %}
		{% include 'cosinnus/common/init_client_module.html' with module='map' id=""|add_uuid height=400 settings=map_settings %}
        <div class="clearfix"></div>
    </div>

    <!-- a box with semi transparent background -->
    <div class="content-box">
        
        {% comment %}  leave this here, the jump is what we want always  {% endcomment %} 
        <a class="anchor" id="invite"></a>
        
        {% if user|has_write_access:object %}
            <legend>{% trans "Invite a member" %}</legend>
            
            <form action="{% group_url 'cosinnus:group-user-add-generic' group=object %}" method="post">{% csrf_token %}
	            <div type="button" class="btn btn-emphasized w100">
	                <ul class="media-list">
	                    <li class="media">
	                        <a class="pull-left" href="#">
	                            <i class="fa fa-user"></i>
	                        </a>
	                        <div class="media-body white-content">
	                            <select name="user" class="w100 user-selector next-button-is-for-sending" data-placeholder="{% trans 'Invite a member' %}...">
	                                <option></option>
	                                <option value="" default disabled selected>{% trans 'Invite a member' %}</option>
	                                {% for candidate in non_members %}
	                                   <option value="{{ candidate.pk }}">{{ candidate|full_name }}</option>
	                                {% endfor %}
	                            </select>
	                            <input type="hidden" name="status" value="3" />
	                        </div>
	                    </li>
	                </ul>
	            </div>
	            <button type="submit" class="btn btn-emphasized large-space" style="display: none;">
	                <ul class="media-list">
	                    <li class="media">
	                        <a class="pull-left" href="#">
	                            <i class="fa fa-pencil"></i>
	                        </a>
	                        <div class="media-body">
	                            {% trans "Invite user" %}
	                        </div>
	                    </li>
	                </ul>
	            </button>
            </form>
        {% endif %}
        
        
        {% if user|has_write_access:object or user in invited %}
            
            <legend>{% trans "Invited Members" %}</legend>
            
            {% for member in invited %}
               {% comment %} In public groups, we enable the logged in user to see himself as pending user {% endcomment %}
               {% if user|has_write_access:object or user == member %}
                    <div class="fadedown regular-space">
                        <div class="btn btn-default w100">
                            <ul class="media-list">
                                <li class="media">
                                    <a class="pull-left" href="{{ member|profile_url }}">
                                        {% include "cosinnus/user/user_avatar_image.html" with user=member %}
                                    </a>
                                    {% if user|has_write_access:object or user == member %}
                                    <a class="pull-right fadedown-clickarea" href="#">
                                        <i class="fa fa-chevron-down"></i>
                                    </a>
                                    {% endif %}
                                    <div class="media-body">
                                        <span class="annotation">
                                            {% trans "Invited to be a member" %}
                                            &nbsp;
                                            <span class="moment-data-date" data-date="{{ member.membership_status_date|date:'c' }}"></span>
                                        </span>
                                        <a href="{% url 'cosinnus:profile-detail' username=member.username %}">
                                            {{ member|full_name }}
                                        </a>
                                    </div>
                                </li>
                            </ul>
                        </div>
                        
                        {% if user|has_write_access:object %}
                            <div>
                                {% captureas modal_revoke_id %}userModal_revoke_{{member.pk}}{% endcaptureas %}
                                
                                <button type="button" class="btn btn-emphasized" data-toggle="modal" data-target="#{{modal_revoke_id}}">
                                    <ul class="media-list">
                                        <li class="media">
                                            <a class="pull-left" href="#">
                                                <i class="fa fa-close"></i>
                                            </a>
                                            <div class="media-body">
                                                {% trans "Revoke Invitation" %}
                                            </div>
                                        </li>
                                    </ul>
                                </button>
                            </div>
                        {% endif %}
                        
                        {% if user == member %}
                            <div>
                                {% captureas modal_decline_invitation_id %}userModal_decline_invitation_{{member.pk}}{% endcaptureas %}
                                <button type="button" class="btn btn-emphasized" data-toggle="modal" data-target="#{{modal_decline_invitation_id}}">
                                    <ul class="media-list">
                                        <li class="media">
                                            <a class="pull-left" href="#">
                                                <i class="fa fa-close"></i>
                                            </a>
                                            <div class="media-body">
                                                {% trans "Decline Invitation" %}
                                            </div>
                                        </li>
                                    </ul>
                                </button>
                                
                                <form action="{% group_url 'cosinnus:group-user-accept' group=object %}" method="post">{% csrf_token %}
                                    <button type="submit" class="btn btn-emphasized">
                                        <ul class="media-list">
                                            <li class="media">
                                                <a class="pull-left" href="#">
                                                    <i class="fa fa-sign-in"></i>
                                                </a>
                                                <div class="media-body">
                                                    {% trans "Accept Invitation" %}
                                                </div>
                                            </li>
                                        </ul>
                                    </button>
                                </form>
                            </div>
                        {% endif %}
                        
                    </div><!-- fadedown -->
                    
                    {% if user|has_write_access:object %}    
                        {% captureas label %}{% blocktrans with name=member|full_name %}Do you really want to revoke the invitation for member „{{ name }}“?{% endblocktrans %}{% endcaptureas %}
                        {% captureas title %}{% trans "Revoke Invitation for Member" %}{% endcaptureas %}
                        {% captureas action %}{% group_url 'cosinnus:group-user-delete' group=object username=member.username %}{% endcaptureas %}
                        {% include "cosinnus/modal_box.html" with id=modal_revoke_id label=label title=title form_action=action %}
                    {% endif %}
                    {% if user == member %}    
                        {% captureas label %}{% blocktrans %}Do you really want to decline the invitation?{% endblocktrans %}{% endcaptureas %}
                        {% captureas title %}{% trans "Decline Invitation" %}{% endcaptureas %}
                        {% captureas action %}{% group_url 'cosinnus:group-user-decline' group=object %}{% endcaptureas %}
                        {% include "cosinnus/modal_box.html" with id=modal_decline_invitation_id label=label title=title form_action=action %}
                    {% endif %}
                
                {% endif %}
                
            {% empty %}
                <!-- {% trans "There are no pending invitations." %} -->
                {% include 'cosinnus/common/empty_button.html' with message="There are no pending invitations." %}
            {% endfor %}
            
        {% endif %}
        
		
        {% if user|has_write_access:object or user in pendings %}
            
            <legend>{% trans "Membership requests" %}</legend>
            
	        {% for member in pendings %}
	           
	           {% comment %} In public groups, we enable the logged in user to see himself as pending user {% endcomment %}
	           {% if not user in pendings or user == member %}
		            <div class="fadedown regular-space">
		                <div class="btn btn-default w100">
		                    <ul class="media-list">
		                        <li class="media">
		                            <a class="pull-left" href="{{ member|profile_url }}">
		                                {% include "cosinnus/user/user_avatar_image.html" with user=member %}
		                            </a>
		                            {% if user|has_write_access:object %}
		                            <a class="pull-right fadedown-clickarea" href="#">
		                                <i class="fa fa-chevron-down"></i>
		                            </a>
		                            {% endif %}
		                            <div class="media-body">
	                                    <span class="annotation">
                                            {% trans "Membership requested" %}
	                                        &nbsp;
	                                        <span class="moment-data-date" data-date="{{ member.membership_status_date|date:'c' }}"></span>
	                                    </span>
		                                <a href="{% url 'cosinnus:profile-detail' username=member.username %}">
		                                    {{ member|full_name }}
		                                </a>
		                            </div>
		                        </li>
		                    </ul>
		                </div>
		                
		                {% if user|has_write_access:object %}
		                    <div>
		                        {% captureas modal_kick_id %}userModal_kick_{{member.pk}}{% endcaptureas %}
		                        {% captureas modal_promote_id %}userModal_promote_{{member.pk}}{% endcaptureas %}
		                        <button type="button" class="btn btn-emphasized" data-toggle="modal" data-target="#{{modal_kick_id}}">
		                            <ul class="media-list">
		                                <li class="media">
		                                    <a class="pull-left" href="#">
		                                        <i class="fa fa-eraser"></i>
		                                    </a>
		                                    <div class="media-body">
		                                        {% trans "Decline User" %}
		                                    </div>
		                                </li>
		                            </ul>
		                        </button>
		                        
		                        <button type="button" class="btn btn-emphasized" data-toggle="modal" data-target="#{{modal_promote_id}}">
		                            <ul class="media-list">
		                                <li class="media">
		                                    <a class="pull-left" href="#">
		                                        <i class="fa fa-group"></i>
		                                    </a>
		                                    <div class="media-body">
	                                            {% trans "Accept User" %}
		                                    </div>
		                                </li>
		                            </ul>
		                        </button>
		                    </div>
		                    
		                {% endif %}
		                
		            </div><!-- fadedown -->
		            
		            {% if user|has_write_access:object %}    
	                    {% captureas label %}{% blocktrans with name=member|full_name %}Do you really want to accept user „{{ name }}“ as a member?{% endblocktrans %}{% endcaptureas %}
	                    {% captureas title %}{% trans "Accept Member" %}{% endcaptureas %}
	                    {% captureas action %}{% group_url 'cosinnus:group-user-edit' group=object username=member.username %}{% endcaptureas %}
	                    {% captureas extra_fields %}<input type="hidden" name="user" value="{{member.pk}}" /><input type="hidden" name="status" value="1" />{% endcaptureas %}
		                {% include "cosinnus/modal_box.html" with id=modal_promote_id label=label title=title form_action=action form_extra_fields=extra_fields %}
		                
		                {% captureas label %}{% blocktrans with name=member|full_name %}Do you really want to decline member „{{ name }}“?{% endblocktrans %}{% endcaptureas %}
		                {% captureas title %}{% trans "Decline Member" %}{% endcaptureas %}
		                {% captureas action %}{% group_url 'cosinnus:group-user-delete' group=object username=member.username %}{% endcaptureas %}
		                {% include "cosinnus/modal_box.html" with id=modal_kick_id label=label title=title form_action=action %}
		                
		            {% endif %}
	            
	            {% endif %}
	            
	        {% empty %}
	            <!-- {% trans "There are no new membership requests." %} -->
	            {% include 'cosinnus/common/empty_button.html' with message="There are no new membership requests." %}
	        {% endfor %}
            
        {% endif %}
		
		
        
        {% comment %} -------- Recruit Box and list of recruitees -------- {% endcomment %}
        
        {% if user in members or user|is_superuser %}
            <div class="clearfix large-space"></div>
        
            <legend>{% trans "Invite People to Register and Join" %}</legend>
            
            <button type="submit" class="btn btn-emphasized btn-left" data-toggle="modal" data-target="#modal-recruit-users">
                <ul class="media-list">
                    <li class="media">
                        <a class="pull-left" href="#">
                            <i class="fa fa-user-plus"></i>
                        </a>
                        <div class="media-body">
                            {% trans "Invite people" %}
                        </div>
                    </li>
                </ul>
            </button>
            
            {% include 'cosinnus/common/modal_box_recruit_users.html' %}
            
            <div class="clearfix"></div>
        {% endif %}
        
        {% if recruited %}
            {% if user in admins or user|is_superuser %}        
                <legend>{% trans "All currently invited people" %}</legend>
            {% else %}
                <legend>{% trans "People currently invited by you" %}</legend>
            {% endif %}
            
	            {% for recruitation in recruited %}
	                {% captureas modal_id %}deleteModal_{{recruitation.id}}{% endcaptureas %}
	                
	                <div class="btn btn-default w100 regular-space">
                        <ul class="media-list">
                            <li class="media">
                                <div class="media-body">
                                    <span class="annotation">
                                        {% trans "Invited to be a member" %}
                                        &nbsp;
                                        <span class="moment-data-date" data-date="{{ recruitation.last_modified|date:'c' }}"></span>
                                        {% if user == recruitation.invited_by or user in admins or user|is_superuser %}
                                            <a title="{% trans "Delete invitation" %}" href="#" data-toggle="modal" data-target="#{{modal_id}}">
                                                <i class="fa fa-trash"></i>
                                            </a>
                                        {% endif %}
                                    </span>
                                    {{ recruitation.email }}
                                    {% if not recruitation.invited_by == user %}
				                        <i>
				                           ({% trans "by" context "an action done *by* <username>" %}
				                           <a href="{% url 'cosinnus:profile-detail' username=recruitation.invited_by.username %}">{{ recruitation.invited_by|full_name }}</a>)
				                        </i>
				                    {% endif %}
                                </div>
                            </li>
                        </ul>
                    </div>
                    {% if user == recruitation.invited_by or user in admins or user|is_superuser %}
                        {% captureas label %}{% blocktrans with title=recruitation.email %}Do you really want to delete the invitation for "{{ title }}"?{% endblocktrans %}{% endcaptureas %}
                        {% captureas title %}{% trans "Delete invitation" %}{% endcaptureas %}
                        {% captureas action %}{% group_url 'cosinnus:group-user-recruit-delete' group=group id=recruitation.id %}{% endcaptureas %}
                        {% include "cosinnus/modal_box.html" with id=modal_id label=label title=title form_action=action %}
                    {% endif %}
	            {% endfor %}
	            
	            
            
	        <div class="clearfix"></div>
        {% endif %}
    

	
        <legend>{% trans "Members" %}{% if member_count %} ({{ member_count }}){% endif %}</legend>
    
        {% for member in members %}
            <div class="fadedown {% if not forloop.last or hidden_user_count > 0 %}regular-space{% endif %}">
                <div class="btn btn-emphasized w100">
                    <ul class="media-list">
                        <li class="media">
                            <a class="pull-left" href="{{ member|profile_url }}">
                                {% include "cosinnus/user/user_avatar_image.html" with user=member %}
                            </a>
                            {% if user|has_write_access:object %}
                            <a class="pull-right fadedown-clickarea" href="#">
                                <i class="fa fa-chevron-down"></i>
                            </a>
                            {% endif %}
                            {% if not member == user and not SETTINGS.COSINNUS_IS_INTEGRATED_PORTAL %}
                            <a class="pull-right" href="{% url 'postman:write' recipients=member.username %}" title="{% trans "Send Message" %}">
	                            <i class="fa fa-envelope"></i>
	                        </a>
	                        {% endif %}
                            <div class="media-body">
                                    <span class="annotation">
                                        {% if member in admins %}
                                            {% trans "Admin" %}
                                        {% elif member in members %}
                                            {% trans "Member" %}
                                        {% endif %}
                                    </span>
                                <a href="{% url 'cosinnus:profile-detail' username=member.username %}">
                                    {{ member|full_name }}
                                </a>
                            </div>
                        </li>
                    </ul>
                </div>
                
                <div>
	                {% if user|has_write_access:object %}
	                    {% captureas modal_kick_id %}userModal_kick_{{member.pk}}{% endcaptureas %}
	                    {% captureas modal_promote_id %}userModal_promote_{{member.pk}}{% endcaptureas %}
	                    <button type="button" class="btn btn-emphasized" data-toggle="modal" data-target="#{{modal_kick_id}}">
	                        <ul class="media-list">
	                            <li class="media">
	                                <a class="pull-left" href="#">
	                                    <i class="fa fa-eraser"></i>
	                                </a>
	                                <div class="media-body">
	                                    {% trans "Kick" %}
	                                </div>
	                            </li>
	                        </ul>
	                    </button>
	                    
	                    <button type="button" class="btn btn-emphasized" data-toggle="modal" data-target="#{{modal_promote_id}}">
	                        <ul class="media-list">
	                            <li class="media">
	                                <a class="pull-left" href="#">
	                                    <i class="fa fa-group"></i>
	                                </a>
	                                <div class="media-body">
	                                    {% if member in admins %}
	                                        {% trans "Make Member" %}
	                                    {% else %}
	                                        {% trans "Make Admin" %}
	                                    {% endif %}
	                                </div>
	                            </li>
	                        </ul>
	                    </button>
	                {% endif %}
	                
	                {% include 'cosinnus/feedback/report_button_btn.html' with object=member %}
                </div>
                
            </div><!-- fadedown -->
            
            {% if user|has_write_access:object %}    
                {% if member in admins %}
                    {% captureas label %}{% blocktrans with name=member|full_name %}Do you really want to demote administrator „{{ name }}“ to member?{% endblocktrans %}{% endcaptureas %}
                    {% captureas title %}{% trans "Demote Admin" %}{% endcaptureas %}
                    {% captureas action %}{% group_url 'cosinnus:group-user-edit' group=object username=member.username %}{% endcaptureas %}
                    {% captureas extra_fields %}<input type="hidden" name="user" value="{{member.pk}}" /><input type="hidden" name="status" value="1" />{% endcaptureas %}
                {% else %}
                    {% captureas label %}{% blocktrans with name=member|full_name %}Do you really want to promote member „{{ name }}“ to administrator?{% endblocktrans %}{% endcaptureas %}
                    {% captureas title %}{% trans "Promote Member" %}{% endcaptureas %}
                    {% captureas action %}{% group_url 'cosinnus:group-user-edit' group=object username=member.username %}{% endcaptureas %}
                    {% captureas extra_fields %}<input type="hidden" name="user" value="{{member.pk}}" /><input type="hidden" name="status" value="2" />{% endcaptureas %}
                {% endif %}
                {% include "cosinnus/modal_box.html" with id=modal_promote_id label=label title=title form_action=action form_extra_fields=extra_fields %}
                
                {% captureas label %}{% blocktrans with name=member|full_name %}Do you really want to remove member „{{ name }}“ from the team?{% endblocktrans %}{% endcaptureas %}
                {% captureas title %}{% trans "Remove Member" %}{% endcaptureas %}
                {% captureas action %}{% group_url 'cosinnus:group-user-delete' group=object username=member.username %}{% endcaptureas %}
                {% include "cosinnus/modal_box.html" with id=modal_kick_id label=label title=title form_action=action %}
                
            {% endif %}
            
        {% endfor %}
        
        {% if hidden_user_count > 0 %}
            <div class="btn btn-default w100">
                <ul class="media-list">
                    <li class="media">
                        <a class="pull-left" href="#">
                            <img src="{% static 'images/jane-doe.png' %}" />
                        </a>
                        <div class="media-body">
                            {% blocktrans with hidden_count=hidden_user_count %}And {{ hidden_count }} private users...{% endblocktrans %}
                        </div>
                    </li>
                </ul>
            </div>
        {% endif %}
        
        {% if more_user_count > 0 %}
        	<br/>
            <div class="btn btn-default w100" href="?show=all">
                <ul class="media-list">
                    <li class="media">
                        <a class="pull-left" >
                            <i class="fa fa-chevron-down"></i>
                        </a>
                        <div class="media-body">
                            {% blocktrans with more_count=more_user_count %}Show all of the other {{ more_count }} users...{% endblocktrans %}
                        </div>
                    </li>
                </ul>
            </div>
        {% endif %}
        
        
        
    </div>

  
  
  
{% endblock %}
