2016-04-20 13:19:39 +03:00
|
|
|
/*
|
|
|
|
* 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
|
2021-03-22 14:08:53 +03:00
|
|
|
* @param {object} options
|
|
|
|
* @param {array.<string>} [options.excludedScopes] array of excluded scopes
|
2016-04-20 13:19:39 +03:00
|
|
|
*/
|
|
|
|
var FederationScopeMenu = OC.Backbone.View.extend({
|
|
|
|
tagName: 'div',
|
2018-05-03 18:05:15 +03:00
|
|
|
className: 'federationScopeMenu popovermenu bubble menu menu-center',
|
2016-11-16 14:35:07 +03:00
|
|
|
field: undefined,
|
|
|
|
_scopes: undefined,
|
2021-02-01 05:34:36 +03:00
|
|
|
_excludedScopes: [],
|
2016-11-16 14:35:07 +03:00
|
|
|
|
|
|
|
initialize: function(options) {
|
|
|
|
this.field = options.field;
|
|
|
|
this._scopes = [
|
|
|
|
{
|
2021-03-22 14:08:53 +03:00
|
|
|
name: 'v2-private',
|
2020-07-09 14:53:52 +03:00
|
|
|
displayName: t('settings', 'Private'),
|
2021-03-29 18:04:32 +03:00
|
|
|
tooltip: t('settings', 'Only visible to people matched via phone number integration through Talk on mobile'),
|
|
|
|
iconClass: 'icon-phone',
|
2021-03-22 14:08:53 +03:00
|
|
|
active: false
|
|
|
|
},
|
|
|
|
{
|
2021-03-23 16:47:10 +03:00
|
|
|
name: 'v2-local',
|
2021-03-22 14:08:53 +03:00
|
|
|
displayName: t('settings', 'Local'),
|
2021-03-29 18:04:32 +03:00
|
|
|
tooltip: t('settings', 'Only visible to people on this instance and guests'),
|
2018-08-01 11:05:42 +03:00
|
|
|
iconClass: 'icon-password',
|
2016-11-18 21:44:21 +03:00
|
|
|
active: false
|
2016-11-16 14:35:07 +03:00
|
|
|
},
|
|
|
|
{
|
2021-03-23 16:47:10 +03:00
|
|
|
name: 'v2-federated',
|
|
|
|
displayName: t('settings', 'Federated'),
|
2020-07-09 14:53:52 +03:00
|
|
|
tooltip: t('settings', 'Only synchronize to trusted servers'),
|
2018-08-01 11:05:42 +03:00
|
|
|
iconClass: 'icon-contacts-dark',
|
2016-11-18 21:44:21 +03:00
|
|
|
active: false
|
2016-11-16 14:35:07 +03:00
|
|
|
},
|
|
|
|
{
|
2021-03-23 16:47:10 +03:00
|
|
|
name: 'v2-published',
|
2021-03-22 14:08:53 +03:00
|
|
|
displayName: t('settings', 'Published'),
|
2020-07-09 14:53:52 +03:00
|
|
|
tooltip: t('settings', 'Synchronize to trusted servers and the global and public address book'),
|
2018-08-01 11:05:42 +03:00
|
|
|
iconClass: 'icon-link',
|
2016-11-18 21:44:21 +03:00
|
|
|
active: false
|
2016-11-16 14:35:07 +03:00
|
|
|
}
|
|
|
|
];
|
2021-03-22 14:08:53 +03:00
|
|
|
|
2021-03-23 13:38:25 +03:00
|
|
|
if (options.excludedScopes && options.excludedScopes.length) {
|
2021-02-01 05:34:36 +03:00
|
|
|
this._excludedScopes = options.excludedScopes
|
2021-03-22 14:08:53 +03:00
|
|
|
}
|
2016-11-16 14:35:07 +03:00
|
|
|
},
|
2016-04-20 13:19:39 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Current context
|
|
|
|
*
|
|
|
|
* @type OCA.Files.FileActionContext
|
|
|
|
*/
|
|
|
|
_context: null,
|
|
|
|
|
|
|
|
events: {
|
2019-03-22 13:58:53 +03:00
|
|
|
'click a.action': '_onSelectScope',
|
|
|
|
'keydown a.action': '_onSelectScopeKeyboard'
|
2016-04-20 13:19:39 +03:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Event handler whenever an action has been clicked within the menu
|
|
|
|
*
|
|
|
|
* @param {Object} event event object
|
|
|
|
*/
|
2019-03-22 13:58:53 +03:00
|
|
|
_onSelectScope: function(event) {
|
2016-04-20 13:19:39 +03:00
|
|
|
var $target = $(event.currentTarget);
|
|
|
|
if (!$target.hasClass('menuitem')) {
|
|
|
|
$target = $target.closest('.menuitem');
|
|
|
|
}
|
|
|
|
|
|
|
|
this.trigger('select:scope', $target.data('action'));
|
|
|
|
|
|
|
|
OC.hideMenus();
|
|
|
|
},
|
|
|
|
|
2019-03-22 13:58:53 +03:00
|
|
|
_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);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2016-04-20 13:19:39 +03:00
|
|
|
/**
|
|
|
|
* Renders the menu with the currently set items
|
|
|
|
*/
|
|
|
|
render: function() {
|
2018-10-15 11:44:24 +03:00
|
|
|
this.$el.html(OC.Settings.Templates['federationscopemenu']({
|
2016-04-20 13:19:39 +03:00
|
|
|
items: this._scopes
|
|
|
|
}));
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Displays the menu
|
|
|
|
*/
|
|
|
|
show: function(context) {
|
|
|
|
this._context = context;
|
2017-08-14 12:16:24 +03:00
|
|
|
var currentlyActiveValue = $('#'+context.target.closest('form').id).find('input[type="hidden"]')[0].value;
|
2016-11-18 21:44:21 +03:00
|
|
|
|
2016-11-22 01:21:53 +03:00
|
|
|
for(var i in this._scopes) {
|
2021-03-23 13:38:25 +03:00
|
|
|
if (this._scopes[i].name === currentlyActiveValue) {
|
|
|
|
this._scopes[i].active = true;
|
|
|
|
} else {
|
|
|
|
this._scopes[i].active = false;
|
|
|
|
}
|
2021-02-01 05:34:36 +03:00
|
|
|
|
|
|
|
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
|
|
|
|
}
|
2016-11-18 21:44:21 +03:00
|
|
|
}
|
2016-04-20 13:19:39 +03:00
|
|
|
|
|
|
|
this.render();
|
|
|
|
this.$el.removeClass('hidden');
|
|
|
|
|
|
|
|
OC.showMenu(null, this.$el);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
OC.Settings = OC.Settings || {};
|
|
|
|
OC.Settings.FederationScopeMenu = FederationScopeMenu;
|
|
|
|
|
|
|
|
})();
|