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.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  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. var TEMPLATE_MENU =
  13. '<ul>' +
  14. '{{#each items}}' +
  15. '<li>' +
  16. '<a href="#" class="menuitem action action-{{name}} permanent {{#if active}}active{{/if}}" data-action="{{name}}">' +
  17. '{{#if icon}}<img class="icon" src="{{icon}}"/>' +
  18. '{{else}}'+
  19. '{{#if iconClass}}' +
  20. '<span class="icon {{iconClass}}"></span>' +
  21. '{{else}}' +
  22. '<span class="no-icon"></span>' +
  23. '{{/if}}' +
  24. '{{/if}}' +
  25. '<p><strong class="menuitem-text">{{displayName}}</strong><br>' +
  26. '<span class="menuitem-text-detail">{{tooltip}}</span></p></a>' +
  27. '</li>' +
  28. '{{/each}}' +
  29. '</ul>';
  30. /**
  31. * Construct a new FederationScopeMenu instance
  32. * @constructs FederationScopeMenu
  33. * @memberof OC.Settings
  34. */
  35. var FederationScopeMenu = OC.Backbone.View.extend({
  36. tagName: 'div',
  37. className: 'federationScopeMenu popovermenu bubble hidden open menu',
  38. field: undefined,
  39. _scopes: undefined,
  40. initialize: function(options) {
  41. this.field = options.field;
  42. this._scopes = [
  43. {
  44. name: 'private',
  45. displayName: (this.field === 'avatar' || this.field === 'displayname') ? t('core', 'Local') : t('core', 'Private'),
  46. tooltip: (this.field === 'avatar' || this.field === 'displayname') ? t('core', 'Only visible to local users') : t('core', 'Only visible to you'),
  47. icon: OC.imagePath('core', 'actions/password'),
  48. active: false
  49. },
  50. {
  51. name: 'contacts',
  52. displayName: t('core', 'Contacts'),
  53. tooltip: t('core', 'Visible to local users and to trusted servers'),
  54. icon: OC.imagePath('core', 'places/contacts-dark'),
  55. active: false
  56. },
  57. {
  58. name: 'public',
  59. displayName: t('core', 'Public'),
  60. tooltip: t('core', 'Will be synced to a global and public address book'),
  61. icon: OC.imagePath('core', 'places/link'),
  62. active: false
  63. }
  64. ];
  65. },
  66. /**
  67. * Current context
  68. *
  69. * @type OCA.Files.FileActionContext
  70. */
  71. _context: null,
  72. events: {
  73. 'click a.action': '_onClickAction'
  74. },
  75. template: Handlebars.compile(TEMPLATE_MENU),
  76. /**
  77. * Event handler whenever an action has been clicked within the menu
  78. *
  79. * @param {Object} event event object
  80. */
  81. _onClickAction: function(event) {
  82. var $target = $(event.currentTarget);
  83. if (!$target.hasClass('menuitem')) {
  84. $target = $target.closest('.menuitem');
  85. }
  86. this.trigger('select:scope', $target.data('action'));
  87. OC.hideMenus();
  88. },
  89. /**
  90. * Renders the menu with the currently set items
  91. */
  92. render: function() {
  93. this.$el.html(this.template({
  94. items: this._scopes
  95. }));
  96. },
  97. /**
  98. * Displays the menu
  99. */
  100. show: function(context) {
  101. this._context = context;
  102. var currentlyActiveValue = $('#'+context.target.closest('form').id).find('.icon-checkmark > input')[0].value;
  103. for(var i in this._scopes) {
  104. this._scopes[i].active = false;
  105. }
  106. switch (currentlyActiveValue) {
  107. case "private":
  108. this._scopes[0].active = true;
  109. break;
  110. case "contacts":
  111. this._scopes[1].active = true;
  112. break;
  113. case "public":
  114. this._scopes[2].active = true;
  115. break;
  116. }
  117. var $el = $(context.target);
  118. var offsetIcon = $el.offset();
  119. var offsetHeading = $el.closest('h2').offset();
  120. this.render();
  121. this.$el.removeClass('hidden');
  122. OC.showMenu(null, this.$el);
  123. //Set the menuwidth
  124. var menuWidth = this.$el.width();
  125. this.$el.css('width', menuWidth);
  126. //Calculate menu position
  127. var l = offsetIcon.left - offsetHeading.left;
  128. l = l - (menuWidth / 2) + ($el.outerWidth()/2);
  129. this.$el.css('left', l);
  130. }
  131. });
  132. OC.Settings = OC.Settings || {};
  133. OC.Settings.FederationScopeMenu = FederationScopeMenu;
  134. })();