diff options
author | Aurélien Bompard <aurelien@bompard.org> | 2013-01-28 16:48:03 +0100 |
---|---|---|
committer | Aurélien Bompard <aurelien@bompard.org> | 2013-01-28 16:48:03 +0100 |
commit | a4bf2658ce6474c1b8dc2d4f8997d8a4c508a1a3 (patch) | |
tree | f29b7f89faff32d99387da43b6a5825d3f5f0f07 /hyperkitty/static/js/hyperkitty.js | |
parent | fd1616185405265189dc6d5ce70cc6c16456088c (diff) | |
download | hyperkitty-a4bf2658ce6474c1b8dc2d4f8997d8a4c508a1a3.tar.gz hyperkitty-a4bf2658ce6474c1b8dc2d4f8997d8a4c508a1a3.tar.xz hyperkitty-a4bf2658ce6474c1b8dc2d4f8997d8a4c508a1a3.zip |
fix the favorites system
Diffstat (limited to 'hyperkitty/static/js/hyperkitty.js')
-rw-r--r-- | hyperkitty/static/js/hyperkitty.js | 55 |
1 files changed, 53 insertions, 2 deletions
diff --git a/hyperkitty/static/js/hyperkitty.js b/hyperkitty/static/js/hyperkitty.js index 7d7c40b..13d3f8b 100644 --- a/hyperkitty/static/js/hyperkitty.js +++ b/hyperkitty/static/js/hyperkitty.js @@ -53,8 +53,8 @@ function vote(elem, value) { function setup_vote() { - $(".voteup").click(function() { vote(this, 1); return false; }); - $(".votedown").click(function() { vote(this, -1); return false; }); + $(".voteup").click(function(e) { e.preventDefault(); vote(this, 1); }); + $(".votedown").click(function(e) { e.preventDefault(); vote(this, -1); }); } @@ -83,6 +83,56 @@ function setup_add_tag() { /* + * Favorites + */ + +function setup_favorites() { + $(".favorite input[name='action']").bind("change", function() { + // bind the links' visibilities to the hidden input status + var form = $(this).parents("form").first(); + if ($(this).val() === "add") { + form.find("a.saved").hide(); + form.find("a.notsaved").show(); + } else { + form.find("a.notsaved").hide(); + form.find("a.saved").show(); + } + }).trigger("change"); + $(".favorite a").bind("click", function(e) { + e.preventDefault(); + var form = $(this).parents("form").first(); + var action_field = form.find("input[name='action']"); + var form_data = form.serializeArray(); + var data = {}; + for (input in form_data) { + data[form_data[input].name] = form_data[input].value; + } + $.ajax({ + type: "POST", + url: form.attr("action"), + dataType: "text", + data: data, + success: function(response) { + // Update the UI + if (action_field.val() === "add") { + action_field.val("rm"); + } else { + action_field.val("add"); + } + action_field.trigger("change"); + }, + error: function(jqXHR, textStatus, errorThrown) { + if (jqXHR.status === 403) { + alert(jqXHR.responseText); + } + } + }); + }); +} + + + +/* * Recent activity graph */ @@ -179,4 +229,5 @@ $(document).ready(function() { setup_add_tag(); setup_quotes(); setup_months_list(); + setup_favorites(); }); |