From c70688e5d0c9f6dc4e56b5111b8f4a21a09e64a4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Calvi=C3=B1o=20S=C3=A1nchez?= Date: Fri, 18 Aug 2017 14:26:15 +0200 Subject: [PATCH] Update the whole file item instead of only its contents MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The "done" and "fail" callbacks both update the item for the uploaded file using "setFileIcon". "setFileIcon" updates the contents of the "
  • " element for the file, but the "fail" callback was giving "setFileIcon" an element generated by the template, so the resulting HTML contained a "
  • " element nested in another "
  • " element. However, generating the HTML is better done through a template, so the template now receives the icon to show in order to be used by a successful upload and a failed one, and "setFileIcon" was changed to "updateFileItem". Note that the mimeTypeUrl does no longer need to be escaped, as Handlebars templates escape the needed characters automatically. Signed-off-by: Daniel Calviño Sánchez --- apps/files_sharing/js/files_drop.js | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/apps/files_sharing/js/files_drop.js b/apps/files_sharing/js/files_drop.js index b3956948ee..edd7cc9082 100644 --- a/apps/files_sharing/js/files_drop.js +++ b/apps/files_sharing/js/files_drop.js @@ -14,7 +14,7 @@ '{{#if isUploading}}' + ' {{name}}' + '{{else}}' + - ' {{name}}' + + ' {{name}}' + '{{/if}}' + '
  • '; var Drop = { @@ -72,8 +72,8 @@ return true; }, - setFileIcon: function (fileName,fileIcon) { - $('#public-upload ul li[data-name="' + fileName + '"]').html(fileIcon); + updateFileItem: function (fileName, fileItem) { + $('#public-upload ul li[data-name="' + fileName + '"]').replaceWith(fileItem); $('[data-toggle="tooltip"]').tooltip(); }, @@ -98,8 +98,8 @@ done: function(e, data) { // Created var mimeTypeUrl = OC.MimeType.getIconUrl(data.files[0].type); - var fileIcon = ' ' + fileName; - Drop.setFileIcon(fileName,fileIcon); + var fileItem = output({isUploading: false, iconSrc: mimeTypeUrl, name: fileName}); + Drop.updateFileItem(fileName, fileItem); }, fail: function(e, data) { OC.Notification.showTemporary(OC.L10N.translate( @@ -107,8 +107,9 @@ 'Could not upload "{filename}"', {filename: fileName} )); - var fileIcon = output({isUploading: false, name: fileName}); - Drop.setFileIcon(fileName,fileIcon); + var errorIconSrc = OC.imagePath('core', 'actions/error.svg'); + var fileItem = output({isUploading: false, iconSrc: errorIconSrc, name: fileName}); + Drop.updateFileItem(fileName, fileItem); }, progressall: function (e, data) { var progress = parseInt(data.loaded / data.total * 100, 10);