1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
{% extends "base.html" %}
{% load i18n append_to_get gravatar %}
{% trans "Anonymous" as anonymous %}
{% block head_js %}
<script>
function vote_done_callback(msg_id, step) {
console.debug('(un)vote successfuly (step ' + step + ')');
var $msg = $('#msg-' + msg_id)
$('.vote-count', $msg).text(function(self, count) {
return parseInt(count) + step;
});
if (step == -1) {
var $btn = $('.vote.btn-success', $msg);
$btn.unbind('click');
$btn.bind('click', function() {
vote(msg_id);
});
} else {
var $btn = $('.vote.btn-default', $msg);
$btn.unbind('click');
$btn.bind('click', function() {
unvote(msg_id);
});
}
$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.' %}"
} else {
return;
}
$('#alert-js #alert-message').html(msg);
$('#alert-js').show();
scroll(0, 0);
}
function get_vote_ajax_dict(msg_id, method) {
var csrftoken = $.cookie('csrftoken');
$('#msg-' + msg_id + ' .vote.btn-success').button('loading');
return {
url: "/api/message/" + msg_id + "/vote",
type: method,
beforeSend: function(xhr, settings) {
xhr.setRequestHeader("X-CSRFToken", csrftoken);
}
}
}
function vote(msg_id) {
console.debug('trying to vote');
$.ajax(get_vote_ajax_dict(msg_id, 'PUT'))
.done(function(){
vote_done_callback(msg_id, 1);
})
.fail(vote_fail_callback);
}
function unvote(msg_id) {
console.debug('trying to remove vote');
$.ajax(get_vote_ajax_dict(msg_id, 'DELETE'))
.done(function(){
vote_done_callback(msg_id, -1);
})
.fail(vote_fail_callback);
}
// Binding functions
$(function() {
console.debug('binding vote function to btns');
$('.email-message').each(function() {
var msg_id = this.getAttribute('id').split('-')[1];
$('.vote.btn-default', this).bind('click', function() {
vote(msg_id);
});
$('.vote.btn-success', this).bind('click', function() {
unvote(msg_id);
});
});
});
</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-10 col-md-10 col-sm-12">
<ul class="unstyled-list">
{% for email in emails %}
{% with email.from_address.user.get_absolute_url as profile_link %}
<li>
{% spaceless %}
<div class="email-message" id="msg-{{ email.id }}">
<div class="panel panel-default">
<div class="panel-heading clearfix">
<div class="col-lg-6 col-md-6 col-sm-6">
{% if profile_link %}
<a href="{{ profile_link }}">
{% endif %}
{% gravatar email.from_address 34 %}
<strong class="user-fullname">{{ email.from_address.get_full_name_or_anonymous }}</strong>
{% if profile_link %}
</a>
{% endif %}
</div>
<div class="col-lg-6 col-md-6 col-sm-6">
<div class="pull-right text-right">
<span class="date">
{{ email.received_time|date:'DATETIME_FORMAT' }}
</span>
<div class="btn-group">
<button class="btn btn-default vote-count disabled">
{{ email.votes_count }}
</button>
{% if user in email.vote_list %}
<button class="btn btn-success vote" data-loading-text="...">
{% else %}
<button class="btn btn-default vote" data-loading-text="...">
{% endif %}
<span class="glyphicon glyphicon-thumbs-up"></span>
</button>
</div>
</div>
</div>
</div>
<div class="panel-body">
<pre>{{ email.body }}</pre>
</div>
</div>
</div>
{% endspaceless %}
</li>
{% endwith %}
{% endfor %}
</ul>
</div>
<div class="col-lg-2 col-md-2 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>
<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|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>
</div>
</div>
{% endblock %}