]> source.dussan.org Git - nextcloud-server.git/commitdiff
feat: update newfilemenu.js for rich-workspace 35474/head
authorLuka Trovic <luka@nextcloud.com>
Tue, 29 Nov 2022 05:37:32 +0000 (06:37 +0100)
committerLuka Trovic <luka@nextcloud.com>
Mon, 30 Jan 2023 19:27:16 +0000 (20:27 +0100)
Signed-off-by: Luka Trovic <luka@nextcloud.com>
apps/files/js/newfilemenu.js

index 5e6eb110e20643e04f15f2d5ebb98531e402748e..a101eccef297702b87d1dc33ed806dfc85702012 100644 (file)
                        if (action === 'upload') {
                                OC.hideMenus();
                        } else {
-                               event.preventDefault();
-                               this.$el.find('.menuitem.active').removeClass('active');
-                               $target.addClass('active');
-                               this._promptFileName($target);
+                               var actionItem = _.filter(this._menuItems, function(item) {
+                                       return item.id === action
+                               }).pop();
+                               if (typeof actionItem.useInput === 'undefined' || actionItem.useInput === true) {
+                                       event.preventDefault();
+                                       this.$el.find('.menuitem.active').removeClass('active');
+                                       $target.addClass('active');
+                                       this._promptFileName($target);
+                               } else {
+                                       actionItem.actionHandler();
+                                       OC.hideMenus();
+                               }
                        }
                },
 
                                templateName: actionSpec.templateName,
                                iconClass: actionSpec.iconClass,
                                fileType: actionSpec.fileType,
+                               useInput: actionSpec.useInput,
                                actionHandler: actionSpec.actionHandler,
-                               checkFilename: actionSpec.checkFilename
+                               checkFilename: actionSpec.checkFilename,
+                               shouldShow: actionSpec.shouldShow,
                        });
                },
 
                 * Renders the menu with the currently set items
                 */
                render: function() {
+                       const menuItems = this._menuItems.filter(item => !item.shouldShow || (item.shouldShow instanceof Function && item.shouldShow() === true))
                        this.$el.html(this.template({
                                uploadMaxHumanFileSize: 'TODO',
                                uploadLabel: t('files', 'Upload file'),
-                               items: this._menuItems
+                               items: menuItems
                        }));
 
                        // Trigger upload action also with keyboard navigation on enter