summaryrefslogtreecommitdiffstats
path: root/hyperkitty
diff options
context:
space:
mode:
Diffstat (limited to 'hyperkitty')
-rw-r--r--hyperkitty/static/js/hyperkitty.js104
-rw-r--r--hyperkitty/templates/base.html1
-rw-r--r--hyperkitty/templates/message.html57
-rw-r--r--hyperkitty/templates/messages/message.html6
-rw-r--r--hyperkitty/templates/thread.html76
-rw-r--r--hyperkitty/templates/threads/right_col.html3
-rw-r--r--hyperkitty/views/message.py4
-rw-r--r--hyperkitty/views/thread.py4
8 files changed, 117 insertions, 138 deletions
diff --git a/hyperkitty/static/js/hyperkitty.js b/hyperkitty/static/js/hyperkitty.js
new file mode 100644
index 0000000..238954d
--- /dev/null
+++ b/hyperkitty/static/js/hyperkitty.js
@@ -0,0 +1,104 @@
+/*
+ * -*- coding: utf-8 -*-
+ * Copyright (C) 1998-2012 by the Free Software Foundation, Inc.
+ *
+ * This file is part of HyperKitty.
+ *
+ * HyperKitty is free software: you can redistribute it and/or modify it under
+ * the terms of the GNU General Public License as published by the Free
+ * Software Foundation, either version 3 of the License, or (at your option)
+ * any later version.
+ *
+ * HyperKitty is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+ * more details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * HyperKitty. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * Author: Aurelien Bompard <abompard@fedoraproject.org>
+ */
+
+
+
+/*
+ * Voting
+ */
+
+function vote(elem, value) {
+ var form_data = $(elem).parent("form").serializeArray();
+ var data = {};
+ for (input in form_data) {
+ data[form_data[input].name] = form_data[input].value;
+ }
+ data['vote'] = value;
+ $.ajax({
+ type: "POST",
+ url: $(elem).parent("form").attr("action"),
+ data: data,
+ success: function(response) {
+ // @TODO : Remove this reload and update the count using the AJAX response
+ location.reload();
+ },
+ error: function(jqXHR, textStatus, errorThrown) {
+ // You must be authenticated to do that
+ if (jqXHR.status === 403) {
+ alert(jqXHR.responseText);
+ }
+ }
+ });
+}
+
+
+function setup_vote() {
+ $(".voteup").click(function() { vote(this, 1); return false; });
+ $(".votedown").click(function() { vote(this, -1); return false; });
+}
+
+
+/*
+ * Tagging
+ */
+
+function setup_add_tag() {
+ $("#add_tag_form").submit( function () {
+ $.ajax({
+ type: "POST",
+ data : $(this).serialize(),
+ url: $(this).attr("action"),
+ success: function(data){
+ // @TODO : Remove this reload and update the tag list using the AJAX response
+ //location.reload();
+ },
+ error: function(jqXHR, textStatus, errorThrown) {
+ // You must be authenticated to do that
+ if (jqXHR.status === 403) {
+ alert(jqXHR.responseText);
+ }
+ }
+ });
+ return false;
+ });
+}
+
+
+
+function setup_attachments() {
+ $("ul.email_info li.attachments ul.attachments-list").hide();
+ $("ul.email_info li.attachments > a").click(function() {
+ $(this).next("ul").fadeToggle('fast');
+ });
+}
+
+
+
+/*
+ * General
+ */
+
+$(document).ready(function() {
+ setup_vote();
+ setup_attachments();
+ setup_add_tag();
+});
diff --git a/hyperkitty/templates/base.html b/hyperkitty/templates/base.html
index 1900dbb..1a69fae 100644
--- a/hyperkitty/templates/base.html
+++ b/hyperkitty/templates/base.html
@@ -55,6 +55,7 @@
{% block footer %} {% endblock %}
<script src="{{ STATIC_URL }}js/libs/jquery-1.7.1.min.js"></script>
+ <script src="{{ STATIC_URL }}js/hyperkitty.js"></script>
{% block additionaljs %} {% endblock %}
</body>
diff --git a/hyperkitty/templates/message.html b/hyperkitty/templates/message.html
index 5ae2fb1..25983ec 100644
--- a/hyperkitty/templates/message.html
+++ b/hyperkitty/templates/message.html
@@ -17,60 +17,3 @@
</section>
{% endblock %}
-
-{% block additionaljs %}
-<script type="text/javascript">
- $(document).ready(function() {
- $(".voteup").click(function() {
- // @TODO: Extract the message id from the HTML DOM element instead of hard coding it in Javascript.
- message_id = this.parentElement.getAttribute('messageid');
- {% if user.is_authenticated %}
- $.ajax({
- type : "POST",
- url : "{% url message_vote mlist_fqdn=list_address %}",
- data : {
- vote : 1,
- messageid : message_id,
- list : "{{list_address}}",
- csrfmiddlewaretoken : '{{ csrf_token }}'
- },
- success : function(response) {
- console.log(response);
- location.reload();
- }
- });
- return false;
- {% else %}
- alert('You need to login in order to vote');
- {% endif %}
- });
-
- $(".votedown").click(function() {
- message_id = this.parentElement.getAttribute('messageid');
- {% if user.is_authenticated %}
- $.ajax({
- type : "POST",
- url : '{% url message_vote mlist_fqdn=list_address %}',
- data : {
- vote : -1,
- messageid : message_id,
- list : "{{list_address}}",
- csrfmiddlewaretoken : '{{ csrf_token }}'
- },
- success : function(response) {
- console.log(response);
- // @TODO : Remove this reload and update count using AJAX
- location.reload();
- }
- });
- return false;
- {% else %}
- alert('You need to login in order to vote');
- {% endif %}
-
- });
-
- });
-</script>
-
-{% endblock %}
diff --git a/hyperkitty/templates/messages/message.html b/hyperkitty/templates/messages/message.html
index 9fec43d..c69c2ff 100644
--- a/hyperkitty/templates/messages/message.html
+++ b/hyperkitty/templates/messages/message.html
@@ -43,8 +43,11 @@
</ul>
{% endif %}
-<ul class="email_info inline" messageid="{{email.message_id_hash}}">
+<ul class="email_info inline">
{% if use_mockups %}
+ <form method="post" action="{% url message_vote mlist_fqdn=list_address %}">
+ <input type="hidden" name="messageid" value="{{email.message_id_hash}}" />
+ {% csrf_token %}
<li class="likestatus {{email.likestatus}}">
+{{email.likes}}/-{{email.dislikes}}
</li>
@@ -54,6 +57,7 @@
<li class="votedown">
<a class="youdislike" href="#dislike">Dislike</a>
</li>
+ </form>
{% endif %}
{% if not unfolded and email.attachments|count %}
<li class="attachments">
diff --git a/hyperkitty/templates/thread.html b/hyperkitty/templates/thread.html
index 9e1333f..e2a0524 100644
--- a/hyperkitty/templates/thread.html
+++ b/hyperkitty/templates/thread.html
@@ -51,80 +51,4 @@
});
</script>
-<script type="text/javascript">
- $(document).ready(function() {
- $(".voteup").click(function() {
- // @TODO: Extract the message id from the HTML DOM element instead of hard coding it in Javascript.
- message_id = this.parentElement.getAttribute('messageid');
- {% if user.is_authenticated %}
- $.ajax({
- type : "POST",
- url : '{% url message_vote mlist_fqdn=list_address %}',
- data : {
- vote : 1,
- messageid : message_id,
- list : "{{list_address}}",
- csrfmiddlewaretoken : '{{ csrf_token }}'
- },
- success : function(response) {
- console.log(response);
- location.reload();
- }
- });
- return false;
- {% else %}
- alert('You need to login in order to vote');
- {% endif %}
- });
-
- $(".votedown").click(function() {
- message_id = this.parentElement.getAttribute('messageid');
- {% if user.is_authenticated %}
- $.ajax({
- type : "POST",
- url : '{% url message_vote mlist_fqdn=list_address %}',
- data : {
- vote : -1,
- messageid : message_id,
- list : "{{list_address}}",
- csrfmiddlewaretoken : '{{ csrf_token }}'
- },
- success : function(response) {
- console.log(response);
- // @TODO : Remove this reload and update count using AJAX
- location.reload();
- }
- });
- return false;
- {% else %}
- alert('You need to login in order to vote');
- {% endif %}
-
- });
-
- $("#add_tag_form").submit( function () {
-
- {% if user.is_authenticated %}
- $.ajax({
- type: "POST",
- data : $(this).serialize(),
- url: "{% url add_tag mlist_fqdn=list_address, email_id=threadid %}",
- success: function(data){
- console.log('Tag is added successfully');
- location.reload();
- }
- });
- return false;
- {% else %}
- alert('You need to login in order to add tag');
- {% endif %}
- });
-
- $("ul.email_info li.attachments ul.attachments-list").hide();
- $("ul.email_info li.attachments > a").click(function() {
- $(this).next("ul").fadeToggle('fast');
- });
-
- });
-</script>
{% endblock %}
diff --git a/hyperkitty/templates/threads/right_col.html b/hyperkitty/templates/threads/right_col.html
index dcf00e7..cc486b1 100644
--- a/hyperkitty/templates/threads/right_col.html
+++ b/hyperkitty/templates/threads/right_col.html
@@ -42,7 +42,8 @@
{% endif %}
</div>
<div id="add_tag">
- <form id="add_tag_form" name="addtag" action="{% url add_tag mlist_fqdn=list_address, email_id=threadid %}" method="post">
+ <form id="add_tag_form" name="addtag" method="post"
+ action="{% url add_tag mlist_fqdn=list_address, email_id=threadid %}">
{% csrf_token %}
{{ addtag_form.as_p }}
</form>
diff --git a/hyperkitty/views/message.py b/hyperkitty/views/message.py
index d6676d8..5ed17c2 100644
--- a/hyperkitty/views/message.py
+++ b/hyperkitty/views/message.py
@@ -116,11 +116,11 @@ def attachment(request, mlist_fqdn, hashid, counter, filename):
return response
-@login_required
def vote(request, mlist_fqdn):
""" Add a rating to a given message identified by messageid. """
if not request.user.is_authenticated():
- return redirect('user_login')
+ return HttpResponse('You must be logged in to vote',
+ content_type="text/plain", status=403)
value = request.POST['vote']
hashid = request.POST['hashid']
diff --git a/hyperkitty/views/thread.py b/hyperkitty/views/thread.py
index 4edd7f7..ec5a60f 100644
--- a/hyperkitty/views/thread.py
+++ b/hyperkitty/views/thread.py
@@ -124,9 +124,11 @@ def thread_index(request, mlist_fqdn, threadid):
return HttpResponse(t.render(c))
-@login_required
def add_tag(request, mlist_fqdn, email_id):
""" Add a tag to a given thread. """
+ if not request.user.is_authenticated():
+ return HttpResponse('You must be logged in to add a tag',
+ content_type="text/plain", status=403)
if request.method == 'POST':
form = AddTagForm(request.POST)