From 246a5a5750dd2b8f990797b2c6cc4270a9a5b59d Mon Sep 17 00:00:00 2001 From: Thomas Citharel Date: Sun, 27 Aug 2017 15:28:26 +0200 Subject: Allow files to be copied through action menu & multiple files actions Signed-off-by: Thomas Citharel --- core/js/files/client.js | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) (limited to 'core/js') diff --git a/core/js/files/client.js b/core/js/files/client.js index 176cabf04b1..dc9f6ade641 100644 --- a/core/js/files/client.js +++ b/core/js/files/client.js @@ -736,6 +736,51 @@ return promise; }, + /** + * Copies path to another path + * + * @param {String} path path to copy + * @param {String} destinationPath destination path + * @param {boolean} [allowOverwrite=false] true to allow overwriting, + * false otherwise + * + * @return {Promise} promise + */ + copy: function (path, destinationPath, allowOverwrite) { + if (!path) { + throw 'Missing argument "path"'; + } + if (!destinationPath) { + throw 'Missing argument "destinationPath"'; + } + + var self = this; + var deferred = $.Deferred(); + var promise = deferred.promise(); + var headers = { + 'Destination' : this._buildUrl(destinationPath) + }; + + if (!allowOverwrite) { + headers.Overwrite = 'F'; + } + + this._client.request( + 'COPY', + this._buildUrl(path), + headers + ).then( + function(response) { + if (self._isSuccessStatus(response.status)) { + deferred.resolve(response.status); + } else { + deferred.reject(response.status); + } + } + ); + return promise; + }, + /** * Add a file info parser function * -- cgit v1.2.3