{% extends 'iconolab_base.html' %}

{% load staticfiles %}

{% load thumbnail %}

{% load iconolab_tags %}

{% load notifications_tags %}

{% block content %}
  <div class="row" style="border: 1px solid gray;">
    <div class="col-md-12 user-profile-block" >
      
      <h3>{% if profile_user == request.user %}Mon espace:{% else %}Profil : {% endif %} {{profile_user.username}}</h3>
      <div class="panel panel-default" style="padding-left: 10px; padding-right: 10px;">
        {% if profile_user == request.user %}
        {% notifications_unread as unread_count %}
        <h4><span class="badge notif-badge {% if unread_count %}badge-warning{% endif %}">{{unread_count}} <i class="fa fa-envelope-o" aria-hidden="true"></i></span> Notifications non lues 
          <a href="{% url 'user_notifications' %}" class="btn btn-default btn-xs">Voir toutes mes notifications</a>
          {% if unread_count %}<a href="{% url 'user_home' profile_user.id %}?clear_notifications=True" class="btn btn-default btn-xs">Tout marquer comme lu</a>{% endif %}
        </h4>
        <div class="row">
          <div class="col-md-12">
            {% if unread_count %}
              <ul class="list-group">
              {% for notification in notifications.unread %}
                <a  
                  {% if notification.target and notification.action_object %}
                    {% with notification.target as annotation %}
                      class="list-group-item list-group-item-info {% if forloop.counter > 5 %}hide-on-load{% endif %}"
                      {% if notification.action_object.get_comment_page %}
                      href="{% url 'annotation_detail' annotation.image.item.collection.name annotation.image.image_guid annotation.annotation_guid %}?page={{notification.action_object.get_comment_page}}#c{{notification.action_object.id}}"
                      {% else %}
                      href="{% url 'revision_detail' annotation.image.item.collection.name annotation.image.image_guid annotation.annotation_guid notification.action_object.revision_guid %}"
                      {% endif %}
                    {% endwith %}
                  {% else %}
                    class="list-group-item disabled {% if forloop.counter > 5 %}hide-on-load{% endif %}"
                  {% endif %}>
                  <b>{{notification.actor.username}}</b> {{notification.verb}} <small> - {{notification.timesince}}</small>
                </a>
                {% if forloop.counter == 5 %}
                  <a class="list-group-item show-all-notifications" title="Montrer autres notifications"> ... </a>
                {% endif %}
              {% endfor %}
              </ul>
            {% endif %}
            <hr>
          </div>
        </div>
        {% endif %}
        <div class="row">
          <div class="col-md-6">
            <h4>{% if profile_user == request.user %}Mes annotations :{% else %}Annotations de {{profile_user.username}}{% endif %} </h4>
            
            {% if not user_annotations %}
              <h4 class="no-user-annotation"><small>Aucune annotation à afficher</small></h4>
            {% else %}
              <ul class="list-inline">
                {% for annotation in user_annotations.all %}
                  {% include "partials/user_page_annotation_panel.html" with annotation=annotation %}
                {% endfor %}
              </ul>
            {% endif %}
          </div>
          <div class="col-md-6">
            <h4>{% if profile_user == request.user %}Mes autres contributions :{% else %}Contributions de {{profile_user.username}}{% endif %} </h4>
            <dl>
            <dt class="dt-annotation">
              {% if profile_user == request.user %}
                Annotations sur lesquelles j'ai proposé des révisions :
              {% else %}
                Annotations sur lesquelles {{profile_user.username}} a proposé des révisions :
              {% endif %} 
              </dt>
              <dd>
              {% if not user_revisions_annotations %}
                 <h4 class="no-user-annotation"><small>Aucune annotation à afficher</small></h4>
              {% else %}
                <ul class="list-inline">
                  {% for annotation in user_revisions_annotations.all %}
                    {% include "partials/user_page_annotation_panel.html" with annotation=annotation %}
                  {% endfor %}
                </ul>
              {% endif %}
              </dd>
              <dt class="dt-annotation">
              {% if profile_user == request.user %}
                Annotations sur lesquelles j'ai commenté (sans proposer de révision) :
              {% else %}
                Annotations sur lesquelles {{profile_user.username}} a commenté (sans proposer de révision) :
              {% endif %}
              </dt>
              <dd>
              {% if not user_comments_annotations %}
                 <h4 class="no-user-annotation"><small>Aucune annotation à afficher</small></h4>
              {% else %}
                <ul class="list-inline">
                  {% for annotation in user_comments_annotations.all %}
                    {% include "partials/user_page_annotation_panel.html" with annotation=annotation %}
                  {% endfor %}
                </ul>
              {% endif %}
              </dd>
            </dl>
          </div>
        </div>
      </div>
    </div>
    {% if profile_user == request.user and profile_user.profile.administers_collection %}
    <div class="col-md-12">
      <div class="panel panel-default" style="padding: 10px;">
      
        <div class="alert alert-warning">
          L'accès à ces fonctionnalités n'est pas encore disponible.
        </div>
        <h3><small>Administration du Fonds</small> {{user.profile.administers_collection.verbose_name}}</h3>
        <div class="text-center">
          <a href="#" class="btn btn-default disabled text-center">Tableau de bord</a>
        </div>
      </div>
    </div>
    {% endif %}
  </div>

{% endblock %}

{% block footer_js %}
  <script>
  	$(".hide-on-load").hide()
  	$(".show-all-notifications").click(function(){
  	  	$(".show-all-notifications").hide();
  	    $(".hide-on-load").slideDown();
  	})
  </script>
{% endblock %}