actualize.phtml 1.3 KB

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