Update the whole file item instead of only its contents
The "done" and "fail" callbacks both update the item for the uploaded file using "setFileIcon". "setFileIcon" updates the contents of the "<li>" element for the file, but the "fail" callback was giving "setFileIcon" an element generated by the template, so the resulting HTML contained a "<li>" element nested in another "<li>" 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 <danxuliu@gmail.com>
This commit is contained in:
parent
8a1850f6b1
commit
b68bad45dc
|
@ -14,7 +14,7 @@
|
||||||
'{{#if isUploading}}' +
|
'{{#if isUploading}}' +
|
||||||
'<span class="icon-loading-small"></span> {{name}}' +
|
'<span class="icon-loading-small"></span> {{name}}' +
|
||||||
'{{else}}' +
|
'{{else}}' +
|
||||||
'<img src="' + OC.imagePath('core', 'actions/error.svg') + '"/> {{name}}' +
|
'<img src="{{iconSrc}}"/> {{name}}' +
|
||||||
'{{/if}}' +
|
'{{/if}}' +
|
||||||
'</li>';
|
'</li>';
|
||||||
var Drop = {
|
var Drop = {
|
||||||
|
@ -72,8 +72,8 @@
|
||||||
return true;
|
return true;
|
||||||
},
|
},
|
||||||
|
|
||||||
setFileIcon: function (fileName,fileIcon) {
|
updateFileItem: function (fileName, fileItem) {
|
||||||
$('#public-upload ul li[data-name="' + fileName + '"]').html(fileIcon);
|
$('#public-upload ul li[data-name="' + fileName + '"]').replaceWith(fileItem);
|
||||||
$('[data-toggle="tooltip"]').tooltip();
|
$('[data-toggle="tooltip"]').tooltip();
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -98,8 +98,8 @@
|
||||||
done: function(e, data) {
|
done: function(e, data) {
|
||||||
// Created
|
// Created
|
||||||
var mimeTypeUrl = OC.MimeType.getIconUrl(data.files[0].type);
|
var mimeTypeUrl = OC.MimeType.getIconUrl(data.files[0].type);
|
||||||
var fileIcon = '<img src="' + escapeHTML(mimeTypeUrl) + '"/> ' + fileName;
|
var fileItem = output({isUploading: false, iconSrc: mimeTypeUrl, name: fileName});
|
||||||
Drop.setFileIcon(fileName,fileIcon);
|
Drop.updateFileItem(fileName, fileItem);
|
||||||
},
|
},
|
||||||
fail: function(e, data) {
|
fail: function(e, data) {
|
||||||
OC.Notification.showTemporary(OC.L10N.translate(
|
OC.Notification.showTemporary(OC.L10N.translate(
|
||||||
|
@ -107,8 +107,9 @@
|
||||||
'Could not upload "{filename}"',
|
'Could not upload "{filename}"',
|
||||||
{filename: fileName}
|
{filename: fileName}
|
||||||
));
|
));
|
||||||
var fileIcon = output({isUploading: false, name: fileName});
|
var errorIconSrc = OC.imagePath('core', 'actions/error.svg');
|
||||||
Drop.setFileIcon(fileName,fileIcon);
|
var fileItem = output({isUploading: false, iconSrc: errorIconSrc, name: fileName});
|
||||||
|
Drop.updateFileItem(fileName, fileItem);
|
||||||
},
|
},
|
||||||
progressall: function (e, data) {
|
progressall: function (e, data) {
|
||||||
var progress = parseInt(data.loaded / data.total * 100, 10);
|
var progress = parseInt(data.loaded / data.total * 100, 10);
|
||||||
|
|
Loading…
Reference in New Issue