diff options
author | Vincent Petry <pvince81@owncloud.com> | 2017-04-17 00:42:51 +0300 |
---|---|---|
committer | Olivier Paroz (oparoz) <github@oparoz.com> | 2017-04-18 10:40:26 +0300 |
commit | b4ac4429841cfe2b7ea260dfb37fcde25580143c (patch) | |
tree | 3548986a3d75aeb8a37c90acbc85ec36e88e856f | |
parent | 54b52fb2935a783305f35a57b1aedb74d839cd4b (diff) |
Fix upload after core changesv11.0.3RC2
+ minor fixes
Signed-off-by: Olivier Paroz (oparoz) <github@oparoz.com>
(cherry picked from commit 2068e12)
Signed-off-by: Olivier Paroz (oparoz) <github@oparoz.com>
-rw-r--r-- | js/galleryview.js | 42 | ||||
-rw-r--r-- | js/upload-helper.js | 62 |
2 files changed, 62 insertions, 42 deletions
diff --git a/js/galleryview.js b/js/galleryview.js index 73b6e59a..88c0af76 100644 --- a/js/galleryview.js +++ b/js/galleryview.js @@ -1,4 +1,4 @@ -/* global Handlebars, Gallery */ +/* global Handlebars, Gallery, Thumbnails */ (function ($, _, OC, t, Gallery) { "use strict"; @@ -291,28 +291,50 @@ /** * Sets up our custom handlers for folder uploading operations * - * We only want it to be called for that specific case as all other file uploading - * operations will call Files.highlightFiles - * * @see OC.Upload.init/file_upload_param.done() * * @private */ _setupUploader: function () { - $('#file_upload_start').on('fileuploaddone', function (e, data) { - if (data.files[0] === data.originalFiles[data.originalFiles.length - 1] - && data.files[0].relativePath) { + var $uploadEl = $('#file_upload_start'); + if (!$uploadEl.exists()) { + return; + } + this._uploader = new OC.Uploader($uploadEl, { + fileList: FileList, + dropZone: $('#content') + }); + this._uploader.on('add', function (e, data) { + data.targetDir = '/' + Gallery.currentAlbum; + }); + this._uploader.on('done', function (e, upload) { + var data = upload.data; + // is that the last upload ? + if (data.files[0] === data.originalFiles[data.originalFiles.length - 1]) { + var fileList = data.originalFiles; //Ask for a refresh of the photowall Gallery.getFiles(Gallery.currentAlbum).done(function () { + var fileId, path; + // Removes the cached thumbnails of files which have been re-uploaded + _(fileList).each(function (fileName) { + path = Gallery.currentAlbum + '/' + fileName; + if (Gallery.imageMap[path]) { + fileId = Gallery.imageMap[path].fileId; + if (Thumbnails.map[fileId]) { + delete Thumbnails.map[fileId]; + } + } + }); + Gallery.view.init(Gallery.currentAlbum); }); } }); - // Since 9.0 - if (OC.Upload) { - OC.Upload._isReceivedSharedFile = function (file) { + // Since Nextcloud 9.0 + if (OC.Uploader) { + OC.Uploader.prototype._isReceivedSharedFile = function (file) { var path = file.name; var sharedWith = false; diff --git a/js/upload-helper.js b/js/upload-helper.js index 32731f00..0ca31ea7 100644 --- a/js/upload-helper.js +++ b/js/upload-helper.js @@ -1,4 +1,4 @@ -/* global Gallery, Thumbnails */ +/* global _, Gallery, Thumbnails */ /** * OCA.FileList methods needed for file uploading * @@ -7,9 +7,9 @@ * * Empty methods are for the "new" button, if we want to implement that one day * - * @type {{inList: FileList.inList, lastAction: FileList.lastAction, getUniqueName: - * FileList.getUniqueName, getCurrentDirectory: FileList.getCurrentDirectory, add: - * FileList.add, checkName: FileList.checkName}} + * @type {{findFile: FileList.findFile, createFile: FileList.createFile, + * getCurrentDirectory: FileList.getCurrentDirectory, getUploadUrl: + * FileList.getUploadUrl}} */ var FileList = { /** @@ -42,34 +42,6 @@ var FileList = { }, /** - * Refreshes the photowall - * - * Called at the end of the uploading process when 1 or multiple files are sent - * Never called with folders on Chrome, unless files are uploaded at the same time as folders - * - * @param fileList - */ - highlightFiles: function (fileList) { - "use strict"; - //Ask for a refresh of the photowall - Gallery.getFiles(Gallery.currentAlbum).done(function () { - var fileId, path; - // Removes the cached thumbnails of files which have been re-uploaded - _(fileList).each(function (fileName) { - path = Gallery.currentAlbum + '/' + fileName; - if (Gallery.imageMap[path]) { - fileId = Gallery.imageMap[path].fileId; - if (Thumbnails.map[fileId]) { - delete Thumbnails.map[fileId]; - } - } - }); - - Gallery.view.init(Gallery.currentAlbum); - }); - }, - - /** * Create an empty file inside the current album. * * @param {string} name name of the file @@ -144,6 +116,32 @@ var FileList = { // In Files, dirs start with a / return '/' + Gallery.currentAlbum; + }, + + /** + * Retrieves the WebDAV upload URL + * + * @param {string} fileName + * @param {string} dir + * + * @returns {string} + */ + getUploadUrl: function (fileName, dir) { + if (_.isUndefined(dir)) { + dir = this.getCurrentDirectory(); + } + + var pathSections = dir.split('/'); + if (!_.isUndefined(fileName)) { + pathSections.push(fileName); + } + var encodedPath = ''; + _.each(pathSections, function (section) { + if (section !== '') { + encodedPath += '/' + encodeURIComponent(section); + } + }); + return OC.linkToRemoteBase('webdav') + encodedPath; } }; |