actualize.phtml 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. "use strict";
  2. var feeds = [<?php foreach ($this->feeds as $feed) { ?>{<?php
  3. ?>url: "<?php echo Minz_Url::display(array('c' => 'feed', 'a' => 'actualize', 'params' => array('id' => $feed->id(), 'ajax' => '1')), 'php'); ?>",<?php
  4. ?>title: "<?php echo $feed->name(); ?>"<?php
  5. ?>},<?php } ?>],
  6. feed_processed = 0,
  7. feed_count = feeds.length;
  8. function initProgressBar(init) {
  9. if (init) {
  10. $("body").after("\<div id=\"actualizeProgress\" class=\"notification good\">\
  11. <?php echo _t('feedback.sub.actualize'); ?><br /><span class=\"title\">/</span><br />\
  12. <span class=\"progress\">0 / " + feed_count + "</span>\
  13. </div>");
  14. } else {
  15. window.location.reload();
  16. }
  17. }
  18. function updateProgressBar(i, title_feed) {
  19. $("#actualizeProgress .progress").html(i + " / " + feed_count);
  20. $("#actualizeProgress .title").html(title_feed);
  21. }
  22. function updateFeeds() {
  23. if (feed_count === 0) {
  24. openNotification("<?php echo _t('feedback.sub.feed.no_refresh'); ?>", "good");
  25. ajax_loading = false;
  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['url'],
  41. }).complete(function (data) {
  42. feed_processed++;
  43. updateProgressBar(feed_processed, feed['title']);
  44. if (feed_processed === feed_count) {
  45. initProgressBar(false);
  46. } else {
  47. updateFeed();
  48. }
  49. });
  50. }