|
81 | 81 | if (action === 'upload') { |
82 | 82 | OC.hideMenus(); |
83 | 83 | } else { |
84 | | - event.preventDefault(); |
85 | | - this.$el.find('.menuitem.active').removeClass('active'); |
86 | | - $target.addClass('active'); |
87 | | - this._promptFileName($target); |
| 84 | + var actionItem = _.filter(this._menuItems, function(item) { |
| 85 | + return item.id === action |
| 86 | + }).pop(); |
| 87 | + if (typeof actionItem.useInput === 'undefined' || actionItem.useInput === true) { |
| 88 | + event.preventDefault(); |
| 89 | + this.$el.find('.menuitem.active').removeClass('active'); |
| 90 | + $target.addClass('active'); |
| 91 | + this._promptFileName($target); |
| 92 | + } else { |
| 93 | + actionItem.actionHandler(); |
| 94 | + OC.hideMenus(); |
| 95 | + } |
88 | 96 | } |
89 | 97 | }, |
90 | 98 |
|
|
198 | 206 | templateName: actionSpec.templateName, |
199 | 207 | iconClass: actionSpec.iconClass, |
200 | 208 | fileType: actionSpec.fileType, |
| 209 | + useInput: actionSpec.useInput, |
201 | 210 | actionHandler: actionSpec.actionHandler, |
202 | | - checkFilename: actionSpec.checkFilename |
| 211 | + checkFilename: actionSpec.checkFilename, |
| 212 | + shouldShow: actionSpec.shouldShow, |
203 | 213 | }); |
204 | 214 | }, |
205 | 215 |
|
|
220 | 230 | * Renders the menu with the currently set items |
221 | 231 | */ |
222 | 232 | render: function() { |
| 233 | + const menuItems = this._menuItems.filter(item => !item.shouldShow || (item.shouldShow instanceof Function && item.shouldShow() === true)) |
223 | 234 | this.$el.html(this.template({ |
224 | 235 | uploadMaxHumanFileSize: 'TODO', |
225 | 236 | uploadLabel: t('files', 'Upload file'), |
226 | | - items: this._menuItems |
| 237 | + items: menuItems |
227 | 238 | })); |
228 | 239 |
|
229 | 240 | // Trigger upload action also with keyboard navigation on enter |
|
0 commit comments