bartender.js 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. $(document).delegate( '.js-bartend', 'click', function () {
  2. $.ajax({
  3. url: '/ajax/bartender.php',
  4. // type: 'post',
  5. data: {
  6. action: 'shake',
  7. dossier: $(this).data('dossier'),
  8. projetId: $(this).data('projet-id'),
  9. projetPadPrincipal: $(this).data('projet-pad-principal'),
  10. projetPadGarde: $(this).data('projet-pad-garde')
  11. },
  12. success: function (data) {
  13. if (data.status === 'error')
  14. alert('Bartender says: '+data.errors.join(' '));
  15. else
  16. setTimeout(status,1000);
  17. },
  18. error: function () {
  19. alert("Je n'ai pas pu contacter le barman pour presser le projet...");
  20. }
  21. });
  22. return false;
  23. });
  24. function status () {
  25. var deferreds = [];
  26. var need_refresh = 0;
  27. $('.js-status').each( function () {
  28. var statusdiv = $(this);
  29. deferreds.push($.ajax({
  30. url: '/ajax/bartender.php',
  31. data: {
  32. action: 'status',
  33. dossier: statusdiv.data('dossier'),
  34. projetId: statusdiv.data('projet-id')
  35. },
  36. success: function (data) {
  37. if (data.status === 'error') {
  38. alert('Bartender says: '+data.errors.join(' '));
  39. }
  40. statusdiv.find('.js-status-placeholder').text(data.status);
  41. statusdiv.find('.js-time-placeholder').text(data.time);
  42. if (data.status === 'IN_PROGRESS') // on relance la vérif de statut dans 3s pour voir si la compil est terminée
  43. need_refresh++;
  44. },
  45. error: function () {
  46. alert("Je n'ai pas pu contacter le barman pour le statut de compilation...");
  47. }
  48. }));
  49. });
  50. $.when.apply($,deferreds).done( function () {
  51. if (need_refresh > 0)
  52. setTimeout(status,3000);
  53. });
  54. }
  55. $(document).ready( function () {
  56. status();
  57. });