smaller files drop fixes

* fix infinite spinner on blacklisted files
* move HTML to template
* indentation
This commit is contained in:
Arthur Schiwon 2016-06-11 15:15:37 +02:00 committed by Lukas Reschke
parent 68c38ae8c2
commit 7f5048e2e5
No known key found for this signature in database
GPG Key ID: 9AB0ADB949B6898C
3 changed files with 40 additions and 5 deletions

View File

@ -43,6 +43,7 @@ OCP\JSON::setContentTypeHeader('text/plain');
// If no token is sent along, rely on login only // If no token is sent along, rely on login only
$errorCode = null; $errorCode = null;
$errorFileName = null;
$l = \OC::$server->getL10N('files'); $l = \OC::$server->getL10N('files');
if (empty($_POST['dirToken'])) { if (empty($_POST['dirToken'])) {
@ -225,6 +226,7 @@ if (\OC\Files\Filesystem::isValidPath($dir) === true) {
} else { } else {
$error = $l->t('Upload failed. Could not find uploaded file'); $error = $l->t('Upload failed. Could not find uploaded file');
$errorFileName = $files['name'][$i];
} }
} catch(Exception $ex) { } catch(Exception $ex) {
$error = $ex->getMessage(); $error = $ex->getMessage();
@ -273,5 +275,9 @@ if ($error === false) {
OCP\JSON::encodedPrint($result); OCP\JSON::encodedPrint($result);
} else { } else {
OCP\JSON::error(array(array('data' => array_merge(array('message' => $error, 'code' => $errorCode), $storageStats)))); OCP\JSON::error(array(array('data' => array_merge(array(
'message' => $error,
'code' => $errorCode,
'filename' => $errorFileName
), $storageStats))));
} }

View File

@ -9,12 +9,24 @@
*/ */
(function ($) { (function ($) {
var TEMPLATE =
'<li data-toggle="tooltip" title="{{name}}" data-name="{{name}}">' +
'{{#if isUploading}}' +
'<span class="icon-loading-small"></span> {{name}}' +
'{{else}}' +
'<img src="' + OC.imagePath('core', 'actions/error.svg') + '"/> {{name}}' +
'{{/if}}' +
'</li>';
var Drop = { var Drop = {
/** @type {Function} **/
_template: undefined,
initialize: function () { initialize: function () {
$(document).bind('drop dragover', function (e) { $(document).bind('drop dragover', function (e) {
// Prevent the default browser drop action: // Prevent the default browser drop action:
e.preventDefault(); e.preventDefault();
}); });
var output = this.template();
$('#public-upload').fileupload({ $('#public-upload').fileupload({
url: OC.linkTo('files', 'ajax/upload.php'), url: OC.linkTo('files', 'ajax/upload.php'),
dataType: 'json', dataType: 'json',
@ -32,12 +44,12 @@
$('#drop-upload-progress-indicator').removeClass('hidden'); $('#drop-upload-progress-indicator').removeClass('hidden');
_.each(data['files'], function(file) { _.each(data['files'], function(file) {
if(errors.length === 0) { if(errors.length === 0) {
$('#public-upload ul').append('<li data-toggle="tooltip" title="'+escapeHTML(file.name)+'" data-name="'+escapeHTML(file.name)+'"><span class="icon-loading-small"></span> '+escapeHTML(file.name)+'</li>'); $('#public-upload ul').append(output({isUploading: true, name: escapeHTML(file.name)}));
$('[data-toggle="tooltip"]').tooltip(); $('[data-toggle="tooltip"]').tooltip();
data.submit(); data.submit();
} else { } else {
OC.Notification.showTemporary(OC.L10N.translate('files_sharing', 'Could not upload "{filename}"', {filename: file.name})); OC.Notification.showTemporary(OC.L10N.translate('files_sharing', 'Could not upload "{filename}"', {filename: file.name}));
$('#public-upload ul').append('<li data-toggle="tooltip" title="'+escapeHTML(file.name)+'" data-name="'+escapeHTML(file.name)+'"><img src="'+OC.imagePath('core', 'actions/error.svg')+'"/> '+escapeHTML(file.name)+'</li>'); $('#public-upload ul').append(output({isUploading: false, name: escapeHTML(file.name)}));
$('[data-toggle="tooltip"]').tooltip(); $('[data-toggle="tooltip"]').tooltip();
} }
}); });
@ -47,7 +59,13 @@
var mimeTypeUrl = OC.MimeType.getIconUrl(response['mimetype']); var mimeTypeUrl = OC.MimeType.getIconUrl(response['mimetype']);
$('#public-upload ul li[data-name="' + escapeHTML(response['filename']) + '"]').html('<img src="' + escapeHTML(mimeTypeUrl) + '"/> ' + escapeHTML(response['filename'])); $('#public-upload ul li[data-name="' + escapeHTML(response['filename']) + '"]').html('<img src="' + escapeHTML(mimeTypeUrl) + '"/> ' + escapeHTML(response['filename']));
$('[data-toggle="tooltip"]').tooltip(); $('[data-toggle="tooltip"]').tooltip();
} else {
var name = response[0]['data']['filename'];
OC.Notification.showTemporary(OC.L10N.translate('files_sharing', 'Could not upload "{filename}"', {filename: name}));
$('#public-upload ul li[data-name="' + escapeHTML(name) + '"]').html(output({isUploading: false, name: escapeHTML(name)}));
$('[data-toggle="tooltip"]').tooltip();
} }
}, },
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);
@ -64,6 +82,17 @@
e.preventDefault(); e.preventDefault();
$('#public-upload #emptycontent input').focus().trigger('click'); $('#public-upload #emptycontent input').focus().trigger('click');
}); });
},
/**
* @returns {Function} from Handlebars
* @private
*/
template: function () {
if (!this._template) {
this._template = Handlebars.compile(TEMPLATE);
}
return this._template;
} }
}; };

