Improve mark items as read
This commit is contained in:
parent
f03e52ab04
commit
c9eb6a47a6
@ -27,13 +27,14 @@
|
||||
request.send();
|
||||
}
|
||||
|
||||
function mark_all_as_read()
|
||||
|
||||
function mark_items_as_read()
|
||||
{
|
||||
var $articles = document.getElementsByTagName("article");
|
||||
var articles = document.getElementsByTagName("article");
|
||||
var idlist = [];
|
||||
for (var i=0;i<$articles.length;i++)
|
||||
{
|
||||
idlist.push($articles[i].getAttribute("data-item-id"));
|
||||
|
||||
for (var i = 0, ilen = articles.length; i < ilen; i++) {
|
||||
idlist.push(articles[i].getAttribute("data-item-id"));
|
||||
}
|
||||
|
||||
var request = new XMLHttpRequest();
|
||||
@ -43,10 +44,11 @@
|
||||
window.location.href = "?action=unread";
|
||||
};
|
||||
|
||||
request.open("POST", "?action=mark-all-read", true);
|
||||
request.open("POST", "?action=mark-items-as-read", true);
|
||||
request.send(JSON.stringify(idlist));
|
||||
}
|
||||
|
||||
|
||||
function mark_as_read(item_id)
|
||||
{
|
||||
var request = new XMLHttpRequest();
|
||||
@ -436,7 +438,7 @@
|
||||
break;
|
||||
case 'mark-all-read':
|
||||
e.preventDefault();
|
||||
mark_all_as_read();
|
||||
mark_items_as_read();
|
||||
break;
|
||||
case 'original-link':
|
||||
var item_id = e.target.getAttribute("data-item-id");
|
||||
|
10
index.php
10
index.php
@ -332,17 +332,15 @@ 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);
|
||||
}
|
||||
// Mark sent items id as read (Ajax request)
|
||||
Router\post_action('mark-items-as-read', function(){
|
||||
|
||||
Model\mark_items_as_read(Request\values());
|
||||
Response\json(array('OK'));
|
||||
});
|
||||
|
||||
|
||||
// Confirmation box to flush history
|
||||
Router\get_action('confirm-flush-history', function() {
|
||||
|
||||
|
14
model.php
14
model.php
@ -515,6 +515,7 @@ function switch_item_status($id)
|
||||
}
|
||||
|
||||
|
||||
// Mark all items as read
|
||||
function mark_as_read()
|
||||
{
|
||||
\PicoTools\singleton('db')
|
||||
@ -524,6 +525,19 @@ function mark_as_read()
|
||||
}
|
||||
|
||||
|
||||
// Mark only specified items as read
|
||||
function mark_items_as_read(array $items_id)
|
||||
{
|
||||
\PicoTools\singleton('db')->startTransaction();
|
||||
|
||||
foreach($items_id as $encoded_id) {
|
||||
set_item_read(decode_item_id($encoded_id));
|
||||
}
|
||||
|
||||
\PicoTools\singleton('db')->closeTransaction();
|
||||
}
|
||||
|
||||
|
||||
function mark_as_removed()
|
||||
{
|
||||
\PicoTools\singleton('db')
|
||||
|
Loading…
Reference in New Issue
Block a user