actualize.phtml 1.2 KB

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