2015-07-16 16:28:45 +03:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2014
|
|
|
|
*
|
|
|
|
* 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>' +
|
2015-08-27 14:22:58 +03:00
|
|
|
'<a href="#" class="menuitem action action-{{nameLowerCase}} permanent" data-action="{{name}}">{{#if icon}}<img class="icon" src="{{icon}}"/>{{else}}<span class="no-icon"></span>{{/if}}<span>{{displayName}}</span></a>' +
|
2015-07-16 16:28:45 +03:00
|
|
|
'</li>' +
|
|
|
|
'{{/each}}' +
|
|
|
|
'</ul>';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Construct a new FileActionsMenu instance
|
|
|
|
* @constructs FileActionsMenu
|
|
|
|
* @memberof OCA.Files
|
|
|
|
*/
|
2015-08-11 12:35:46 +03:00
|
|
|
var FileActionsMenu = OC.Backbone.View.extend({
|
|
|
|
tagName: 'div',
|
2015-08-27 14:22:58 +03:00
|
|
|
className: 'fileActionsMenu popovermenu bubble hidden open menu',
|
2015-07-16 16:28:45 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Current context
|
|
|
|
*
|
|
|
|
* @type OCA.Files.FileActionContext
|
|
|
|
*/
|
|
|
|
_context: null,
|
|
|
|
|
2015-08-11 12:35:46 +03:00
|
|
|
events: {
|
|
|
|
'click a.action': '_onClickAction'
|
2015-07-16 16:28:45 +03:00
|
|
|
},
|
|
|
|
|
2015-08-11 12:35:46 +03:00
|
|
|
template: function(data) {
|
|
|
|
if (!OCA.Files.FileActionsMenu._TEMPLATE) {
|
|
|
|
OCA.Files.FileActionsMenu._TEMPLATE = Handlebars.compile(TEMPLATE_MENU);
|
|
|
|
}
|
|
|
|
return OCA.Files.FileActionsMenu._TEMPLATE(data);
|
2015-08-05 13:48:42 +03:00
|
|
|
},
|
|
|
|
|
2015-07-16 16:28:45 +03:00
|
|
|
/**
|
|
|
|
* Event handler whenever an action has been clicked within the menu
|
|
|
|
*
|
|
|
|
* @param {Object} event event object
|
|
|
|
*/
|
|
|
|
_onClickAction: function(event) {
|
|
|
|
var $target = $(event.target);
|
|
|
|
if (!$target.is('a')) {
|
|
|
|
$target = $target.closest('a');
|
|
|
|
}
|
|
|
|
var fileActions = this._context.fileActions;
|
|
|
|
var actionName = $target.attr('data-action');
|
|
|
|
var actions = fileActions.getActions(
|
|
|
|
fileActions.getCurrentMimeType(),
|
|
|
|
fileActions.getCurrentType(),
|
|
|
|
fileActions.getCurrentPermissions()
|
|
|
|
);
|
|
|
|
var actionSpec = actions[actionName];
|
|
|
|
var fileName = this._context.$file.attr('data-file');
|
|
|
|
|
|
|
|
event.stopPropagation();
|
|
|
|
event.preventDefault();
|
|
|
|
|
|
|
|
OC.hideMenus();
|
|
|
|
|
|
|
|
actionSpec.action(
|
|
|
|
fileName,
|
|
|
|
this._context
|
|
|
|
);
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Renders the menu with the currently set items
|
|
|
|
*/
|
|
|
|
render: function() {
|
|
|
|
var fileActions = this._context.fileActions;
|
|
|
|
var actions = fileActions.getActions(
|
|
|
|
fileActions.getCurrentMimeType(),
|
|
|
|
fileActions.getCurrentType(),
|
|
|
|
fileActions.getCurrentPermissions()
|
|
|
|
);
|
|
|
|
|
|
|
|
var defaultAction = fileActions.getDefaultFileAction(
|
|
|
|
fileActions.getCurrentMimeType(),
|
|
|
|
fileActions.getCurrentType(),
|
|
|
|
fileActions.getCurrentPermissions()
|
|
|
|
);
|
|
|
|
|
|
|
|
var items = _.filter(actions, function(actionSpec) {
|
|
|
|
return (
|
|
|
|
actionSpec.type === OCA.Files.FileActions.TYPE_DROPDOWN &&
|
|
|
|
(!defaultAction || actionSpec.name !== defaultAction.name)
|
|
|
|
);
|
|
|
|
});
|
|
|
|
items = _.map(items, function(item) {
|
|
|
|
item.nameLowerCase = item.name.toLowerCase();
|
|
|
|
return item;
|
|
|
|
});
|
|
|
|
|
2015-08-11 12:35:46 +03:00
|
|
|
this.$el.html(this.template({
|
2015-07-16 16:28:45 +03:00
|
|
|
items: items
|
|
|
|
}));
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Displays the menu under the given element
|
|
|
|
*
|
|
|
|
* @param {OCA.Files.FileActionContext} context context
|
2015-08-11 12:35:46 +03:00
|
|
|
* @param {Object} $trigger trigger element
|
2015-07-16 16:28:45 +03:00
|
|
|
*/
|
2015-08-11 12:35:46 +03:00
|
|
|
show: function(context) {
|
2015-07-16 16:28:45 +03:00
|
|
|
this._context = context;
|
|
|
|
|
|
|
|
this.render();
|
|
|
|
this.$el.removeClass('hidden');
|
|
|
|
|
|
|
|
OC.showMenu(null, this.$el);
|
|
|
|
}
|
2015-08-11 12:35:46 +03:00
|
|
|
});
|
2015-07-16 16:28:45 +03:00
|
|
|
|
|
|
|
OCA.Files.FileActionsMenu = FileActionsMenu;
|
|
|
|
|
|
|
|
})();
|
|
|
|
|