aboutsummaryrefslogtreecommitdiffstats
path: root/apps/files/js
diff options
context:
space:
mode:
Diffstat (limited to 'apps/files/js')
-rw-r--r--apps/files/js/app.js19
-rw-r--r--apps/files/js/fileactions.js12
-rw-r--r--apps/files/js/filelist.js89
-rw-r--r--apps/files/js/filemultiselectmenu.js112
-rw-r--r--apps/files/js/merged-index.json1
5 files changed, 193 insertions, 40 deletions
diff --git a/apps/files/js/app.js b/apps/files/js/app.js
index 6e4e8c1b136..6a21bce975b 100644
--- a/apps/files/js/app.js
+++ b/apps/files/js/app.js
@@ -88,6 +88,23 @@
allowLegacyActions: true,
scrollTo: urlParams.scrollto,
filesClient: OC.Files.getClient(),
+ multiSelectMenu: [
+ {
+ name: 'copyMove',
+ displayName: t('files', 'Move or copy'),
+ iconClass: 'icon-external',
+ },
+ {
+ name: 'download',
+ displayName: t('files', 'Download'),
+ iconClass: 'icon-download',
+ },
+ {
+ name: 'delete',
+ displayName: t('files', 'Delete'),
+ iconClass: 'icon-delete',
+ }
+ ],
sorting: {
mode: $('#defaultFileSorting').val(),
direction: $('#defaultFileSortingDirection').val()
@@ -130,7 +147,7 @@
window.FileActions.off('registerAction.app-files', this._onActionsUpdated);
},
- _onActionsUpdated: function(ev, newAction) {
+ _onActionsUpdated: function(ev) {
// forward new action to the file list
if (ev.action) {
this.fileList.fileActions.registerAction(ev.action);
diff --git a/apps/files/js/fileactions.js b/apps/files/js/fileactions.js
index 4c0ccaf6451..3623663ed6c 100644
--- a/apps/files/js/fileactions.js
+++ b/apps/files/js/fileactions.js
@@ -692,21 +692,21 @@
OCA.Files.FileActions = FileActions;
/**
- * Replaces the download icon with a loading spinner and vice versa
+ * Replaces the button icon with a loading spinner and vice versa
* - also adds the class disabled to the passed in element
*
- * @param {jQuery} $downloadButtonElement download fileaction
+ * @param {jQuery} $buttonElement The button element
* @param {boolean} showIt whether to show the spinner(true) or to hide it(false)
*/
- OCA.Files.FileActions.updateFileActionSpinner = function($downloadButtonElement, showIt) {
- var $icon = $downloadButtonElement.find('.icon');
+ OCA.Files.FileActions.updateFileActionSpinner = function($buttonElement, showIt) {
+ var $icon = $buttonElement.find('.icon');
if (showIt) {
var $loadingIcon = $('<span class="icon icon-loading-small"></span>');
$icon.after($loadingIcon);
$icon.addClass('hidden');
} else {
- $downloadButtonElement.find('.icon-loading-small').remove();
- $downloadButtonElement.find('.icon').removeClass('hidden');
+ $buttonElement.find('.icon-loading-small').remove();
+ $buttonElement.find('.icon').removeClass('hidden');
}
};
diff --git a/apps/files/js/filelist.js b/apps/files/js/filelist.js
index 307147076b2..c420e7212a0 100644
--- a/apps/files/js/filelist.js
+++ b/apps/files/js/filelist.js
@@ -126,7 +126,11 @@
* @type OCA.Files.FileActions
*/
fileActions: null,
-
+ /**
+ * File selection menu, defaults to OCA.Files.FileSelectionMenu
+ * @type OCA.Files.FileSelectionMenu
+ */
+ fileMultiSelectMenu: null,
/**
* Whether selection is allowed, checkboxes and selection overlay will
* be rendered
@@ -288,6 +292,12 @@
this.fileSummary = this._createSummary();
+ if (options.multiSelectMenu) {
+ this.fileMultiSelectMenu = new OCA.Files.FileMultiSelectMenu(options.multiSelectMenu);
+ this.fileMultiSelectMenu.render();
+ this.$el.find('.selectedActions').append(this.fileMultiSelectMenu.$el);
+ }
+
if (options.sorting) {
this.setSort(options.sorting.mode, options.sorting.direction, false, false);
} else {
@@ -336,11 +346,10 @@
this.$el.on('show', _.bind(this._onShow, this));
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));
- 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'});
+ this.$el.find('.actions-selected').click(function () {
+ self.fileMultiSelectMenu.show(self);
+ return false;
+ });
this.$container.on('scroll', _.bind(this._onScroll, this));
@@ -365,6 +374,7 @@
}
}
+
OC.Plugins.attach('OCA.Files.FileList', this);
},
@@ -388,6 +398,22 @@
$('#app-content').off('appresized', this._onResize);
},
+ multiSelectMenuClick: function (ev, action) {
+ switch (action) {
+ case 'delete':
+ this._onClickDeleteSelected(ev)
+ break;
+ case 'download':
+ this._onClickDownloadSelected(ev);
+ break;
+ case 'copyMove':
+ this._onClickCopyMoveSelected(ev);
+ break;
+ case 'restore':
+ this._onClickRestoreSelected(ev);
+ break;
+ }
+ },
/**
* Initializes the file actions, set up listeners.
*
@@ -745,7 +771,9 @@
*/
_onClickDownloadSelected: function(event) {
var files;
+ var self = this;
var dir = this.getCurrentDirectory();
+
if (this.isAllSelected() && this.getSelectedFiles().length > 1) {
files = OC.basename(dir);
dir = OC.dirname(dir) || '/';
@@ -754,19 +782,16 @@
files = _.pluck(this.getSelectedFiles(), 'name');
}
- var downloadFileaction = $('#selectedActionsList').find('.download');
-
// don't allow a second click on the download action
- if(downloadFileaction.hasClass('disabled')) {
- event.preventDefault();
- return;
+ if(this.fileMultiSelectMenu.isDisabled('download')) {
+ return false;
}
+ this.fileMultiSelectMenu.toggleLoading('download', true);
var disableLoadingState = function(){
- OCA.Files.FileActions.updateFileActionSpinner(downloadFileaction, false);
+ self.fileMultiSelectMenu.toggleLoading('download', false);
};
- OCA.Files.FileActions.updateFileActionSpinner(downloadFileaction, true);
if(this.getSelectedFiles().length > 1) {
OCA.Files.Files.handleDownload(this.getDownloadUrl(files, dir, true), disableLoadingState);
}
@@ -774,7 +799,7 @@
var first = this.getSelectedFiles()[0];
OCA.Files.Files.handleDownload(this.getDownloadUrl(first.name, dir, true), disableLoadingState);
}
- return false;
+ event.preventDefault();
},
/**
@@ -786,20 +811,18 @@
files = _.pluck(this.getSelectedFiles(), 'name');
- var moveFileAction = $('#selectedActionsList').find('.move');
-
// don't allow a second click on the download action
- if(moveFileAction.hasClass('disabled')) {
- event.preventDefault();
- return;
+ if(this.fileMultiSelectMenu.isDisabled('copyMove')) {
+ return false;
}
var disableLoadingState = function(){
- OCA.Files.FileActions.updateFileActionSpinner(moveFileAction, false);
+ self.fileMultiSelectMenu.toggleLoading('copyMove', false);
};
var actions = this.isSelectedMovable() ? OC.dialogs.FILEPICKER_TYPE_COPY_MOVE : OC.dialogs.FILEPICKER_TYPE_COPY;
OC.dialogs.filepicker(t('files', 'Target folder'), function(targetPath, type) {
+ self.fileMultiSelectMenu.toggleLoading('copyMove', true);
if (type === OC.dialogs.FILEPICKER_TYPE_COPY) {
self.copy(files, targetPath, disableLoadingState);
}
@@ -807,7 +830,7 @@
self.move(files, targetPath, disableLoadingState);
}
}, false, "httpd/unix-directory", true, actions);
- return false;
+ event.preventDefault();
},
/**
@@ -820,7 +843,6 @@
}
this.do_delete(files);
event.preventDefault();
- return false;
},
/**
@@ -2885,19 +2907,20 @@
this.$el.find('#headerName a.name>span:first').text(selection);
this.$el.find('#modified a>span:first').text('');
this.$el.find('table').addClass('multiselect');
- this.$el.find('.selectedActions .download').toggleClass('hidden', !this.isSelectedDownloadable());
- this.$el.find('.delete-selected').toggleClass('hidden', !this.isSelectedDeletable());
-
- var $copyMove = this.$el.find('.selectedActions .copy-move');
- if (this.isSelectedCopiable()) {
- $copyMove.toggleClass('hidden', false);
- if (this.isSelectedMovable()) {
- $copyMove.find('.label').text(t('files', 'Move or copy'));
+
+ if (this.fileMultiSelectMenu) {
+ this.fileMultiSelectMenu.toggleItemVisibility('download', this.isSelectedDownloadable());
+ this.fileMultiSelectMenu.toggleItemVisibility('delete', this.isSelectedDeletable());
+ this.fileMultiSelectMenu.toggleItemVisibility('copyMove', this.isSelectedCopiable());
+ if (this.isSelectedCopiable()) {
+ if (this.isSelectedMovable()) {
+ this.fileMultiSelectMenu.updateItemText('copyMove', t('files', 'Move or copy'));
+ } else {
+ this.fileMultiSelectMenu.updateItemText('copyMove', t('files', 'Copy'));
+ }
} else {
- $copyMove.find('.label').text(t('files', 'Copy'));
+ this.fileMultiSelectMenu.toggleItemVisibility('copyMove', false);
}
- } else {
- $copyMove.toggleClass('hidden', true);
}
}
},
diff --git a/apps/files/js/filemultiselectmenu.js b/apps/files/js/filemultiselectmenu.js
new file mode 100644
index 00000000000..d587d1fbdb2
--- /dev/null
+++ b/apps/files/js/filemultiselectmenu.js
@@ -0,0 +1,112 @@
+/*
+ * Copyright (c) 2018
+ *
+ * This file is licensed under the Affero General Public License version 3
+ * or later.
+ *
+ * See the COPYING-README file.
+ *
+ */
+
+(function() {
+ var TEMPLATE_MENU =
+ '<ul>' +
+ '{{#each items}}' +
+ '<li class="item-{{name}}">' +
+ '<a href="#" class="menuitem action {{name}} permanent" data-action="{{name}}">' +
+ '{{#if iconClass}}' +
+ '<span class="icon {{iconClass}}"></span>' +
+ '{{else}}' +
+ '<span class="no-icon"></span>' +
+ '{{/if}}' +
+ '<span class="label">{{displayName}}</span>' +
+ '</a></li>' +
+ '{{/each}}' +
+ '</ul>';
+
+ var FileMultiSelectMenu = OC.Backbone.View.extend({
+ tagName: 'div',
+ className: 'filesSelectMenu popovermenu bubble menu-center',
+ _scopes: null,
+ initialize: function(menuItems) {
+ this._scopes = menuItems;
+ },
+ events: {
+ 'click a.action': '_onClickAction'
+ },
+ template: Handlebars.compile(TEMPLATE_MENU),
+ /**
+ * Renders the menu with the currently set items
+ */
+ render: function() {
+ this.$el.html(this.template({
+ items: this._scopes
+ }));
+ },
+ /**
+ * Displays the menu under the given element
+ *
+ * @param {OCA.Files.FileActionContext} context context
+ * @param {Object} $trigger trigger element
+ */
+ show: function(context) {
+ this._context = context;
+ this.$el.removeClass('hidden');
+ if (window.innerWidth < 480) {
+ this.$el.removeClass('menu-center').addClass('menu-right');
+ } else {
+ this.$el.removeClass('menu-right').addClass('menu-center');
+ }
+ OC.showMenu(null, this.$el);
+ return false;
+ },
+ toggleItemVisibility: function (itemName, show) {
+ if (show) {
+ this.$el.find('.item-' + itemName).removeClass('hidden');
+ } else {
+ this.$el.find('.item-' + itemName).addClass('hidden');
+ }
+ },
+ updateItemText: function (itemName, translation) {
+ this.$el.find('.item-' + itemName).find('.label').text(translation);
+ },
+ toggleLoading: function (itemName, showLoading) {
+ var $actionElement = this.$el.find('.item-' + itemName);
+ if ($actionElement.length === 0) {
+ return;
+ }
+ var $icon = $actionElement.find('.icon');
+ if (showLoading) {
+ var $loadingIcon = $('<span class="icon icon-loading-small"></span>');
+ $icon.after($loadingIcon);
+ $icon.addClass('hidden');
+ $actionElement.addClass('disabled');
+ } else {
+ $actionElement.find('.icon-loading-small').remove();
+ $actionElement.find('.icon').removeClass('hidden');
+ $actionElement.removeClass('disabled');
+ }
+ },
+ isDisabled: function (itemName) {
+ var $actionElement = this.$el.find('.item-' + itemName);
+ return $actionElement.hasClass('disabled');
+ },
+ /**
+ * Event handler whenever an action has been clicked within the menu
+ *
+ * @param {Object} event event object
+ */
+ _onClickAction: function (event) {
+ var $target = $(event.currentTarget);
+ if (!$target.hasClass('menuitem')) {
+ $target = $target.closest('.menuitem');
+ }
+
+ OC.hideMenus();
+ this._context.multiSelectMenuClick(event, $target.data('action'));
+ return false;
+ }
+ });
+
+ OCA.Files.FileMultiSelectMenu = FileMultiSelectMenu;
+})(OC, OCA);
diff --git a/apps/files/js/merged-index.json b/apps/files/js/merged-index.json
index 127bbb46b29..cd7e72e1a51 100644
--- a/apps/files/js/merged-index.json
+++ b/apps/files/js/merged-index.json
@@ -6,6 +6,7 @@
"jquery-visibility.js",
"fileinfomodel.js",
"filesummary.js",
+ "filemultiselectmenu.js",
"breadcrumb.js",
"filelist.js",
"search.js",