federationscopemenu.js 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  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. */
  17. var FederationScopeMenu = OC.Backbone.View.extend({
  18. tagName: 'div',
  19. className: 'federationScopeMenu popovermenu bubble menu menu-center',
  20. field: undefined,
  21. _scopes: undefined,
  22. initialize: function(options) {
  23. this.field = options.field;
  24. this._scopes = [
  25. {
  26. name: 'private',
  27. displayName: (this.field === 'avatar' || this.field === 'displayname') ? t('settings', 'Local') : t('settings', 'Private'),
  28. tooltip: (this.field === 'avatar' || this.field === 'displayname') ? t('settings', 'Only visible to local users') : t('settings', 'Only visible to you'),
  29. iconClass: 'icon-password',
  30. active: false
  31. },
  32. {
  33. name: 'contacts',
  34. displayName: t('settings', 'Contacts'),
  35. tooltip: t('settings', 'Visible to local users and to trusted servers'),
  36. iconClass: 'icon-contacts-dark',
  37. active: false
  38. },
  39. {
  40. name: 'public',
  41. displayName: t('settings', 'Public'),
  42. tooltip: t('settings', 'Will be synced to a global and public address book'),
  43. iconClass: 'icon-link',
  44. active: false
  45. }
  46. ];
  47. },
  48. /**
  49. * Current context
  50. *
  51. * @type OCA.Files.FileActionContext
  52. */
  53. _context: null,
  54. events: {
  55. 'click a.action': '_onClickAction'
  56. },
  57. /**
  58. * Event handler whenever an action has been clicked within the menu
  59. *
  60. * @param {Object} event event object
  61. */
  62. _onClickAction: function(event) {
  63. var $target = $(event.currentTarget);
  64. if (!$target.hasClass('menuitem')) {
  65. $target = $target.closest('.menuitem');
  66. }
  67. this.trigger('select:scope', $target.data('action'));
  68. OC.hideMenus();
  69. },
  70. /**
  71. * Renders the menu with the currently set items
  72. */
  73. render: function() {
  74. this.$el.html(OC.Settings.Templates['federationscopemenu']({
  75. items: this._scopes
  76. }));
  77. },
  78. /**
  79. * Displays the menu
  80. */
  81. show: function(context) {
  82. this._context = context;
  83. var currentlyActiveValue = $('#'+context.target.closest('form').id).find('input[type="hidden"]')[0].value;
  84. for(var i in this._scopes) {
  85. this._scopes[i].active = false;
  86. }
  87. switch (currentlyActiveValue) {
  88. case "private":
  89. this._scopes[0].active = true;
  90. break;
  91. case "contacts":
  92. this._scopes[1].active = true;
  93. break;
  94. case "public":
  95. this._scopes[2].active = true;
  96. break;
  97. }
  98. this.render();
  99. this.$el.removeClass('hidden');
  100. OC.showMenu(null, this.$el);
  101. }
  102. });
  103. OC.Settings = OC.Settings || {};
  104. OC.Settings.FederationScopeMenu = FederationScopeMenu;
  105. })();