filemultiselectmenu.js 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. /**
  2. * SPDX-FileCopyrightText: 2018-2024 Nextcloud GmbH and Nextcloud contributors
  3. * SPDX-License-Identifier: AGPL-3.0-or-later
  4. */
  5. (function() {
  6. var FileMultiSelectMenu = OC.Backbone.View.extend({
  7. tagName: 'div',
  8. className: 'filesSelectMenu popovermenu bubble menu-center',
  9. _scopes: null,
  10. initialize: function(menuItems) {
  11. this._scopes = menuItems;
  12. },
  13. events: {
  14. 'click a.action': '_onClickAction'
  15. },
  16. /**
  17. * Renders the menu with the currently set items
  18. */
  19. render: function() {
  20. this.$el.html(OCA.Files.Templates['filemultiselectmenu']({
  21. items: this._scopes
  22. }));
  23. },
  24. /**
  25. * Displays the menu under the given element
  26. *
  27. * @param {OCA.Files.FileActionContext} context context
  28. * @param {Object} $trigger trigger element
  29. */
  30. show: function(context) {
  31. this._context = context;
  32. this.$el.removeClass('hidden');
  33. if (window.innerWidth < 480) {
  34. this.$el.removeClass('menu-center').addClass('menu-right');
  35. } else {
  36. this.$el.removeClass('menu-right').addClass('menu-center');
  37. }
  38. OC.showMenu(null, this.$el);
  39. return false;
  40. },
  41. toggleItemVisibility: function (itemName, show) {
  42. if (show) {
  43. this.$el.find('.item-' + itemName).removeClass('hidden');
  44. } else {
  45. this.$el.find('.item-' + itemName).addClass('hidden');
  46. }
  47. },
  48. updateItemText: function (itemName, translation) {
  49. this.$el.find('.item-' + itemName).find('.label').text(translation);
  50. },
  51. toggleLoading: function (itemName, showLoading) {
  52. var $actionElement = this.$el.find('.item-' + itemName);
  53. if ($actionElement.length === 0) {
  54. return;
  55. }
  56. var $icon = $actionElement.find('.icon');
  57. if (showLoading) {
  58. var $loadingIcon = $('<span class="icon icon-loading-small"></span>');
  59. $icon.after($loadingIcon);
  60. $icon.addClass('hidden');
  61. $actionElement.addClass('disabled');
  62. } else {
  63. $actionElement.find('.icon-loading-small').remove();
  64. $actionElement.find('.icon').removeClass('hidden');
  65. $actionElement.removeClass('disabled');
  66. }
  67. },
  68. isDisabled: function (itemName) {
  69. var $actionElement = this.$el.find('.item-' + itemName);
  70. return $actionElement.hasClass('disabled');
  71. },
  72. /**
  73. * Event handler whenever an action has been clicked within the menu
  74. *
  75. * @param {Object} event event object
  76. */
  77. _onClickAction: function (event) {
  78. var $target = $(event.currentTarget);
  79. if (!$target.hasClass('menuitem')) {
  80. $target = $target.closest('.menuitem');
  81. }
  82. OC.hideMenus();
  83. this._context.multiSelectMenuClick(event, $target.data('action'));
  84. return false;
  85. }
  86. });
  87. OCA.Files.FileMultiSelectMenu = FileMultiSelectMenu;
  88. })(OC, OCA);