browseimage.ui.js 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. var interval;
  2. window.renderCell = function(result, {col, row})
  3. {
  4. if(col.name === 'progress')
  5. {
  6. result[0] = {html: "<span class='image-progress-" + row.data.id + "'></span>"};
  7. }
  8. if(col.name === 'path')
  9. {
  10. result[0] = {html: "<span class='image-path-" + row.data.id + "'></span>"};
  11. }
  12. if(col.name === 'status')
  13. {
  14. result[0] = {html: "<span class='image-status-" + row.data.id + "'>" + result[0] + "</span>"};
  15. }
  16. return result;
  17. };
  18. $(function () {
  19. updateProgressInterval();
  20. });
  21. function updateProgressInterval() {
  22. updateProgress();
  23. interval = setInterval(function ()
  24. {
  25. updateProgress();
  26. }, 3000);
  27. }
  28. function updateProgress() {
  29. $.get($.createLink('zahost', 'ajaxImageDownloadProgress', 'hostID=' + hostID)).done(function (response)
  30. {
  31. var result = JSON.parse(response);
  32. var statusList = result.data;
  33. var hasInprogress = false;
  34. for (var imageID in statusList) {
  35. if (statusList[imageID].statusCode) {
  36. if (statusList[imageID].statusCode == 'inprogress' || statusList[imageID].statusCode == 'created' || statusList[imageID].statusCode == 'pending')
  37. {
  38. hasInprogress = true;
  39. }
  40. else if (statusList[imageID].statusCode == 'completed')
  41. {
  42. $('.image-path-' + imageID).text(statusList[imageID].path);
  43. $('.image-path-' + imageID).attr('title', statusList[imageID].path);
  44. $('.image-progress-' + imageID).text("100%");
  45. }
  46. else
  47. {
  48. $('.image-progress-' + imageID).text('');
  49. }
  50. if(statusList[imageID].status != $('.image-status-' + imageID).text()) loadPage();
  51. $('.image-status-' + imageID).text(statusList[imageID].status);
  52. if(statusList[imageID].progress != '' && statusList[imageID].statusCode != 'completed')
  53. {
  54. $('.image-progress-' + imageID).text(statusList[imageID].progress);
  55. }
  56. }
  57. }
  58. if (!hasInprogress)
  59. {
  60. clearInterval(interval)
  61. }
  62. });
  63. }