{% extends 'iconolab_base.html' %}

{% load staticfiles %}

{% load thumbnail %}

{% load iconolab_tags %}

{% load notifications_tags %}

{% block content %}
  <div class="page-header">
    <h1>{% if profile_user == request.user %}Mon espace:{% else %}Profil : {% endif %} {{profile_user.username}}</h1>
  </div>
  {% if profile_user == request.user %}
  <div class="row">
    <div class="col-md-12">
      <h2>Coordonnées</h2>
      <form method="post">
        {% csrf_token %}
        <fieldset class="form-group {% if user_form.email.errors %}has-error{% endif %}">
          <label class="control-label" for="id_{{ user_form.email.name }}">Email</label>
          <input type="text" class="form-control"
            name="{{ user_form.email.name }}"
            id="id_{{ user_form.email.name }}" value="{% if user_form.email.value %}{{ user_form.email.value }}{% endif %}">
          {% if user_form.email.errors %}
          <span class="help-block">{{ user_form.email.errors | striptags }}</span>
          {% endif %}
        </fieldset>
        <button type="submit" class="btn btn-block btn-primary">Valider</button>
      </form>
    </div>
  </div>
  {% endif %}
  <div class="row">
    <div class="col-md-12 user-profile-block" >
      <h2>Notifications</h2>
      <div>
        {% 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 dernières annotations :{% else %}Dernières 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_pages/annotations_created_panel.html" with annotation=annotation user=profile_user %}
                {% endfor %}
                <li>
                  <a class="btn btn-default btn-sm" href="{% url 'user_annotations' profile_user.id %}"><span class="glyphicon glyphicon-list" aria-hidden="true"></span> Voir toutes les annotations</a>
                </li>
              </ul>
            {% endif %}
          </div>
          <div class="col-md-6">
            <h4>{% if profile_user == request.user %}Mes contributions :{% else %}Contributions de {{profile_user.username}}{% endif %}</h4>
            <dl>
            <dt class="dt-annotation">
              {% if profile_user == request.user %}
                Dernières annotations sur lesquelles j'ai proposé des révisions :
              {% else %}
                Dernières annotations sur lesquelles {{profile_user.username}} a proposé des révisions :
              {% endif %}
              </dt>
              <dd>
              {% if not user_contributed_annotations %}
                 <h4 class="no-user-annotation"><small>Aucune annotation à afficher</small></h4>
              {% else %}
                <ul class="list-inline">
                  {% for annotation_data in user_contributed_annotations %}
                     {% include "partials/user_pages/annotations_contributed_panel.html" with annotation_data=annotation_data user=profile_user %}
                  {% endfor %}
                  <li>
                    <a class="btn btn-default btn-sm" href="{% url 'user_contributed' profile_user.id %}"><span class="glyphicon glyphicon-list" aria-hidden="true"></span> Voir toutes les contributions</a>
                  </li>
                </ul>
              {% endif %}
              </dd>
              <dt class="dt-annotation">
              {% if profile_user == request.user %}
                Dernières annotation sur lesquelles j'ai commenté (sans proposer de révision) :
              {% else %}
                Dernières annotations sur lesquelles {{profile_user.username}} a commenté (sans proposer de révision) :
              {% endif %}
              </dt>
              <dd>
              {% if not user_commented_annotations %}
                 <h4 class="no-user-annotation"><small>Aucune annotation à afficher</small></h4>
              {% else %}
                <ul class="list-unstyled">
                  {% for annotation_data in user_commented_annotations %}
                    {% include "partials/user_pages/annotations_commented_panel.html" with annotation_data=annotation_data user=profile_user %}
                  {% endfor %}
                  <li>
                    <a class="btn btn-default btn-sm" href="{% url 'user_commented' profile_user.id %}"><span class="glyphicon glyphicon-list" aria-hidden="true"></span> Voir toutes les annotations commentées</a>
                  </li>
                </ul>
              {% endif %}
              </dd>
            </dl>
          </div>
        </div>
      </div>
    </div>
    {% if profile_user.profile.managed_collections %}
    <div class="col-md-12">
      <div class="panel panel-default text-center" style="padding: 10px;">
        <h2><small>Administration de Fonds:</small></h2>
        {% for collection in profile_user.profile.managed_collections.all %}
        <h3>{{collection.verbose_name}}</h3>
        <div>
          <a href="{% url 'user_admin_panel' profile_user.id collection.name %}" class="btn btn-default text-center">Tableau de bord</a>
        </div>
        {% endfor %}
      </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 %}
