{% extends "cosinnus/base.html" %}
{% load i18n bootstrap3 cosinnus_tags %}
{% load static from staticfiles %}

{% block page_title %}{{ group.name }}{% endblock page_title %}

{% block extrahead %}
  <link href="{% static "css/cosinnus.dashboard.css" %}" rel="stylesheet">
{% endblock extrahead %}

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

{% block container_classes %}container{% endblock container_classes %}

{% block main_page_header %}
    
    <div class="row app-main">
        <!-- start with left navigation -->
        <div class="col-lg-3 col-md-3"><!-- left column -->
            {% if group %}
                {% cosinnus_menu "cosinnus/appsmenu.html" %}
            {% endif %}
        </div><!-- left column -->
        
        <!-- now the content -->
        <div class="col-lg-9 col-md-9"><!-- right column -->
	
			{% if SETTINGS.COSINNUS_ALLOW_DASHBOARD_WIDGET_REARRANGE %}
		    {% if user.is_authenticated and user.pk in group.admins or user.is_superuser %}
		    <button type="button" class="btn btn-emphasized" id="dashboardArrangeInputShow">
		        <ul class="media-list">
		            <li class="media">
		                <a class="pull-left" href="#">
		                    <i class="fa {% if edit_mode %}fa-reply{% else %}fa-cogs{% endif %}"></i>
		                </a>
		                <div class="media-body">
		                    {% trans "Rearrange" %}
		                </div>
		            </li>
		        </ul>
		    </button><!-- btn -->
		    
		    <button type="button" class="btn btn-emphasized" id="dashboardArrangeInputSave" style="display: none;">
		        <ul class="media-list">
		            <li class="media">
		                <a class="pull-left" href="#">
		                    <i class="fa {% if edit_mode %}fa-reply{% else %}fa-cogs{% endif %}"></i>
		                </a>
		                <div class="media-body">
		                    {% trans "Save" %}
		                </div>
		            </li>
		        </ul>
		    </button><!-- btn -->
		    <button type="button" class="btn btn-default" id="dashboardArrangeInputCancel" style="display: none;">
		        <ul class="media-list">
		            <li class="media">
		                <a class="pull-left" href="#">
		                    <i class="fa {% if edit_mode %}fa-reply{% else %}fa-cogs{% endif %}"></i>
		                </a>
		                <div class="media-body">
		                    {% trans "Cancel" %}
		                </div>
		            </li>
		        </ul>
		    </button><!-- btn -->
		    
		    <button type="button" class="btn btn-emphasized" id="dashboardArrangeInputWait" style="display: none;" disabled=1>
		        <ul class="media-list">
		            <li class="media">
		                <a class="pull-left" href="#">
		                    <i class="fa fa-cogs"></i>
		                </a>
		                <div class="media-body">
		                    {% trans "Saving..." %}
		                </div>
		            </li>
		        </ul>
		    </button><!-- btn -->
		    {% endif %}
		    {% endif %}


            
            <ol class="breadcrumb">
                {% include 'cosinnus/breadcrumb.html' %}
                <li class="active">{% trans "Dashboard" %}</li>
            </ol>
            
    		<div class="clearfix"></div>
            
        </div><!-- right column -->
        
    </div><!-- row -->
    
    
    {% include 'cosinnus/messages.html' %}
    
    {% if SETTINGS.COSINNUS_ALLOW_DASHBOARD_WIDGET_REARRANGE %}
    	<div id="dashboardArrangeMessage" class="alert alert-success alert-dismissable" style="display: none;">
            <i class="fa fa-exclamation fa-3x"></i>
            <h4>{% trans "You are now editing the dashboard's layout" %}</h4>
            <div class="v-offset-s">
	        <p>
	        	{% blocktrans with group.name as team_name %}The layout you choose will be the layout for all members of {{ team_name }}! Click save to apply your changes.{% endblocktrans %}
	        </p>
	        <p>
				{% trans "Drag and drop individual widgets to rearrange their order. Please note that the order you give is only an approximate prioritization for the widgets. After saving, the actual order on the page might differ depending on the widgets' current size and the overall page layout." %}</a>
			</p>
			</div>
	    </div>
    {% endif %}
    
    {% if SETTINGS.COSINNUS_MICROSITES_ENABLED %}
	    {% comment %} -------    Microsite edit-me message ------------ {% endcomment %}
	    {% if user.is_authenticated and user.pk in group.admins and not group.description_long %}
		    <div class="alert alert-warning alert-dismissable">
	            <i class="fa fa-heart fa-3x"></i>
	            <h4>{% trans "Your Microsite needs some love!" %}</h4>
	            <div class="v-offset-s">
		        <p>
		        	{% if group.type == 0 %}
		        		{% trans "The Microsite is your projects's welcome page for everyone checking it out. Make it awesome so they want to join you!" %}
		        	{% else %}
			        	{% trans "The Microsite is your group's welcome page for everyone checking it out. Make it awesome so they want to join you!" %}
		        	{% endif %}
		        </p>
		        <p>
					{% trans "Access it from the top menu or" %} <a href="{% group_url 'cosinnus:group-microsite' group=group %}">{% trans "get started here..." %}</a>
				</p>
				</div>
		    </div>
	    {% endif %}
    {% endif %}


    <div class="dashboard-header">
        <div class="dashboard-header-image">
            <a href="{% group_url 'cosinnus:group-detail' group=group %}">
                {% include "cosinnus/group/group_avatar_image.html" with group=group %}
            </a>
        </div>
        <div class="dashboard-header-text">
            <div class="multiline-ellipsis">
                <div class="multiline-ellipsis-prop"></div>
                <div class="multiline-ellipsis-main">
                    {% if user.pk in group.members or user in group.admins or not user.is_authenticated %}
                    	
                    	{% if "marketplace" in object_counts %}
                            <div class="dashboard-header-link app-marketplace">
                                <a href="{% group_url 'cosinnus:marketplace:list' group=group %}">
                                    <i class="fa fa-exchange"></i>
                                    <span>{{ object_counts.marketplace }}</span>
                                    {% if object_counts.marketplace == 1 %}{% trans "Marketplace" %}{% else %}{% trans "Marketplace" %}{% endif %}
                                </a>
                            </div>
                        {% endif %}
                    	{% if "poll" in object_counts %}
                            <div class="dashboard-header-link app-poll">
                                <a href="{% group_url 'cosinnus:poll:list' group=group %}">
                                    <i class="fa fa-bar-chart"></i>
                                    <span>{{ object_counts.poll }}</span>
                                    {% if object_counts.poll == 1 %}{% trans "Poll" %}{% else %}{% trans "Polls" %}{% endif %}
                                </a>
                            </div>
                        {% endif %}
                        {% if "file" in object_counts %}
                            <div class="dashboard-header-link app-files">
                                <a href="{% group_url 'cosinnus:file:list' group=group %}">
                                    <i class="fa fa-file"></i>
                                    <span>{{ object_counts.file }}</span>
                                    {% if object_counts.file == 1 %}{% trans "File" %}{% else %}{% trans "Files" %}{% endif %}
                                </a>
                            </div>
                        {% endif %}
                        {% if "etherpad" in object_counts %}
                            <div class="dashboard-header-link app-etherpad">
                                <a href="{% group_url 'cosinnus:etherpad:list' group=group %}">
                                    <i class="fa fa-file-text-o"></i>
                                    <span>{{ object_counts.etherpad }}</span>
                                    {% if object_counts.etherpad == 1 %}{% trans "Etherpad" %}{% else %}{% trans "Etherpads" %}{% endif %}
                                </a>
                            </div>
                        {% endif %}
                        {% if "todo" in object_counts %}
                            <div class="dashboard-header-link app-todos">
                                <a href="{% group_url 'cosinnus:todo:list' group=group %}">
                                    <i class="fa fa-tasks"></i>
                                    <span>{{ object_counts.todo }}</span>
                                    {% if object_counts.todo == 1 %}{% trans "Todo" %}{% else %}{% trans "Todos" %}{% endif %}
                                </a>
                            </div>
                        {% endif %}
                        {% if "event" in object_counts %}
                            <div class="dashboard-header-link app-calendar">
                                <a href="{% group_url 'cosinnus:event:list' group=group %}">
                                    <i class="fa fa-calendar"></i>
                                    <span>{{ object_counts.event }}</span>
                                    {% if object_counts.event == 1 %}{% trans "Event" context "Calendar" %}{% else %}{% trans "Events" context "Calendar" %}{% endif %}
                                </a>
                            </div>
                        {% endif %}
                        {% if "note" in object_counts %}
                            <div class="dashboard-header-link app-main">
                                <a href="{% group_url 'cosinnus:note:list' group=group %}">
                                    <i class="fa fa-book"></i>
                                    <span>{{ object_counts.note }}</span>
                                    {% if object_counts.todo == 1 %}{% trans "News" %}{% else %}{% trans "News" %}{% endif %}
                                </a>
                            </div>
                        {% endif %}
                        
                    {% elif user.pk in group.pendings %}
                        <div class="dashboard-header-link app-etherpad" data-toggle="modal" data-target="#join_withdraw_modal">
                            <a href="#">
                                <i class="fa fa-sign-out"></i>
                                <span>{% trans "Withdraw" context "withdraw join team button first item" %}</span>
                                {% trans "Request" context "withdraw join team button second item" %}
                            </a>
                        </div>
                        <div class="dashboard-header-link app-main">
                            <i class="fa fa-info-circle"></i>
                            <span>{% trans "Join" context "join request pending team button first item" %}</span>
                            {% trans "Requested" context "join request pending team button second item" %}
                        </div>
                        {% captureas label %}{% blocktrans with title=group.name %}Do you really want to withdraw your join request to „{{ title }}“?{% endblocktrans %}{% endcaptureas %}
                        {% captureas title %}{% trans "Withdraw Join Request" %}{% endcaptureas %}
                        {% captureas action %}{% group_url 'cosinnus:group-user-withdraw' group=group %}{% endcaptureas %}
                        {% include "cosinnus/modal_box.html" with id="join_withdraw_modal" label=label title=title form_action=action %}
                    {% else %}
                        <div class="dashboard-header-link app-main" data-toggle="modal" data-target="#join_withdraw_modal">
                            <a href="#">
                                <i class="fa fa-sign-in"></i>
                                <span>{% trans "Join" context "join team button first item" %}</span>
                                {% trans "Now" context "join team button second item" %}
                            </a>
                        </div>
                        {% captureas label %}{% blocktrans with title=group.name %}Do you wish to request to join „{{ title }}“?{% endblocktrans %}{% endcaptureas %}
                        {% captureas title %}{% trans "Join" %}{% endcaptureas %}
                        {% captureas action %}{% group_url 'cosinnus:group-user-join' group=group %}{% endcaptureas %}
                        
                        {% include "cosinnus/modal_box.html" with id="join_withdraw_modal" label=label title=title form_action=action %}
                    {% endif %}
                    
                    {% comment %} Group follow button is out for now
                    <div class="dashboard-header-link app-main">
                        <a href="#" title="Not available in this Beta version">
                            <i class="fa fa-thumbs-o-up"></i>
                            {% trans "Gruppe abonnieren" %}
                        </a>
                    </div>
                     {% endcomment %}
                    
                    <h2>
                    	{{ group.name }}
	                    {% if group.facebook_group_id %}
	                    		&nbsp;<a href="https://facebook.com/{{ group.facebook_group_id}}/" target="_blank" title="{% trans "View on Facebook" %}"><i class="fa fa-facebook-square"></i></a>
	                    {% elif group.facebook_page_id %}
	                    		&nbsp;<a href="https://facebook.com/{{ group.facebook_page_id}}/" target="_blank" title="{% trans "View on Facebook" %}"><i class="fa fa-facebook-square"></i></a>
	                    {% endif %}
                    </h2>
                    
                    {% with society=group.get_parent_typed %}
                        {% if society %}
                            <p><i>{% trans "Group:" %} <a href="{{ society.get_absolute_url }}">{{ society.name }}</a></i></p>
                        {% endif %}
                    {% endwith %}
                    
                    <p></p>
                    {% if group.description and group.description|length > 0 %}
                        <div class="textfield transparent">{{ group.description|textfield }}</div>
                    {% else %}
                        <p>
                            <i>{% trans "No Description set" %}</i>
                        </p>
                    {% endif %}
                    
                    {% with  topics=group.media_tag_object.topics %}
                        {% if topics %}
                            <p>
	                           {% trans "Topics" %}: {% render_cosinnus_topics topics %}
                            </p>
	                    {% endif %}
                    {% endwith %}
                    
                    </div>
                <div class="multiline-ellipsis-realend"><a href="#">....{% trans "more" %}</a></div>
            </div>
        </div>
    </div>
{% endblock main_page_header %}
            

{% block main_page %}
    <div class="row" id="dashboard">
        <div class="col-xs-12 hidden" id="dashboard-unsorted">
        {% for widget in widgets %}
            {% cosinnus_render_widget widget %}
        {% endfor %}          
        </div>
        <div class="col-sm-6 col-md-4" id="dashboard-col1">
        </div>
        <div class="col-sm-6 col-md-4 hidden-xs" id="dashboard-col2">
        </div>
        <div class="col-md-4 hidden-xs hidden-sm" id="dashboard-col3">
        </div>
    </div><!-- row -->
{% endblock main_page %}


{% block extrafooter %}
  {{ block.super }}

  <script src="{% static "js/cosinnus.dashboard.js" %}?v=0.3"></script>
  <script type="text/javascript">
    $(document).ready(function(){
      var dashboard = window.Cosinnus.dashboard.init("#dashboard", {% if group.slug %}"{{ group.slug }}"{% else %}null{% endif %});
    });
  </script>
{% endblock %}