summaryrefslogtreecommitdiffstats
path: root/apps/files_sharing/js/files_drop.js
diff options
context:
space:
mode:
authorArtur Neumann <info@individual-it.net>2017-04-18 20:38:43 +0545
committerArtur Neumann <info@individual-it.net>2017-04-18 20:42:36 +0545
commitcdb65eff34df30a50384f574bf2abb94989f28bd (patch)
tree72aef9fba26b1a3172fc2d4c144b768e505d2a83 /apps/files_sharing/js/files_drop.js
parent3795636b9073a2204036bfe2b581acb187dfcba6 (diff)
downloadnextcloud-server-cdb65eff34df30a50384f574bf2abb94989f28bd.tar.gz
nextcloud-server-cdb65eff34df30a50384f574bf2abb94989f28bd.zip
refactor to make it easier to test
Signed-off-by: Artur Neumann <info@individual-it.net>
Diffstat (limited to 'apps/files_sharing/js/files_drop.js')
-rw-r--r--apps/files_sharing/js/files_drop.js95
1 files changed, 50 insertions, 45 deletions
diff --git a/apps/files_sharing/js/files_drop.js b/apps/files_sharing/js/files_drop.js
index ba5bd82cc49..ddfcfcd3d8b 100644
--- a/apps/files_sharing/js/files_drop.js
+++ b/apps/files_sharing/js/files_drop.js
@@ -20,9 +20,11 @@
var Drop = {
/** @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(),
port: OC.getPort(),
@@ -32,7 +34,45 @@
root: OC.getRootPath() + '/public.php/webdav',
useHTTPS: OC.getProtocol() === 'https'
});
-
+
+ var name = data.files[0].name;
+ try {
+ // FIXME: not so elegant... need to refactor that method to return a value
+ Files.isFileNameValid(name);
+ }
+ catch (errorMessage) {
+ OC.Notification.show(errorMessage, {type: 'error'});
+ return false;
+ }
+ var base = OC.getProtocol() + '://' + OC.getHost();
+ data.url = base + OC.getRootPath() + '/public.php/webdav/' + encodeURI(name);
+
+ data.multipart = false;
+
+ if (!data.headers) {
+ data.headers = {};
+ }
+
+ var userName = filesClient.getUserName();
+ var password = filesClient.getPassword();
+ if (userName) {
+ // copy username/password from DAV client
+ data.headers['Authorization'] =
+ 'Basic ' + btoa(userName + ':' + (password || ''));
+ }
+
+ $('#drop-upload-done-indicator').addClass('hidden');
+ $('#drop-upload-progress-indicator').removeClass('hidden');
+ _.each(data['files'], function(file) {
+ $('#public-upload ul').append(output({isUploading: true, name: escapeHTML(file.name)}));
+ $('[data-toggle="tooltip"]').tooltip();
+ data.submit();
+ });
+
+ return true;
+ },
+
+ initialize: function () {
$(document).bind('drop dragover', function (e) {
// Prevent the default browser drop action:
e.preventDefault();
@@ -43,42 +83,9 @@
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
- Files.isFileNameValid(name);
- }
- catch (errorMessage) {
- OC.Notification.show(errorMessage, {type: 'error'});
- return false;
- }
- var base = OC.getProtocol() + '://' + OC.getHost();
- data.url = base + OC.getRootPath() + '/public.php/webdav/' + encodeURI(name);
-
- data.multipart = false;
-
- if (!data.headers) {
- data.headers = {};
- }
-
- var userName = filesClient.getUserName();
- var password = filesClient.getPassword();
- if (userName) {
- // copy username/password from DAV client
- data.headers['Authorization'] =
- 'Basic ' + btoa(userName + ':' + (password || ''));
- }
-
- $('#drop-upload-done-indicator').addClass('hidden');
- $('#drop-upload-progress-indicator').removeClass('hidden');
- _.each(data['files'], function(file) {
- $('#public-upload ul').append(output({isUploading: true, name: escapeHTML(file.name)}));
- $('[data-toggle="tooltip"]').tooltip();
- data.submit();
- });
-
+ 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) {
@@ -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);
-