queueRenderer.js 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. var getQueueRenderer = function () {
  2. return new QueueRenderer();
  3. };
  4. var QueueRenderer = (function () {
  5. function QueueRenderer() {
  6. }
  7. QueueRenderer.prototype.createTextDiv = function (className, value) {
  8. var element = document.createElement("div");
  9. element.className = className;
  10. element.innerHTML = value;
  11. return element;
  12. };
  13. QueueRenderer.prototype.createButton = function (value, callback) {
  14. var element = document.createElement("button");
  15. element.className = "table-row-button";
  16. element.innerHTML = value;
  17. element.addEventListener("click", callback);
  18. return element;
  19. };
  20. QueueRenderer.prototype.createQueueRow = function (file, queueSettings) {
  21. var itemRow = document.createElement("div");
  22. itemRow.id = file.guid;
  23. itemRow.className = "table-row-item";
  24. this.renderQueueRowContent(itemRow, file, queueSettings);
  25. return itemRow;
  26. };
  27. QueueRenderer.prototype.translateFileStatus = function (file) {
  28. console.log(file)
  29. console.log(pu)
  30. switch (file.uploadStatus.toString()) {
  31. case pu.UploadStatus.queued:
  32. return "Queued";
  33. case pu.UploadStatus.uploading:
  34. return "Uploading";
  35. case pu.UploadStatus.uploaded:
  36. return "Uploaded";
  37. case pu.UploadStatus.failed:
  38. return "Failed";
  39. case pu.UploadStatus.canceled:
  40. return "Canceled";
  41. }
  42. return "Unknown";
  43. };
  44. QueueRenderer.prototype.renderQueueRowContent = function (itemRow, file, queueSettings) {
  45. while (itemRow.firstChild)
  46. itemRow.removeChild(itemRow.firstChild);
  47. itemRow.appendChild(this.createTextDiv('table-row-item-status', this.translateFileStatus(file)));
  48. itemRow.appendChild(this.createTextDiv('table-row-item-name', file.name));
  49. itemRow.appendChild(this.createTextDiv('table-row-item-progress', file.progress.toString() + "%"));
  50. switch (file.uploadStatus.toString()) {
  51. case pu.UploadStatus.queued:
  52. if (!queueSettings.autoStart) {
  53. itemRow.appendChild(this.createButton("Start", function () { return file.start(); }));
  54. break;
  55. }
  56. case pu.UploadStatus.uploading:
  57. itemRow.appendChild(this.createButton("Cancel", function () { return file.cancel(); }));
  58. break;
  59. case pu.UploadStatus.uploaded:
  60. case pu.UploadStatus.failed:
  61. case pu.UploadStatus.canceled:
  62. itemRow.appendChild(this.createButton("Delete", function () { return file.remove(); }));
  63. break;
  64. }
  65. };
  66. QueueRenderer.prototype.renderItemProgress = function (queueId, file) {
  67. var itemRow = document.getElementById(file.guid);
  68. for (var i = 0; i < itemRow.childNodes.length; i++) {
  69. var node = itemRow.childNodes[i];
  70. if (node.attributes.getNamedItem('class').value == 'table-row-item-progress') {
  71. node.textContent = file.progress.toString() + "%";
  72. break;
  73. }
  74. }
  75. };
  76. QueueRenderer.prototype.renderQueue = function (queueId, queueTitle, files, queueSettings) {
  77. var _this = this;
  78. var queue = document.getElementById(queueId);
  79. while (queue.firstChild)
  80. queue.removeChild(queue.firstChild);
  81. queue.appendChild(this.createTextDiv("table-header-title", queueTitle));
  82. files.forEach(function (file) {
  83. queue.appendChild(_this.createQueueRow(file, queueSettings));
  84. });
  85. };
  86. return QueueRenderer;
  87. })();