0
0
Fork 0
mirror of https://github.com/nextcloud/server.git synced 2025-02-07 09:59:46 +00:00
nextcloud_server/apps/settings/js/federationscopemenu.js
Daniel Calviño Sánchez da84ed7d4c Fix active scope not visible in the menu if excluded
Depending on some settings (for example, if lookup server upload is
disabled) some items can be hidden in the scope menu. However, if the
user selected an scope in the past once the settings were changed the
scope was no longer visible in the menu. Now the active scope will be
always visible in the menu, although if it is an excluded scope it will
be disabled. Selecting any other scope will then hide the excluded and
no longer active one.

When upload to the lookup server is disabled the scope menu was hidden
for display name and email in the personal information settings; now the
menu will be always shown to enable the above described behaviour.

Note that the menu will be shown even if there is a single available
scope so the user can read its description.

Signed-off-by: Daniel Calviño Sánchez <danxuliu@gmail.com>
2021-04-23 11:44:42 +02:00

147 lines
3.6 KiB
JavaScript

/*
* Copyright (c) 2016
*
* This file is licensed under the Affero General Public License version 3
* or later.
*
* See the COPYING-README file.
*
*/
/* global OC, Handlebars */
(function() {
/**
* Construct a new FederationScopeMenu instance
* @constructs FederationScopeMenu
* @memberof OC.Settings
* @param {object} options
* @param {array.<string>} [options.excludedScopes] array of excluded scopes
*/
var FederationScopeMenu = OC.Backbone.View.extend({
tagName: 'div',
className: 'federationScopeMenu popovermenu bubble menu menu-center',
field: undefined,
_scopes: undefined,
_excludedScopes: [],
initialize: function(options) {
this.field = options.field;
this._scopes = [
{
name: 'v2-private',
displayName: t('settings', 'Private'),
tooltip: t('settings', 'Only visible to people matched via phone number integration through Talk on mobile'),
iconClass: 'icon-phone',
active: false
},
{
name: 'v2-local',
displayName: t('settings', 'Local'),
tooltip: t('settings', 'Only visible to people on this instance and guests'),
iconClass: 'icon-password',
active: false
},
{
name: 'v2-federated',
displayName: t('settings', 'Federated'),
tooltip: t('settings', 'Only synchronize to trusted servers'),
iconClass: 'icon-contacts-dark',
active: false
},
{
name: 'v2-published',
displayName: t('settings', 'Published'),
tooltip: t('settings', 'Synchronize to trusted servers and the global and public address book'),
iconClass: 'icon-link',
active: false
}
];
if (options.excludedScopes && options.excludedScopes.length) {
this._excludedScopes = options.excludedScopes
}
},
/**
* Current context
*
* @type OCA.Files.FileActionContext
*/
_context: null,
events: {
'click a.action': '_onSelectScope',
'keydown a.action': '_onSelectScopeKeyboard'
},
/**
* Event handler whenever an action has been clicked within the menu
*
* @param {Object} event event object
*/
_onSelectScope: function(event) {
var $target = $(event.currentTarget);
if (!$target.hasClass('menuitem')) {
$target = $target.closest('.menuitem');
}
this.trigger('select:scope', $target.data('action'));
OC.hideMenus();
},
_onSelectScopeKeyboard: function(event) {
if (event.keyCode === 13 || event.keyCode === 32) {
// Enter and space can be used to select a scope
event.preventDefault();
this._onSelectScope(event);
}
},
/**
* Renders the menu with the currently set items
*/
render: function() {
this.$el.html(OC.Settings.Templates['federationscopemenu']({
items: this._scopes
}));
},
/**
* Displays the menu
*/
show: function(context) {
this._context = context;
var currentlyActiveValue = $('#'+context.target.closest('form').id).find('input[type="hidden"]')[0].value;
for(var i in this._scopes) {
if (this._scopes[i].name === currentlyActiveValue) {
this._scopes[i].active = true;
} else {
this._scopes[i].active = false;
}
var isExcludedScope = this._excludedScopes.includes(this._scopes[i].name)
if (isExcludedScope && !this._scopes[i].active) {
this._scopes[i].hidden = true
} else if (isExcludedScope && this._scopes[i].active) {
this._scopes[i].hidden = false
this._scopes[i].disabled = true
} else {
this._scopes[i].hidden = false
this._scopes[i].disabled = false
}
}
this.render();
this.$el.removeClass('hidden');
OC.showMenu(null, this.$el);
}
});
OC.Settings = OC.Settings || {};
OC.Settings.FederationScopeMenu = FederationScopeMenu;
})();