From 2eb4aadf4c1437416327896453fa4ad6ea0fbd40 Mon Sep 17 00:00:00 2001 From: Cédric Bonhomme Date: Sun, 29 Jun 2014 11:59:45 +0200 Subject: Improved read/unread JS function. --- pyaggr3g470r/static/js/articles.js | 17 +++++++++++++++-- pyaggr3g470r/templates/home.html | 2 +- 2 files changed, 16 insertions(+), 3 deletions(-) (limited to 'pyaggr3g470r') diff --git a/pyaggr3g470r/static/js/articles.js b/pyaggr3g470r/static/js/articles.js index e62ca360..990f293c 100644 --- a/pyaggr3g470r/static/js/articles.js +++ b/pyaggr3g470r/static/js/articles.js @@ -25,19 +25,32 @@ if (typeof jQuery === 'undefined') { throw new Error('Requires jQuery') } // Mark an article as read or unread. $('.readed').on('click', function() { var article_id = $(this).parent().parent().parent().attr("data-article"); + var filter = $('#filters').attr("data-filter"); var data; if ($(this).hasClass("glyphicon-unchecked")) { data = JSON.stringify({ readed: false }) + if (filter == "read") { + $(this).parent().parent().parent().remove(); + } + else { + // here, filter == "all" $(this).removeClass('glyphicon-unchecked').addClass('glyphicon-check'); + } } else { data = JSON.stringify({ readed: true }) - $(this).removeClass('glyphicon-check').addClass('glyphicon-unchecked'); + if (filter == "unread") { + $(this).parent().parent().parent().remove(); + } + else { + // here, filter == "all" + $(this).removeClass('glyphicon-check').addClass('glyphicon-unchecked'); + } } // sends the updates to the server @@ -57,7 +70,7 @@ if (typeof jQuery === 'undefined') { throw new Error('Requires jQuery') } } }); }); - + // Like or unlike an article $('.like').on('click', function() { var article_id = $(this).parent().parent().parent().attr("data-article"); diff --git a/pyaggr3g470r/templates/home.html b/pyaggr3g470r/templates/home.html index 4f691a50..2a9fac48 100644 --- a/pyaggr3g470r/templates/home.html +++ b/pyaggr3g470r/templates/home.html @@ -51,7 +51,7 @@

{{ _('Articles') }} ({{ articles.__len__() }})

-
+
{% if filter_ == 'all' %}{% endif %} {{ _('All') }} {% if filter_ == 'all' %}{% endif %} -- cgit