summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Marien Fressinaud <dev@marienfressinaud.fr> 2014-02-13 19:51:38 +0100
committerGravatar Marien Fressinaud <dev@marienfressinaud.fr> 2014-02-13 19:51:38 +0100
commitc33b13809ef4e1941d3655479db8c5fcf5731013 (patch)
treedc1e3a2185ff306a22bd3fc86feda2000d1e0357
parent9f6fa5f7c6e476aceb8a1979cd62f6fbf53b6757 (diff)
Add a "locker" to mark_read action
In order to prevent multiple requests while another one is still pending. It is based on a list of pending actions (in fact, in a list of pending feeds) Fix #423
-rw-r--r--p/scripts/main.js20
1 files changed, 16 insertions, 4 deletions
diff --git a/p/scripts/main.js b/p/scripts/main.js
index 8cda62d26..e94df2a39 100644
--- a/p/scripts/main.js
+++ b/p/scripts/main.js
@@ -1,6 +1,7 @@
"use strict";
var $stream = null,
- isCollapsed = true;
+ isCollapsed = true,
+ pending_feed = [];
function is_normal_mode() {
return $stream.hasClass('normal');
@@ -107,7 +108,8 @@ function incUnreadsFeed(article, feed_id, nb) {
}
function mark_read(active, only_not_read) {
- if (active.length === 0 || (only_not_read === true && !active.hasClass("not_read"))) {
+ if (active.length === 0 ||
+ (only_not_read === true && !active.hasClass("not_read"))) {
return false;
}
@@ -116,6 +118,16 @@ function mark_read(active, only_not_read) {
return false;
}
+ var feed_url = active.find(".website>a").attr("href"),
+ feed_id = feed_url.substr(feed_url.lastIndexOf('f_')),
+ index_pending = pending_feed.indexOf(feed_id);
+
+ if (index_pending !== -1) {
+ return false;
+ }
+
+ pending_feed.push(feed_id);
+
$.ajax({
type: 'POST',
url: url,
@@ -132,9 +144,9 @@ function mark_read(active, only_not_read) {
}
$r.find('.icon').replaceWith(data.icon);
- var feed_url = active.find(".website>a").attr("href"),
- feed_id = feed_url.substr(feed_url.lastIndexOf('f_'));
incUnreadsFeed(active, feed_id, inc);
+
+ pending_feed.splice(index_pending, 1);
});
}