message-thread.html 5.17 KB
{% extends "base.html" %}
{% load i18n tz superarchives %}

{% trans "Anonymous" as anonymous %}

{% block title %}{{ first_msg.subject_clean }}{% endblock %}

{% block head_js %}

<script>
  function vote_done_callback(step) {
    console.debug('(un)vote successfuly (step ' + step + ')');
    var $btn = $(this);
    var step;

    if ($btn.hasClass('btn-default')) {
      step = 1;
    } else {
      step = -1;
    }

    $btn.prev('.vote-count').text(function(self, count) {
        return parseInt(count) + step;
    });

    $btn.toggleClass('btn-success');
    $btn.toggleClass('btn-default');
    $btn.button('reset')
  }

  function vote_fail_callback(jqXHR, textStatus, errorThrown) {
    var msg;

    if (jqXHR.status === 403) {
      msg = " {% trans 'You must login before voting.' %}"

      $('#alert-js #alert-message').html(msg);
      $('#alert-js').show();
      scroll(0, 0);
    }

  }

  function vote(event) {
    var $ajax;
    var $btn = $(this);
    var $msg = $(this).parents('.email-message');

    var method;
    var csrftoken = $.cookie('csrftoken');
    var msg_id = $msg.attr('id').split('-')[1];

    if($btn.hasClass('btn-default')) {
        method = 'PUT';
    } else {
        method = 'DELETE';
    }

    console.debug('trying to vote');
    $btn.button('loading');
    $ajax = $.ajax({
      url: "/archives/message/" + msg_id + "/vote",
      type: method,
      context: $btn.get(0),
      beforeSend: function(xhr, settings) {
        xhr.setRequestHeader("X-CSRFToken", csrftoken);
      }
    });
    $ajax.done(vote_done_callback);
    $ajax.fail(vote_fail_callback);
  }

  function scrollToAnchor(aid){
    var aTag = $(aid);
    console.log(aTag);
    $('html, body').animate({scrollTop: aTag.offset().top}, 800);
  }

  {% if user.is_active %}
  function focus_reply(event) {
    scrollToAnchor('#msg-reply');
    $('textarea', '#msg-reply').focus();
  }
  {% endif %}

  // Binding functions
  $(function() {
    $(".panel-heading").on('click', function(event) {
        var $target = $(event.target);
        // Do not collapse the the message if the clicked element (target)
        //  is a button or a link
        if($target.hasClass('btn') || $target.is('a') || $target.parent().is('a')) {
            return;
        }

        $(this).next('.panel-collapse').collapse('toggle');
    });

    $('.vote.btn', this).on('click', vote);
    {% if user.is_active %}
      $('.reply.btn', this).on('click', focus_reply);
    {% endif %}

    $('.message-link').popover({'placement': 'right'});
  });

</script>

{% endblock %}

{% block main-content %}
<div class="row">

  <div class="col-lg-12">
    <h2>{{ first_msg.subject_clean }}</h2>
    <hr />
  </div>

  <div class="col-lg-9 col-md-9 col-sm-12">
    <ul class="unstyled-list">
    {% for email in emails %}
      {% include "superarchives/includes/message.html" with userprofile=email.from_address.user emailaddress=email.from_address fullname=email.from_address.get_full_name_or_anonymous %}
    {% endfor %}

    {% if user.is_active %}
      {% include "superarchives/includes/message.html" with userprofile=user emailaddress=user.email fullname=user.get_full_name reply=True %}
    {% endif %}
    </ul>
  </div>

  <div class="col-lg-3 col-md-3 hidden-sm hidden-xs">
    <h4><strong>{% trans "Order by" %}:</strong></h4>
    <ul class="unstyled-list">
      <li>
        <span class="glyphicon glyphicon-chevron-right"></span>
        <a href="{% append_to_get order='voted' %}">{% trans "Votes" %}</a>
      </li>
      <li>
        <span class="glyphicon glyphicon-chevron-right"></span>
        <a href="{% append_to_get order='date' %}">{% trans "Date" %}</a>
      </li>
    </ul>

    {% if thread.get_related %}
    <h4><strong>{% trans "Related:" %}</strong></h4>
    <ul class="unstyled-list">
      {% for similar in thread.get_related|slice:":10" %}
      <li>
        <span class="label label-primary label-small">{{ similar.tag }}</span>
        <a href="{{ similar.url }}">{{ similar.title|truncatechars:50 }}</a>
      </li>
      {% endfor %}
    </ul>
    {% endif %}

    <h4><strong>{% trans "Statistics:" %}</strong></h4>
    <ul class="unstyled-list">
      <li>
        <span class="glyphicon glyphicon-chevron-right"></span>
        {% trans "started at" %}
        <h5>{{ first_msg.received_time|localtime|timesince }} {% trans "ago" %}</h5>
      </li>

      <li>
        <span class="glyphicon glyphicon-chevron-right"></span>
        {% trans "viewed" %}
        <h5>{{ pagehits }} {% trans "times" %}</h5>
      </li>
      <li>
        <span class="glyphicon glyphicon-chevron-right"></span>
        {% trans "answered" %}
        <h5>{{ emails|length }} {% trans "times" %}</h5>
      </li>
      <li>
        <span class="glyphicon glyphicon-chevron-right"></span>
        {% trans "voted" %}
        <h5>{{ total_votes }} {% trans "times" %}</h5>
      </li>
    </ul>

    {% if thread.keyword_set.count %}
    <h4><strong>{% trans "Tags:" %}</strong></h4>
    <div class="tag-cloud">
      {% for keyword in thread.keyword_set.all %}
        <a class="tag size-{{ keyword.weight }}" href="{% url 'haystack_search' %}?q={{ keyword }}">{{ keyword|escape }}</a>
      {% endfor %}
    </div>
    {% endif %}

  </div>

</div>
{% endblock %}