aboutsummaryrefslogtreecommitdiffstats
path: root/apps/files/js/file-upload.js
diff options
context:
space:
mode:
Diffstat (limited to 'apps/files/js/file-upload.js')
-rw-r--r--apps/files/js/file-upload.js79
1 files changed, 54 insertions, 25 deletions
diff --git a/apps/files/js/file-upload.js b/apps/files/js/file-upload.js
index 17f0f777169..77b85ecd7da 100644
--- a/apps/files/js/file-upload.js
+++ b/apps/files/js/file-upload.js
@@ -18,7 +18,7 @@
* - TODO music upload button
*/
-/* global Files, FileList, jQuery, oc_requesttoken, humanFileSize, getUniqueName */
+/* global jQuery, oc_requesttoken, humanFileSize */
/**
* Function that will allow us to know if Ajax uploads are supported
@@ -75,6 +75,9 @@ OC.Upload = {
this._uploads.push(jqXHR);
}
},
+ showUploadCancelMessage: _.debounce(function() {
+ OC.Notification.showTemporary(t('files', 'Upload cancelled.'), {timeout: 10});
+ }, 500),
/**
* Checks the currently known uploads.
* returns true if any hxr has the state 'pending'
@@ -139,6 +142,9 @@ OC.Upload = {
if (data.data) {
data.data.append('resolution', 'replace');
} else {
+ if (!data.formData) {
+ data.formData = [];
+ }
data.formData.push({name:'resolution', value:'replace'}); //hack for ie8
}
data.submit();
@@ -152,6 +158,9 @@ OC.Upload = {
if (data.data) {
data.data.append('resolution', 'autorename');
} else {
+ if (!data.formData) {
+ data.formData = [];
+ }
data.formData.push({name:'resolution', value:'autorename'}); //hack for ie8
}
data.submit();
@@ -164,8 +173,9 @@ OC.Upload = {
}
},
/**
- * TODO checks the list of existing files prior to uploading and shows a simple dialog to choose
+ * checks the list of existing files prior to uploading and shows a simple dialog to choose
* skip all, replace all or choose which files to keep
+ *
* @param {array} selection of files to upload
* @param {object} callbacks - object with several callback methods
* @param {function} callbacks.onNoConflicts
@@ -175,14 +185,37 @@ OC.Upload = {
* @param {function} callbacks.onCancel
*/
checkExistingFiles: function (selection, callbacks) {
- /*
- $.each(selection.uploads, function(i, upload) {
- var $row = OCA.Files.App.fileList.findFileEl(upload.files[0].name);
- if ($row) {
- // TODO check filelist before uploading and show dialog on conflicts, use callbacks
+ var fileList = OCA.Files.App.fileList;
+ var conflicts = [];
+ // only keep non-conflicting uploads
+ selection.uploads = _.filter(selection.uploads, function(upload) {
+ var fileInfo = fileList.findFile(upload.files[0].name);
+ if (fileInfo) {
+ conflicts.push([
+ // original
+ _.extend(fileInfo, {
+ directory: fileInfo.directory || fileInfo.path || fileList.getCurrentDirectory()
+ }),
+ // replacement (File object)
+ upload
+ ]);
+ return false;
}
+ return true;
});
- */
+ if (conflicts.length) {
+ // wait for template loading
+ OC.dialogs.fileexists(null, null, null, OC.Upload).done(function() {
+ _.each(conflicts, function(conflictData) {
+ OC.dialogs.fileexists(conflictData[1], conflictData[0], conflictData[1].files[0], OC.Upload);
+ });
+ });
+ }
+
+ // upload non-conflicting files
+ // note: when reaching the server they might still meet conflicts
+ // if the folder was concurrently modified, these will get added
+ // to the already visible dialog, if applicable
callbacks.onNoConflicts(selection);
},
@@ -368,27 +401,27 @@ OC.Upload = {
},
submit: function(e, data) {
OC.Upload.rememberUpload(data);
- if ( ! data.formData ) {
- var fileDirectory = '';
- if(typeof data.files[0].relativePath !== 'undefined') {
- fileDirectory = data.files[0].relativePath;
- }
- // noone set update parameters, we set the minimum
- data.formData = {
- requesttoken: oc_requesttoken,
- dir: data.targetDir || FileList.getCurrentDirectory(),
- file_directory: fileDirectory
- };
+ if (!data.formData) {
+ data.formData = [];
+ }
+
+ var fileDirectory = '';
+ if(typeof data.files[0].relativePath !== 'undefined') {
+ fileDirectory = data.files[0].relativePath;
}
+ // FIXME: prevent re-adding the same
+ data.formData.push({name: 'requesttoken', value: oc_requesttoken});
+ data.formData.push({name: 'dir', value: data.targetDir || FileList.getCurrentDirectory()});
+ data.formData.push({name: 'file_directory', value: fileDirectory});
},
fail: function(e, data) {
OC.Upload.log('fail', e, data);
if (typeof data.textStatus !== 'undefined' && data.textStatus !== 'success' ) {
if (data.textStatus === 'abort') {
- OC.Notification.show(t('files', 'Upload cancelled.'));
+ OC.Upload.showUploadCancelMessage();
} else {
// HTTP connection problem
- OC.Notification.show(data.errorThrown);
+ OC.Notification.showTemporary(data.errorThrown, {timeout: 10});
if (data.result) {
var result = JSON.parse(data.result);
if (result && result[0] && result[0].data && result[0].data.code === 'targetnotfound') {
@@ -397,10 +430,6 @@ OC.Upload = {
}
}
}
- //hide notification after 10 sec
- setTimeout(function() {
- OC.Notification.hide();
- }, 10000);
}
OC.Upload.deleteUpload(data);
},