From 66a27f5866dfb54042799676f1e9faacd4c9aba0 Mon Sep 17 00:00:00 2001 From: doubleface Date: Tue, 16 Jul 2013 09:00:14 -0400 Subject: [PATCH] Only mark as read items displayed on the page --- assets/js/app.js | 23 +++++++++++++++++++++++ index.php | 10 ++++++++++ templates/unread_items.php | 6 +++++- 3 files changed, 38 insertions(+), 1 deletion(-) diff --git a/assets/js/app.js b/assets/js/app.js index 2b34bd3..cfd0509 100644 --- a/assets/js/app.js +++ b/assets/js/app.js @@ -27,6 +27,25 @@ request.send(); } + function mark_all_as_read() + { + var $articles = document.getElementsByTagName("article"); + var idlist = []; + for (var i=0;i<$articles.length;i++) + { + idlist.push($articles[i].getAttribute("data-item-id")); + } + + var request = new XMLHttpRequest(); + + request.onload = function() { + + window.location.href = "?action=unread"; + }; + + request.open("POST", "?action=mark-all-read", true); + request.send(JSON.stringify(idlist)); + } function mark_as_read(item_id) { @@ -415,6 +434,10 @@ var item_id = e.target.getAttribute("data-item-id"); mark_as_unread(item_id); break; + case 'mark-all-read': + e.preventDefault(); + mark_all_as_read(); + break; case 'original-link': var item_id = e.target.getAttribute("data-item-id"); mark_as_read(item_id); diff --git a/index.php b/index.php index d415c94..71ad6ad 100644 --- a/index.php +++ b/index.php @@ -331,6 +331,16 @@ Router\get_action('mark-as-read', function() { Response\redirect('?action=unread'); }); +Router\post_action('mark-all-read', function(){ + + $values = Request\values(); + foreach($values as $value) { + $id = Model\decode_item_id($value); + Model\set_item_read($id); + } + + Response\json(array('OK')); +}); // Confirmation box to flush history Router\get_action('confirm-flush-history', function() { diff --git a/templates/unread_items.php b/templates/unread_items.php index ad67ae7..6b07bd3 100644 --- a/templates/unread_items.php +++ b/templates/unread_items.php @@ -7,7 +7,11 @@