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.

federationscopemenu.js 3.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. /*
  2. * Copyright (c) 2016
  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. /* global OC, Handlebars */
  11. (function() {
  12. /**
  13. * Construct a new FederationScopeMenu instance
  14. * @constructs FederationScopeMenu
  15. * @memberof OC.Settings
  16. * @param {object} options
  17. * @param {array.<string>} [options.excludedScopes] array of excluded scopes
  18. */
  19. var FederationScopeMenu = OC.Backbone.View.extend({
  20. tagName: 'div',
  21. className: 'federationScopeMenu popovermenu bubble menu menu-center',
  22. field: undefined,
  23. _scopes: undefined,
  24. _excludedScopes: [],
  25. initialize: function(options) {
  26. this.field = options.field;
  27. this._scopes = [
  28. {
  29. name: 'v2-private',
  30. displayName: t('settings', 'Private'),
  31. tooltip: t('settings', 'Only visible to people matched via phone number integration through Talk on mobile'),
  32. iconClass: 'icon-phone',
  33. active: false
  34. },
  35. {
  36. name: 'v2-local',
  37. displayName: t('settings', 'Local'),
  38. tooltip: t('settings', 'Only visible to people on this instance and guests'),
  39. iconClass: 'icon-password',
  40. active: false
  41. },
  42. {
  43. name: 'v2-federated',
  44. displayName: t('settings', 'Federated'),
  45. tooltip: t('settings', 'Only synchronize to trusted servers'),
  46. iconClass: 'icon-contacts-dark',
  47. active: false
  48. },
  49. {
  50. name: 'v2-published',
  51. displayName: t('settings', 'Published'),
  52. tooltip: t('settings', 'Synchronize to trusted servers and the global and public address book'),
  53. iconClass: 'icon-link',
  54. active: false
  55. }
  56. ];
  57. if (options.excludedScopes && options.excludedScopes.length) {
  58. this._excludedScopes = options.excludedScopes
  59. }
  60. },
  61. /**
  62. * Current context
  63. *
  64. * @type OCA.Files.FileActionContext
  65. */
  66. _context: null,
  67. events: {
  68. 'click a.action': '_onSelectScope',
  69. 'keydown a.action': '_onSelectScopeKeyboard'
  70. },
  71. /**
  72. * Event handler whenever an action has been clicked within the menu
  73. *
  74. * @param {Object} event event object
  75. */
  76. _onSelectScope: function(event) {
  77. var $target = $(event.currentTarget);
  78. if (!$target.hasClass('menuitem')) {
  79. $target = $target.closest('.menuitem');
  80. }
  81. this.trigger('select:scope', $target.data('action'));
  82. OC.hideMenus();
  83. },
  84. _onSelectScopeKeyboard: function(event) {
  85. if (event.keyCode === 13 || event.keyCode === 32) {
  86. // Enter and space can be used to select a scope
  87. event.preventDefault();
  88. this._onSelectScope(event);
  89. }
  90. },
  91. /**
  92. * Renders the menu with the currently set items
  93. */
  94. render: function() {
  95. this.$el.html(OC.Settings.Templates['federationscopemenu']({
  96. items: this._scopes
  97. }));
  98. },
  99. /**
  100. * Displays the menu
  101. */
  102. show: function(context) {
  103. this._context = context;
  104. var currentlyActiveValue = $('#'+context.target.closest('form').id).find('input[type="hidden"]')[0].value;
  105. for(var i in this._scopes) {
  106. if (this._scopes[i].name === currentlyActiveValue) {
  107. this._scopes[i].active = true;
  108. } else {
  109. this._scopes[i].active = false;
  110. }
  111. var isExcludedScope = this._excludedScopes.includes(this._scopes[i].name)
  112. if (isExcludedScope && !this._scopes[i].active) {
  113. this._scopes[i].hidden = true
  114. } else if (isExcludedScope && this._scopes[i].active) {
  115. this._scopes[i].hidden = false
  116. this._scopes[i].disabled = true
  117. } else {
  118. this._scopes[i].hidden = false
  119. this._scopes[i].disabled = false
  120. }
  121. }
  122. this.render();
  123. this.$el.removeClass('hidden');
  124. OC.showMenu(null, this.$el);
  125. }
  126. });
  127. OC.Settings = OC.Settings || {};
  128. OC.Settings.FederationScopeMenu = FederationScopeMenu;
  129. })();