2018-05-28 01:49:01 +00:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2018
|
|
|
|
*
|
|
|
|
* This file is licensed under the Affero General Public License version 3
|
|
|
|
* or later.
|
|
|
|
*
|
|
|
|
* See the COPYING-README file.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
(function() {
|
2018-06-02 15:15:19 +00:00
|
|
|
var FileMultiSelectMenu = OC.Backbone.View.extend({
|
2018-05-28 01:49:01 +00:00
|
|
|
tagName: 'div',
|
|
|
|
className: 'filesSelectMenu popovermenu bubble menu-center',
|
|
|
|
_scopes: null,
|
|
|
|
initialize: function(menuItems) {
|
|
|
|
this._scopes = menuItems;
|
|
|
|
},
|
|
|
|
events: {
|
|
|
|
'click a.action': '_onClickAction'
|
|
|
|
},
|
2018-10-01 08:52:56 +00:00
|
|
|
|
2018-05-28 01:49:01 +00:00
|
|
|
/**
|
|
|
|
* Renders the menu with the currently set items
|
|
|
|
*/
|
|
|
|
render: function() {
|
2018-10-01 08:52:56 +00:00
|
|
|
this.$el.html(OCA.Files.Templates['filemultiselectmenu']({
|
2018-05-28 01:49:01 +00:00
|
|
|
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');
|
2018-06-02 15:15:19 +00:00
|
|
|
if (window.innerWidth < 480) {
|
|
|
|
this.$el.removeClass('menu-center').addClass('menu-right');
|
|
|
|
} else {
|
|
|
|
this.$el.removeClass('menu-right').addClass('menu-center');
|
|
|
|
}
|
2018-05-28 01:49:01 +00:00
|
|
|
OC.showMenu(null, this.$el);
|
|
|
|
return false;
|
|
|
|
},
|
2018-06-06 18:01:25 +00:00
|
|
|
toggleItemVisibility: function (itemName, show) {
|
|
|
|
if (show) {
|
|
|
|
this.$el.find('.item-' + itemName).removeClass('hidden');
|
|
|
|
} else {
|
|
|
|
this.$el.find('.item-' + itemName).addClass('hidden');
|
|
|
|
}
|
2018-05-28 01:49:01 +00:00
|
|
|
},
|
|
|
|
updateItemText: function (itemName, translation) {
|
2018-06-06 18:01:25 +00:00
|
|
|
this.$el.find('.item-' + itemName).find('.label').text(translation);
|
2018-06-02 15:15:19 +00:00
|
|
|
},
|
|
|
|
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;
|
2018-05-28 01:49:01 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2018-06-02 15:15:19 +00:00
|
|
|
OCA.Files.FileMultiSelectMenu = FileMultiSelectMenu;
|
|
|
|
})(OC, OCA);
|