aboutsummaryrefslogtreecommitdiff
path: root/app/views/javascript/actualize.phtml
blob: 16188422a4af3e838e43e844b2876d35683c7d4c (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
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 } ?>

function initProgressBar (init) {
	if (init) {
		$("body").after ("\<div id=\"actualizeProgress\" class=\"actualizeProgress\">\
			Actualisation <span class=\"progress\">0 / " + feeds.length + "</span><br />\
			<progress id=\"actualizeProgressBar\" value=\"0\" max=\"" + feeds.length + "\"></progress>\
		</div>");
	} else {
		window.location.reload ();
	}
}
function updateProgressBar (i) {
	$("#actualizeProgressBar").val(i);
	$("#actualizeProgress .progress").html (i + " / " + feeds.length);
}

function updateFeeds () {
	initProgressBar (true);

	var i = 0;
	for (var f in feeds) {
		$.ajax ({
			type: 'POST',
			url: feeds[f],
		}).done (function (data) {
			i++;
			updateProgressBar (i);

			if (i == feeds.length) {
				initProgressBar (false);
			}
		});
	}
}

$(document).ready (function () {
	$("#actualize").click (function () {
		updateFeeds ();
		return false;
	});
});