From 6ea042ab3c6310bb87cb01041656e6928a163a5f Mon Sep 17 00:00:00 2001 From: Aurélien Bompard Date: Mon, 10 Dec 2012 12:25:38 +0100 Subject: Don't reload the page when adding tags or liking stuff --- hyperkitty/static/js/hyperkitty.js | 20 +++++------ hyperkitty/templates/messages/message.html | 6 ++-- hyperkitty/templates/month_view.html | 8 +++-- hyperkitty/templates/threads/add_tag_form.html | 2 +- hyperkitty/templates/threads/right_col.html | 13 ++------ hyperkitty/templates/threads/tags.html | 13 ++++++++ hyperkitty/tests/test_views.py | 4 +-- hyperkitty/urls.py | 2 +- hyperkitty/views/message.py | 29 +++++++++++----- hyperkitty/views/thread.py | 46 +++++++++++++++----------- 10 files changed, 85 insertions(+), 58 deletions(-) create mode 100644 hyperkitty/templates/threads/tags.html diff --git a/hyperkitty/static/js/hyperkitty.js b/hyperkitty/static/js/hyperkitty.js index 238954d..2b6a818 100644 --- a/hyperkitty/static/js/hyperkitty.js +++ b/hyperkitty/static/js/hyperkitty.js @@ -36,13 +36,15 @@ function vote(elem, value) { $.ajax({ type: "POST", url: $(elem).parent("form").attr("action"), + dataType: "json", data: data, success: function(response) { - // @TODO : Remove this reload and update the count using the AJAX response - location.reload(); + var likestatus = $(elem).parent("form").find(".likestatus"); + likestatus.find(".likecount").html(response.like); + likestatus.find(".dislikecount").html(response.dislike); }, error: function(jqXHR, textStatus, errorThrown) { - // You must be authenticated to do that + // authentication or double-vote if (jqXHR.status === 403) { alert(jqXHR.responseText); } @@ -65,17 +67,15 @@ function setup_add_tag() { $("#add_tag_form").submit( function () { $.ajax({ type: "POST", + dataType: "json", 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(); + success: function(data) { + $("#tags").html(data.html); }, error: function(jqXHR, textStatus, errorThrown) { - // You must be authenticated to do that - if (jqXHR.status === 403) { - alert(jqXHR.responseText); - } + // authentication and invalid data + alert(jqXHR.responseText); } }); return false; diff --git a/hyperkitty/templates/messages/message.html b/hyperkitty/templates/messages/message.html index c69c2ff..7281f7d 100644 --- a/hyperkitty/templates/messages/message.html +++ b/hyperkitty/templates/messages/message.html @@ -46,10 +46,10 @@ {% if use_mockups %} -