You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

filemultiselectmenu.js 2.6KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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.$el.removeClass('hidden');
  38. if (window.innerWidth < 480) {
  39. this.$el.removeClass('menu-center').addClass('menu-right');
  40. } else {
  41. this.$el.removeClass('menu-right').addClass('menu-center');
  42. }
  43. OC.showMenu(null, this.$el);
  44. return false;
  45. },
  46. toggleItemVisibility: function (itemName, show) {
  47. if (show) {
  48. this.$el.find('.item-' + itemName).removeClass('hidden');
  49. } else {
  50. this.$el.find('.item-' + itemName).addClass('hidden');
  51. }
  52. },
  53. updateItemText: function (itemName, translation) {
  54. this.$el.find('.item-' + itemName).find('.label').text(translation);
  55. },
  56. toggleLoading: function (itemName, showLoading) {
  57. var $actionElement = this.$el.find('.item-' + itemName);
  58. if ($actionElement.length === 0) {
  59. return;
  60. }
  61. var $icon = $actionElement.find('.icon');
  62. if (showLoading) {
  63. var $loadingIcon = $('<span class="icon icon-loading-small"></span>');
  64. $icon.after($loadingIcon);
  65. $icon.addClass('hidden');
  66. $actionElement.addClass('disabled');
  67. } else {
  68. $actionElement.find('.icon-loading-small').remove();
  69. $actionElement.find('.icon').removeClass('hidden');
  70. $actionElement.removeClass('disabled');
  71. }
  72. },
  73. isDisabled: function (itemName) {
  74. var $actionElement = this.$el.find('.item-' + itemName);
  75. return $actionElement.hasClass('disabled');
  76. },
  77. /**
  78. * Event handler whenever an action has been clicked within the menu
  79. *
  80. * @param {Object} event event object
  81. */
  82. _onClickAction: function (event) {
  83. var $target = $(event.currentTarget);
  84. if (!$target.hasClass('menuitem')) {
  85. $target = $target.closest('.menuitem');
  86. }
  87. OC.hideMenus();
  88. this._context.multiSelectMenuClick(event, $target.data('action'));
  89. return false;
  90. }
  91. });
  92. OCA.Files.FileMultiSelectMenu = FileMultiSelectMenu;
  93. })(OC, OCA);