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 From 33f0601862c337799235c06282764fc95fe21f02 Mon Sep 17 00:00:00 2001 From: Thomas Citharel Date: Sun, 27 Aug 2017 17:39:22 +0200 Subject: [WIP] Added copy and move buttons Signed-off-by: Thomas Citharel --- apps/files/js/fileactions.js | 29 +++++------- apps/files/js/filelist.js | 20 ++++----- apps/files/templates/list.php | 4 +- core/css/jquery.ocdialog.css | 3 ++ core/js/jquery.ocdialog.js | 5 +++ core/js/oc-dialogs.js | 101 +++++++++++++++++++++++++++++++++++++----- 6 files changed, 119 insertions(+), 43 deletions(-) (limited to 'core/js') diff --git a/apps/files/js/fileactions.js b/apps/files/js/fileactions.js index 527cbc0bd34..668960d5937 100644 --- a/apps/files/js/fileactions.js +++ b/apps/files/js/fileactions.js @@ -618,30 +618,21 @@ }); this.registerAction({ - name: 'Move', - displayName: t('files', 'Move'), + name: 'CopyMove', + displayName: t('files', 'Copy or Move'), mime: 'all', order: -25, permissions: OC.PERMISSION_UPDATE, iconClass: 'icon-external', actionHandler: function (filename, context) { - OC.dialogs.filepicker(t('files', 'Target folder'), function(targetPath) { - context.fileList.move(filename, targetPath); - }, false, "httpd/unix-directory", true); - } - }); - - this.registerAction({ - name: 'Copy', - displayName: t('files', 'Copy'), - mime: 'all', - order: -25, - permissions: OC.PERMISSION_READ, - iconClass: 'icon-external', - actionHandler: function (filename, context) { - OC.dialogs.filepicker(t('files', 'Target folder'), function(targetPath) { - context.fileList.copy(filename, targetPath); - }, false, "httpd/unix-directory", true); + OC.dialogs.filepicker(t('files', 'Target folder'), function(targetPath, type) { + if (type === OC.dialogs.FILEPICKER_TYPE_COPY) { + context.fileList.copy(filename, targetPath); + } + if (type === OC.dialogs.FILEPICKER_TYPE_MOVE) { + context.fileList.move(filename, targetPath); + } + }, false, "httpd/unix-directory", true, OC.dialogs.FILEPICKER_TYPE_COPY_MOVE); } }); diff --git a/apps/files/js/filelist.js b/apps/files/js/filelist.js index 946ac125484..d67cb409b1e 100644 --- a/apps/files/js/filelist.js +++ b/apps/files/js/filelist.js @@ -337,11 +337,7 @@ this.$el.on('urlChanged', _.bind(this._onUrlChanged, this)); this.$el.find('.select-all').click(_.bind(this._onClickSelectAll, this)); this.$el.find('.download').click(_.bind(this._onClickDownloadSelected, this)); -<<<<<<< HEAD - this.$el.find('.move').click(_.bind(this._onClickMoveSelected, this)); -======= - this.$el.find('.copy').click(_.bind(this._onClickCopySelected, this)); ->>>>>>> Allow files to be copied through action menu & multiple files actions + this.$el.find('.copy-move').click(_.bind(this._onClickCopyMoveSelected, this)); this.$el.find('.delete-selected').click(_.bind(this._onClickDeleteSelected, this)); this.$el.find('.selectedActions a').tooltip({placement:'top'}); @@ -765,7 +761,7 @@ /** * Event handler for when clicking on "Move" for the selected files */ - _onClickMoveSelected: function(event) { + _onClickCopyMoveSelected: function(event) { var files; var self = this; @@ -783,10 +779,14 @@ OCA.Files.FileActions.updateFileActionSpinner(moveFileAction, false); }; - OCA.Files.FileActions.updateFileActionSpinner(moveFileAction, true); - OC.dialogs.filepicker(t('files', 'Target folder'), function(targetPath) { - self.move(files, targetPath, disableLoadingState); - }, false, "httpd/unix-directory", true); + OC.dialogs.filepicker(t('files', 'Target folder'), function(targetPath, type) { + if (type === OC.dialogs.FILEPICKER_TYPE_COPY) { + self.copy(files, targetPath, disableLoadingState); + } + if (type === OC.dialogs.FILEPICKER_TYPE_MOVE) { + self.move(files, targetPath, disableLoadingState); + } + }, false, "httpd/unix-directory", true, OC.dialogs.FILEPICKER_TYPE_COPY_MOVE); return false; }, diff --git a/apps/files/templates/list.php b/apps/files/templates/list.php index 67c330c38c7..3857ad3badd 100644 --- a/apps/files/templates/list.php +++ b/apps/files/templates/list.php @@ -47,9 +47,9 @@ t( 'Name' )); ?> - + - t('Move'))?> + t('Copy or Move'))?> diff --git a/core/css/jquery.ocdialog.css b/core/css/jquery.ocdialog.css index 487bc1c4f69..2100a3db7a6 100644 --- a/core/css/jquery.ocdialog.css +++ b/core/css/jquery.ocdialog.css @@ -38,6 +38,9 @@ .oc-dialog-buttonrow.twobuttons button:nth-child(1) { float: left; } +.oc-dialog-buttonrow.twobuttons.aside button:nth-child(1) { + float: none; +} .oc-dialog-buttonrow.twobuttons button:nth-child(2) { float: right; } diff --git a/core/js/jquery.ocdialog.js b/core/js/jquery.ocdialog.js index b54cce2c0ca..555b35e59ff 100644 --- a/core/js/jquery.ocdialog.js +++ b/core/js/jquery.ocdialog.js @@ -130,6 +130,11 @@ }); this._setSizes(); break; + case 'style': + if (value.buttons !== undefined) { + this.$buttonrow.addClass(value.buttons); + } + break; case 'closeButton': if(value) { var $closeButton = $(''); diff --git a/core/js/oc-dialogs.js b/core/js/oc-dialogs.js index 5fc224e38bf..f81ead06216 100644 --- a/core/js/oc-dialogs.js +++ b/core/js/oc-dialogs.js @@ -29,6 +29,12 @@ var OCdialogs = { // dialog button types YES_NO_BUTTONS: 70, OK_BUTTONS: 71, + + FILEPICKER_TYPE_CHOOSE: 1, + FILEPICKER_TYPE_MOVE: 2, + FILEPICKER_TYPE_COPY: 3, + FILEPICKER_TYPE_COPY_MOVE: 4, + // used to name each dialog dialogsCounter: 0, /** @@ -174,13 +180,19 @@ var OCdialogs = { * @param multiselect whether it should be possible to select multiple files * @param mimetypeFilter mimetype to filter by - directories will always be included * @param modal make the dialog modal + * @param type Type of file picker : Choose, copy, move, copy and move */ - filepicker:function(title, callback, multiselect, mimetypeFilter, modal) { + filepicker:function(title, callback, multiselect, mimetypeFilter, modal, type) { var self = this; // avoid opening the picker twice if (this.filepicker.loading) { return; } + + if (type === undefined) { + type = this.FILEPICKER_TYPE_CHOOSE; + } + this.filepicker.loading = true; this.filepicker.filesClient = (OCA.Sharing && OCA.Sharing.PublicApp && OCA.Sharing.PublicApp.fileList)? OCA.Sharing.PublicApp.fileList.filesClient: OC.Files.getClient(); $.when(this._getFilePickerTemplate()).then(function($tmpl) { @@ -210,15 +222,17 @@ var OCdialogs = { self.$filePicker.ready(function() { self.$filelist = self.$filePicker.find('.filelist tbody'); self.$dirTree = self.$filePicker.find('.dirtree'); - self.$dirTree.on('click', 'div:not(:last-child)', self, self._handleTreeListSelect.bind(self)); + self.$dirTree.on('click', 'div:not(:last-child)', self, function (event) { + self._handleTreeListSelect(event, type); + }); self.$filelist.on('click', 'tr', function(event) { - self._handlePickerClick(event, $(this)); + self._handlePickerClick(event, $(this), type); }); self._fillFilePicker(''); }); // build buttons - var functionToCall = function() { + var functionToCall = function(returnType) { if (callback !== undefined) { var datapath; if (multiselect === true) { @@ -233,15 +247,47 @@ var OCdialogs = { datapath += '/' + selectedName; } } - callback(datapath); + callback(datapath, returnType); self.$filePicker.ocdialog('close'); } }; - var buttonlist = [{ - text: t('core', 'Choose'), - click: functionToCall, - defaultButton: true - }]; + + var chooseCallback = function () { + functionToCall(OCdialogs.FILEPICKER_TYPE_CHOOSE); + }; + + var copyCallback = function () { + console.log('copy callback'); + functionToCall(OCdialogs.FILEPICKER_TYPE_COPY); + }; + + var moveCallback = function () { + functionToCall(OCdialogs.FILEPICKER_TYPE_MOVE); + }; + + var buttonlist = []; + if (type === OCdialogs.FILEPICKER_TYPE_CHOOSE) { + buttonlist.push({ + text: t('core', 'Choose'), + click: chooseCallback, + defaultButton: true + }); + } else { + if (type === OCdialogs.FILEPICKER_TYPE_COPY || type === OCdialogs.FILEPICKER_TYPE_COPY_MOVE) { + buttonlist.push({ + text: t('core', 'Copy'), + click: copyCallback, + defaultButton: false + }); + } + if (type === OCdialogs.FILEPICKER_TYPE_MOVE || type === OCdialogs.FILEPICKER_TYPE_COPY_MOVE) { + buttonlist.push({ + text: t('core', 'Move'), + click: moveCallback, + defaultButton: true + }); + } + } self.$filePicker.ocdialog({ closeOnEscape: true, @@ -250,6 +296,9 @@ var OCdialogs = { height: 500, modal: modal, buttons: buttonlist, + style: { + buttons: 'aside', + }, close: function() { try { $(this).ocdialog('destroy').remove(); @@ -879,12 +928,13 @@ var OCdialogs = { /** * handle selection made in the tree list */ - _handleTreeListSelect:function(event) { + _handleTreeListSelect:function(event, type) { var self = event.data; var dir = $(event.target).parent().data('dir'); self._fillFilePicker(dir); var getOcDialog = (event.target).closest('.oc-dialog'); var buttonEnableDisable = $('.primary', getOcDialog); + this._changeButtonsText(type, dir.split(/[/]+/).pop()); if (this.$filePicker.data('mimetype') === "httpd/unix-directory") { buttonEnableDisable.prop("disabled", false); } else { @@ -894,7 +944,7 @@ var OCdialogs = { /** * handle clicks made in the filepicker */ - _handlePickerClick:function(event, $element) { + _handlePickerClick:function(event, $element, type) { var getOcDialog = this.$filePicker.closest('.oc-dialog'); var buttonEnableDisable = getOcDialog.find('.primary'); if ($element.data('type') === 'file') { @@ -905,11 +955,38 @@ var OCdialogs = { buttonEnableDisable.prop("disabled", false); } else if ( $element.data('type') === 'dir' ) { this._fillFilePicker(this.$filePicker.data('path') + '/' + $element.data('entryname')); + this._changeButtonsText(type, $element.data('entryname')); if (this.$filePicker.data('mimetype') === "httpd/unix-directory") { buttonEnableDisable.prop("disabled", false); } else { buttonEnableDisable.prop("disabled", true); } } + }, + + /** + * Handle + * @param type of action + * @param dir on which to change buttons text + * @private + */ + _changeButtonsText(type, dir) { + var copyText = dir === '' ? t('core', 'Copy') : t('core', 'Copy to {folder}', {folder: dir}); + var moveText = dir === '' ? t('core', 'Move') : t('core', 'Move to {folder}', {folder: dir}); + var buttons = $('.oc-dialog-buttonrow button'); + switch (type) { + case this.FILEPICKER_TYPE_CHOOSE: + break; + case this.FILEPICKER_TYPE_COPY: + buttons.text(copyText); + break; + case this.FILEPICKER_TYPE_MOVE: + buttons.text(moveText); + break; + case this.FILEPICKER_TYPE_COPY_MOVE: + buttons.eq(0).text(copyText); + buttons.eq(1).text(moveText); + break; + } } }; -- cgit v1.2.3 From 07c1137abfb792b78b140f97811af4d96fed072c Mon Sep 17 00:00:00 2001 From: Thomas Citharel Date: Sun, 27 Aug 2017 18:01:54 +0200 Subject: typo Signed-off-by: Thomas Citharel --- core/js/oc-dialogs.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'core/js') diff --git a/core/js/oc-dialogs.js b/core/js/oc-dialogs.js index f81ead06216..902d5263d04 100644 --- a/core/js/oc-dialogs.js +++ b/core/js/oc-dialogs.js @@ -970,7 +970,7 @@ var OCdialogs = { * @param dir on which to change buttons text * @private */ - _changeButtonsText(type, dir) { + _changeButtonsText: function(type, dir) { var copyText = dir === '' ? t('core', 'Copy') : t('core', 'Copy to {folder}', {folder: dir}); var moveText = dir === '' ? t('core', 'Move') : t('core', 'Move to {folder}', {folder: dir}); var buttons = $('.oc-dialog-buttonrow button'); -- cgit v1.2.3 From 5767659d226a47d59bc6a024033e54c3741eebc7 Mon Sep 17 00:00:00 2001 From: Thomas Citharel Date: Mon, 28 Aug 2017 10:56:21 +0200 Subject: Change move copy order and debug leftover Signed-off-by: Thomas Citharel --- apps/files/js/fileactions.js | 4 ++-- apps/files/templates/list.php | 2 +- core/js/oc-dialogs.js | 1 - 3 files changed, 3 insertions(+), 4 deletions(-) (limited to 'core/js') diff --git a/apps/files/js/fileactions.js b/apps/files/js/fileactions.js index 668960d5937..3da9b06b0d3 100644 --- a/apps/files/js/fileactions.js +++ b/apps/files/js/fileactions.js @@ -618,8 +618,8 @@ }); this.registerAction({ - name: 'CopyMove', - displayName: t('files', 'Copy or Move'), + name: 'MoveCopy', + displayName: t('files', 'Move or copy'), mime: 'all', order: -25, permissions: OC.PERMISSION_UPDATE, diff --git a/apps/files/templates/list.php b/apps/files/templates/list.php index 3857ad3badd..f3b6759644c 100644 --- a/apps/files/templates/list.php +++ b/apps/files/templates/list.php @@ -49,7 +49,7 @@ - t('Copy or Move'))?> + t('Move or copy'))?> diff --git a/core/js/oc-dialogs.js b/core/js/oc-dialogs.js index 902d5263d04..1bc1399466d 100644 --- a/core/js/oc-dialogs.js +++ b/core/js/oc-dialogs.js @@ -257,7 +257,6 @@ var OCdialogs = { }; var copyCallback = function () { - console.log('copy callback'); functionToCall(OCdialogs.FILEPICKER_TYPE_COPY); }; -- cgit v1.2.3