From cacfb4b909938fb28e032eff7a919600a9d3b6da Mon Sep 17 00:00:00 2001 From: Bola Ahmed Buari Date: Wed, 12 May 2021 13:48:43 +0000 Subject: [PATCH] Fixes #2383: No error message on failed uploads --- .../ticket_zoom/article_new.coffee | 20 +++++++++++++++++++ .../javascripts/app/lib/base/html5Upload.js | 15 +++++++++++--- 2 files changed, 32 insertions(+), 3 deletions(-) diff --git a/app/assets/javascripts/app/controllers/ticket_zoom/article_new.coffee b/app/assets/javascripts/app/controllers/ticket_zoom/article_new.coffee index d954d13bc..e613a8dc9 100644 --- a/app/assets/javascripts/app/controllers/ticket_zoom/article_new.coffee +++ b/app/assets/javascripts/app/controllers/ticket_zoom/article_new.coffee @@ -239,6 +239,26 @@ class App.TicketZoomArticleNew extends App.Controller # hide cancel on 90% if parseInt(progress) >= 90 @cancelContainer.addClass('hide') + + # Called when upload failed + onError: (message) => + @attachmentPlaceholder.removeClass('hide') + @attachmentUpload.addClass('hide') + @$('.article-attachment input').val('') + + if @callbackFileUploadStop + @callbackFileUploadStop() + + new App.ControllerModal( + head: 'Upload Failed' + buttonCancel: 'Cancel' + buttonCancelClass: 'btn--danger' + buttonSubmit: false + message: message + shown: true + small: true + container: @el.closest('.content') + ) ) ) diff --git a/app/assets/javascripts/app/lib/base/html5Upload.js b/app/assets/javascripts/app/lib/base/html5Upload.js index b8b5aa001..2a78163b0 100644 --- a/app/assets/javascripts/app/lib/base/html5Upload.js +++ b/app/assets/javascripts/app/lib/base/html5Upload.js @@ -57,6 +57,10 @@ console.log('Event: upload onCompleted, data = ' + data); file = null; (self.eventHandlers.onCompleted || noop)(data); + }, + onError: function (message) { + console.log('Event: upload error, message: ' + message); + (self.eventHandlers.onError || noop)(message); } }; } @@ -226,12 +230,17 @@ // Triggered when upload is completed: xhr.onload = function (event) { - console.log('Upload completed: ' + fileName); - // Reduce number of active uploads: manager.activeUploads -= 1; - upload.events.onCompleted(event.target.responseText); + // call the error callback when the status is not ok + if (xhr.status !== 200){ + console.log('Upload failed: ' + fileName); + upload.events.onError(event.target.statusText); + } else { + console.log('Upload completed: ' + fileName); + upload.events.onCompleted(event.target.responseText); + } // Check if there are any uploads left in a queue: if (manager.uploadsQueue.length) {