1/* 2 * Copyright (c) 2014 3 * 4 * This file is licensed under the Affero General Public License version 3 5 * or later. 6 * 7 * See the COPYING-README file. 8 * 9 */ 10 11(function() { 12 13 /** 14 * Construct a new FileActionsMenu instance 15 * @constructs FileActionsMenu 16 * @memberof OCA.Files 17 */ 18 var FileActionsMenu = OC.Backbone.View.extend({ 19 tagName: 'div', 20 className: 'fileActionsMenu popovermenu bubble hidden open menu', 21 22 /** 23 * Current context 24 * 25 * @type OCA.Files.FileActionContext 26 */ 27 _context: null, 28 29 events: { 30 'click a.action': '_onClickAction' 31 }, 32 33 template: function(data) { 34 return OCA.Files.Templates['fileactionsmenu'](data); 35 }, 36 37 /** 38 * Event handler whenever an action has been clicked within the menu 39 * 40 * @param {Object} event event object 41 */ 42 _onClickAction: function(event) { 43 var $target = $(event.target); 44 if (!$target.is('a')) { 45 $target = $target.closest('a'); 46 } 47 var fileActions = this._context.fileActions; 48 var actionName = $target.attr('data-action'); 49 var actions = fileActions.getActions( 50 fileActions.getCurrentMimeType(), 51 fileActions.getCurrentType(), 52 fileActions.getCurrentPermissions(), 53 fileActions.getCurrentFile() 54 ); 55 var actionSpec = actions[actionName]; 56 var fileName = this._context.$file.attr('data-file'); 57 58 event.stopPropagation(); 59 event.preventDefault(); 60 61 OC.hideMenus(); 62 63 actionSpec.action( 64 fileName, 65 this._context 66 ); 67 }, 68 69 /** 70 * Renders the menu with the currently set items 71 */ 72 render: function() { 73 var self = this; 74 var fileActions = this._context.fileActions; 75 var actions = fileActions.getActions( 76 fileActions.getCurrentMimeType(), 77 fileActions.getCurrentType(), 78 fileActions.getCurrentPermissions(), 79 fileActions.getCurrentFile() 80 ); 81 82 var defaultAction = fileActions.getCurrentDefaultFileAction(); 83 84 var items = _.filter(actions, function(actionSpec) { 85 if (actionSpec.shouldRender) { 86 if (!actionSpec.shouldRender(self._context)) { 87 return false; 88 } 89 } 90 91 return !defaultAction || actionSpec.name !== defaultAction.name; 92 }); 93 items = _.map(items, function(item) { 94 if (_.isFunction(item.displayName)) { 95 item = _.extend({}, item); 96 item.displayName = item.displayName(self._context); 97 } 98 if (_.isFunction(item.iconClass)) { 99 var fileName = self._context.$file.attr('data-file'); 100 item = _.extend({}, item); 101 item.iconClass = item.iconClass(fileName, self._context); 102 } 103 if (_.isFunction(item.icon)) { 104 var fileName = self._context.$file.attr('data-file'); 105 item = _.extend({}, item); 106 item.icon = item.icon(fileName, self._context); 107 } 108 item.inline = item.type === OCA.Files.FileActions.TYPE_INLINE 109 return item; 110 }); 111 items = items.sort(function(actionA, actionB) { 112 var orderA = actionA.order || 0; 113 var orderB = actionB.order || 0; 114 if (orderB === orderA) { 115 return OC.Util.naturalSortCompare(actionA.displayName, actionB.displayName); 116 } 117 return orderA - orderB; 118 }); 119 120 items = _.map(items, function(item) { 121 item.nameLowerCase = item.name.toLowerCase(); 122 return item; 123 }); 124 125 this.$el.html(this.template({ 126 items: items 127 })); 128 }, 129 130 /** 131 * Displays the menu under the given element 132 * 133 * @param {OCA.Files.FileActionContext} context context 134 * @param {Object} $trigger trigger element 135 */ 136 show: function(context) { 137 this._context = context; 138 139 this.render(); 140 this.$el.removeClass('hidden'); 141 142 window._nc_event_bus.emit('files:action-menu:opened', { 143 el: this.$el[0], 144 context, 145 }) 146 147 OC.showMenu(null, this.$el); 148 } 149 }); 150 151 OCA.Files.FileActionsMenu = FileActionsMenu; 152 153})();
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.