refactor to make it easier to test

Signed-off-by: Artur Neumann <info@individual-it.net>
This commit is contained in:
Artur Neumann 2017-04-18 20:38:43 +05:45
parent 3795636b90
commit cdb65eff34
1 changed files with 50 additions and 45 deletions

View File

@ -21,7 +21,9 @@
/** @type {Function} **/
_template: undefined,
initialize: function () {
addFileToUpload: function(e, data) {
var errors = [];
var output = this.template();
var filesClient = new OC.Files.Client({
host: OC.getHost(),
@ -33,18 +35,6 @@
useHTTPS: OC.getProtocol() === 'https'
});
$(document).bind('drop dragover', function (e) {
// Prevent the default browser drop action:
e.preventDefault();
});
var output = this.template();
$('#public-upload').fileupload({
type: 'PUT',
dropZone: $('#public-upload'),
sequentialUploads: true,
add: function(e, data) {
var errors = [];
var name = data.files[0].name;
try {
// FIXME: not so elegant... need to refactor that method to return a value
@ -81,6 +71,23 @@
return true;
},
initialize: function () {
$(document).bind('drop dragover', function (e) {
// Prevent the default browser drop action:
e.preventDefault();
});
var output = this.template();
$('#public-upload').fileupload({
type: 'PUT',
dropZone: $('#public-upload'),
sequentialUploads: true,
add: function(e, data) {
Drop.addFileToUpload(e, data);
//we return true to keep trying to upload next file even
//if addFileToUpload did not like the privious one
return true;
},
done: function(e, data) {
// Created
if (data.jqXHR.status === 201) {
@ -123,15 +130,13 @@
}
};
OCA.FilesSharingDrop = Drop;
$(document).ready(function() {
if($('#upload-only-interface').val() === "1") {
$('.avatardiv').avatar($('#sharingUserId').val(), 128, true);
}
OCA.Files_Sharing_Drop = Drop;
OCA.Files_Sharing_Drop.initialize();
OCA.FilesSharingDrop.initialize();
});
})(jQuery);