View File

@ -30,13 +30,13 @@
' <input type="checkbox" value="1" name="allowPublicUpload" id="sharingDialogAllowPublicUpload-{{cid}}" class="checkbox publicUploadCheckbox" {{{publicUploadChecked}}} />' + ' <input type="checkbox" value="1" name="allowPublicUpload" id="sharingDialogAllowPublicUpload-{{cid}}" class="checkbox publicUploadCheckbox" {{{publicUploadChecked}}} />' +
'<label for="sharingDialogAllowPublicUpload-{{cid}}">{{publicUploadLabel}}</label>' + '<label for="sharingDialogAllowPublicUpload-{{cid}}">{{publicUploadLabel}}</label>' +
'</div>' + '</div>' +
'{{#if hideFileList}}' + ' {{#if hideFileList}}' +
'<div id="hideFileListWrapper">' + '<div id="hideFileListWrapper">' +
' <span class="icon-loading-small hidden"></span>' + ' <span class="icon-loading-small hidden"></span>' +
' <input type="checkbox" value="1" name="hideFileList" id="sharingDialogHideFileList-{{cid}}" class="checkbox hideFileListCheckbox" {{{hideFileListChecked}}} />' + ' <input type="checkbox" value="1" name="hideFileList" id="sharingDialogHideFileList-{{cid}}" class="checkbox hideFileListCheckbox" {{{hideFileListChecked}}} />' +
'<label for="sharingDialogHideFileList-{{cid}}">{{hideFileListLabel}}</label>' + '<label for="sharingDialogHideFileList-{{cid}}">{{hideFileListLabel}}</label>' +
'</div>' + '</div>' +
'{{/if}}' + ' {{/if}}' +
' {{/if}}' + ' {{/if}}' +
' {{#if showPasswordCheckBox}}' + ' {{#if showPasswordCheckBox}}' +
'<input type="checkbox" name="showPassword" id="showPassword-{{cid}}" class="checkbox showPasswordCheckbox" {{#if isPasswordSet}}checked="checked"{{/if}} value="1" />' + '<input type="checkbox" name="showPassword" id="showPassword-{{cid}}" class="checkbox showPasswordCheckbox" {{#if isPasswordSet}}checked="checked"{{/if}} value="1" />' +