aboutsummaryrefslogtreecommitdiff
path: root/app/views/javascript/actualize.phtml
diff options
context:
space:
mode:
Diffstat (limited to 'app/views/javascript/actualize.phtml')
-rw-r--r--app/views/javascript/actualize.phtml55
1 files changed, 34 insertions, 21 deletions
diff --git a/app/views/javascript/actualize.phtml b/app/views/javascript/actualize.phtml
index 1f6072c29..6a92e5642 100644
--- a/app/views/javascript/actualize.phtml
+++ b/app/views/javascript/actualize.phtml
@@ -1,14 +1,17 @@
"use strict";
-var feeds = [];
-<?php foreach ($this->feeds as $feed) { ?>
-feeds.push("<?php echo Minz_Url::display (array ('c' => 'feed', 'a' => 'actualize', 'params' => array ('id' => $feed->id (), 'ajax' => '1')), 'php'); ?>");
-<?php } ?>
+var feeds = [<?php
+ foreach ($this->feeds as $feed) {
+ echo "'", Minz_Url::display(array('c' => 'feed', 'a' => 'actualize', 'params' => array('id' => $feed->id(), 'ajax' => '1')), 'php'), "',\n";
+ }
+ ?>],
+ feed_processed = 0,
+ feed_count = feeds.length;
function initProgressBar(init) {
if (init) {
- $("body").after("\<div id=\"actualizeProgress\" class=\"actualizeProgress\">\
- <?php echo Minz_Translate::t ('refresh'); ?> <span class=\"progress\">0 / " + feeds.length + "</span><br />\
- <progress id=\"actualizeProgressBar\" value=\"0\" max=\"" + feeds.length + "\"></progress>\
+ $("body").after("\<div id=\"actualizeProgress\" class=\"notification good\">\
+ <?php echo Minz_Translate::t ('refresh'); ?> <span class=\"progress\">0 / " + feed_count + "</span><br />\
+ <progress id=\"actualizeProgressBar\" value=\"0\" max=\"" + feed_count + "\"></progress>\
</div>");
} else {
window.location.reload();
@@ -16,27 +19,37 @@ function initProgressBar(init) {
}
function updateProgressBar(i) {
$("#actualizeProgressBar").val(i);
- $("#actualizeProgress .progress").html(i + " / " + feeds.length);
+ $("#actualizeProgress .progress").html(i + " / " + feed_count);
}
function updateFeeds() {
- if (feeds.length === 0) {
+ if (feed_count === 0) {
+ openNotification("<?php echo Minz_Translate::t ('no_feed_to_refresh'); ?>", "good");
return;
}
initProgressBar(true);
- var i = 0;
- for (var f in feeds) {
- $.ajax({
- type: 'POST',
- url: feeds[f],
- }).done(function (data) {
- i++;
- updateProgressBar(i);
+ for (var i = 0; i < 10; i++) {
+ updateFeed();
+ }
+}
- if (i === feeds.length) {
- initProgressBar(false);
- }
- });
+function updateFeed() {
+ var feed = feeds.pop();
+ if (feed == undefined) {
+ return;
}
+ $.ajax({
+ type: 'POST',
+ url: feed,
+ }).complete(function (data) {
+ feed_processed++;
+ updateProgressBar(feed_processed);
+
+ if (feed_processed === feed_count) {
+ initProgressBar(false);
+ } else {
+ updateFeed();
+ }
+ });
}