actualize.phtml 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. "use strict";
  2. var feeds = [];
  3. <?php foreach ($this->feeds as $feed) { ?>
  4. feeds.push("<?php echo Minz_Url::display (array ('c' => 'feed', 'a' => 'actualize', 'params' => array ('id' => $feed->id (), 'ajax' => '1')), 'php'); ?>");
  5. <?php } ?>
  6. var feed_count = feeds.length;
  7. var feed_processed = 0;
  8. function initProgressBar(init) {
  9. if (init) {
  10. $("body").after("\<div id=\"actualizeProgress\" class=\"actualizeProgress\">\
  11. <?php echo Minz_Translate::t ('refresh'); ?> <span class=\"progress\">0 / " + feed_count + "</span><br />\
  12. <progress id=\"actualizeProgressBar\" value=\"0\" max=\"" + feed_count + "\"></progress>\
  13. </div>");
  14. } else {
  15. window.location.reload();
  16. }
  17. }
  18. function updateProgressBar(i) {
  19. $("#actualizeProgressBar").val(i);
  20. $("#actualizeProgress .progress").html(i + " / " + feed_count);
  21. }
  22. function updateFeeds() {
  23. if (feed_count === 0) {
  24. return;
  25. }
  26. initProgressBar(true);
  27. for (var i = 0; i < 10; i++) {
  28. updateFeed();
  29. }
  30. }
  31. function updateFeed() {
  32. if (feeds.length === 0) {
  33. return;
  34. }
  35. var feed = feeds.pop();
  36. $.ajax({
  37. type: 'POST',
  38. url: feed,
  39. }).done(function (data) {
  40. feed_processed++;
  41. updateProgressBar(feed_processed);
  42. if (feed_processed === feed_count) {
  43. initProgressBar(false);
  44. } else {
  45. updateFeed();
  46. }
  47. });
  48. }