aboutsummaryrefslogtreecommitdiff
path: root/app/views/javascript/actualize.phtml
blob: 74cef49988ff3291a35f2beb20896385081d04aa (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
"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) {
	if (init) {
		$("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();
	}
}
function updateProgressBar(i, title_feed) {
	$("#actualizeProgress .progress").html(i + " / " + feed_count);
	$("#actualizeProgress .title").html(title_feed);
}

function updateFeeds() {
	if (feed_count === 0) {
		openNotification("<?php echo _t('no_feed_to_refresh'); ?>", "good");
		ajax_loading = false;
		return;
	}
	initProgressBar(true);

	for (var i = 0; i < 10; i++) {
		updateFeed();
	}
}

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();
		}
	});
}