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