aboutsummaryrefslogtreecommitdiff
path: root/app/views/javascript/actualize.phtml
diff options
context:
space:
mode:
authorGravatar Marien Fressinaud <dev@marienfressinaud.fr> 2014-10-09 15:53:10 +0200
committerGravatar Marien Fressinaud <dev@marienfressinaud.fr> 2014-10-09 15:53:10 +0200
commitf97d4b3b6cca4a55636bbd50158f3c57666b0f08 (patch)
tree3ca9dd42155228292f0842d65b9b6d90e9140639 /app/views/javascript/actualize.phtml
parente51ceb6812e3736aa9b9ce1f2d5181f5b4b6aaa3 (diff)
parent444b1552364b39761c3278c7da5152fd3998f216 (diff)
Merge branch 'master' into hotfixes
Diffstat (limited to 'app/views/javascript/actualize.phtml')
-rw-r--r--app/views/javascript/actualize.phtml75
1 files changed, 43 insertions, 32 deletions
diff --git a/app/views/javascript/actualize.phtml b/app/views/javascript/actualize.phtml
index fa6e67ddb..74cef4998 100644
--- a/app/views/javascript/actualize.phtml
+++ b/app/views/javascript/actualize.phtml
@@ -1,45 +1,56 @@
-var feeds = new Array ();
-<?php foreach ($this->feeds as $feed) { ?>
-feeds.push ("<?php echo Url::display (array ('c' => 'feed', 'a' => 'actualize', 'params' => array ('id' => $feed->id (), 'ajax' => '1')), 'php'); ?>");
-<?php } ?>
+"use strict";
+var feeds = [<?php foreach ($this->feeds as $feed) { ?>{<?php
+ ?>url: "<?php echo Minz_Url::display(array('c' => 'feed', 'a' => 'actualize', 'params' => array('id' => $feed->id(), 'ajax' => '1')), 'php'); ?>",<?php
+ ?>title: "<?php echo $feed->name(); ?>"<?php
+?>},<?php } ?>],
+ feed_processed = 0,
+ feed_count = feeds.length;
-function initProgressBar (init) {
+function initProgressBar(init) {
if (init) {
- $("body").after ("\<div id=\"actualizeProgress\" class=\"actualizeProgress\">\
- <?php echo 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 _t('refresh'); ?><br /><span class=\"title\">/</span><br />\
+ <span class=\"progress\">0 / " + feed_count + "</span>\
</div>");
} else {
- window.location.reload ();
+ window.location.reload();
}
}
-function updateProgressBar (i) {
- $("#actualizeProgressBar").val(i);
- $("#actualizeProgress .progress").html (i + " / " + feeds.length);
+function updateProgressBar(i, title_feed) {
+ $("#actualizeProgress .progress").html(i + " / " + feed_count);
+ $("#actualizeProgress .title").html(title_feed);
}
-function updateFeeds () {
- initProgressBar (true);
-
- var i = 0;
- for (var f in feeds) {
- $.ajax ({
- type: 'POST',
- url: feeds[f],
- }).done (function (data) {
- i++;
- updateProgressBar (i);
+function updateFeeds() {
+ if (feed_count === 0) {
+ openNotification("<?php echo _t('no_feed_to_refresh'); ?>", "good");
+ ajax_loading = false;
+ return;
+ }
+ initProgressBar(true);
- if (i == feeds.length) {
- initProgressBar (false);
- }
- });
+ for (var i = 0; i < 10; i++) {
+ updateFeed();
}
}
-$(document).ready (function () {
- $("#actualize").click (function () {
- updateFeeds ();
- return false;
+function updateFeed() {
+ var feed = feeds.pop();
+ if (feed == undefined) {
+ return;
+ }
+
+ $.ajax({
+ type: 'POST',
+ url: feed['url'],
+ }).complete(function (data) {
+ feed_processed++;
+ updateProgressBar(feed_processed, feed['title']);
+
+ if (feed_processed === feed_count) {
+ initProgressBar(false);
+ } else {
+ updateFeed();
+ }
});
-});
+}