filemultiselectmenu.js 2.6 KB

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