2016-04-20 10:19:39 +00: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
|
|
|
|
*/
|
|
|
|
var FederationScopeMenu = OC.Backbone.View.extend({
|
|
|
|
tagName: 'div',
|
2018-05-03 15:05:15 +00:00
|
|
|
className: 'federationScopeMenu popovermenu bubble menu menu-center',
|
2016-11-16 11:35:07 +00:00
|
|
|
field: undefined,
|
|
|
|
_scopes: undefined,
|
|
|
|
|
|
|
|
initialize: function(options) {
|
|
|
|
this.field = options.field;
|
|
|
|
this._scopes = [
|
|
|
|
{
|
|
|
|
name: 'private',
|
2017-11-30 10:11:40 +00:00
|
|
|
displayName: (this.field === 'avatar' || this.field === 'displayname') ? t('settings', 'Local') : t('settings', 'Private'),
|
|
|
|
tooltip: (this.field === 'avatar' || this.field === 'displayname') ? t('settings', 'Only visible to local users') : t('settings', 'Only visible to you'),
|
2018-08-01 08:05:42 +00:00
|
|
|
iconClass: 'icon-password',
|
2016-11-18 18:44:21 +00:00
|
|
|
active: false
|
2016-11-16 11:35:07 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'contacts',
|
2017-11-30 10:11:40 +00:00
|
|
|
displayName: t('settings', 'Contacts'),
|
|
|
|
tooltip: t('settings', 'Visible to local users and to trusted servers'),
|
2018-08-01 08:05:42 +00:00
|
|
|
iconClass: 'icon-contacts-dark',
|
2016-11-18 18:44:21 +00:00
|
|
|
active: false
|
2016-11-16 11:35:07 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'public',
|
2017-11-30 10:11:40 +00:00
|
|
|
displayName: t('settings', 'Public'),
|
|
|
|
tooltip: t('settings', 'Will be synced to a global and public address book'),
|
2018-08-01 08:05:42 +00:00
|
|
|
iconClass: 'icon-link',
|
2016-11-18 18:44:21 +00:00
|
|
|
active: false
|
2016-11-16 11:35:07 +00:00
|
|
|
}
|
|
|
|
];
|
|
|
|
},
|
2016-04-20 10:19:39 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Current context
|
|
|
|
*
|
|
|
|
* @type OCA.Files.FileActionContext
|
|
|
|
*/
|
|
|
|
_context: null,
|
|
|
|
|
|
|
|
events: {
|
2019-03-22 10:58:53 +00:00
|
|
|
'click a.action': '_onSelectScope',
|
|
|
|
'keydown a.action': '_onSelectScopeKeyboard'
|
2016-04-20 10:19:39 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Event handler whenever an action has been clicked within the menu
|
|
|
|
*
|
|
|
|
* @param {Object} event event object
|
|
|
|
*/
|
2019-03-22 10:58:53 +00:00
|
|
|
_onSelectScope: function(event) {
|
2016-04-20 10:19:39 +00: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 10:58:53 +00: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 10:19:39 +00:00
|
|
|
/**
|
|
|
|
* Renders the menu with the currently set items
|
|
|
|
*/
|
|
|
|
render: function() {
|
2018-10-15 08:44:24 +00:00
|
|
|
this.$el.html(OC.Settings.Templates['federationscopemenu']({
|
2016-04-20 10:19:39 +00:00
|
|
|
items: this._scopes
|
|
|
|
}));
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Displays the menu
|
|
|
|
*/
|
|
|
|
show: function(context) {
|
|
|
|
this._context = context;
|
2017-08-14 09:16:24 +00:00
|
|
|
var currentlyActiveValue = $('#'+context.target.closest('form').id).find('input[type="hidden"]')[0].value;
|
2016-11-18 18:44:21 +00:00
|
|
|
|
2016-11-21 22:21:53 +00:00
|
|
|
for(var i in this._scopes) {
|
2016-11-18 18:44:21 +00:00
|
|
|
this._scopes[i].active = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (currentlyActiveValue) {
|
|
|
|
case "private":
|
|
|
|
this._scopes[0].active = true;
|
|
|
|
break;
|
|
|
|
case "contacts":
|
|
|
|
this._scopes[1].active = true;
|
|
|
|
break;
|
|
|
|
case "public":
|
|
|
|
this._scopes[2].active = true;
|
|
|
|
break;
|
|
|
|
}
|
2016-04-20 10:19:39 +00:00
|
|
|
|
|
|
|
this.render();
|
|
|
|
this.$el.removeClass('hidden');
|
|
|
|
|
|
|
|
OC.showMenu(null, this.$el);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
OC.Settings = OC.Settings || {};
|
|
|
|
OC.Settings.FederationScopeMenu = FederationScopeMenu;
|
|
|
|
|
|
|
|
})();
|