actualize.phtml 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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=\"notification good\">\
  12. <?php echo _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. openNotification("<?php echo _t('no_feed_to_refresh'); ?>", "good");
  26. ajax_loading = false;
  27. return;
  28. }
  29. initProgressBar(true);
  30. for (var i = 0; i < 10; i++) {
  31. updateFeed();
  32. }
  33. }
  34. function updateFeed() {
  35. var feed = feeds.pop();
  36. if (feed == undefined) {
  37. return;
  38. }
  39. $.ajax({
  40. type: 'POST',
  41. url: feed,
  42. }).complete(function (data) {
  43. feed_processed++;
  44. updateProgressBar(feed_processed);
  45. if (feed_processed === feed_count) {
  46. initProgressBar(false);
  47. } else {
  48. updateFeed();
  49. }
  50. });
  51. }