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() {
|
|
|
|
|
|
|
|
var TEMPLATE_MENU =
|
|
|
|
'<ul>' +
|
|
|
|
'{{#each items}}' +
|
|
|
|
'<li>' +
|
2016-11-18 13:27:34 +00:00
|
|
|
'<a href="#" class="menuitem action action-{{name}} permanent {{#if active}}active{{/if}}" data-action="{{name}}">' +
|
2016-04-20 10:19:39 +00:00
|
|
|
'{{#if icon}}<img class="icon" src="{{icon}}"/>' +
|
|
|
|
'{{else}}'+
|
|
|
|
'{{#if iconClass}}' +
|
|
|
|
'<span class="icon {{iconClass}}"></span>' +
|
|
|
|
'{{else}}' +
|
|
|
|
'<span class="no-icon"></span>' +
|
|
|
|
'{{/if}}' +
|
|
|
|
'{{/if}}' +
|
2016-11-18 13:27:34 +00:00
|
|
|
'<p><strong class="menuitem-text">{{displayName}}</strong><br>' +
|
|
|
|
'<span class="menuitem-text-detail">{{tooltip}}</span></p></a>' +
|
2016-04-20 10:19:39 +00:00
|
|
|
'</li>' +
|
|
|
|
'{{/each}}' +
|
|
|
|
'</ul>';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Construct a new FederationScopeMenu instance
|
|
|
|
* @constructs FederationScopeMenu
|
|
|
|
* @memberof OC.Settings
|
|
|
|
*/
|
|
|
|
var FederationScopeMenu = OC.Backbone.View.extend({
|
|
|
|
tagName: 'div',
|
2017-01-11 20:17:27 +00:00
|
|
|
className: 'federationScopeMenu popovermenu bubble hidden menu',
|
2016-11-16 11:35:07 +00:00
|
|
|
field: undefined,
|
|
|
|
_scopes: undefined,
|
|
|
|
|
|
|
|
initialize: function(options) {
|
|
|
|
this.field = options.field;
|
|
|
|
this._scopes = [
|
|
|
|
{
|
|
|
|
name: 'private',
|
2016-11-21 08:07:50 +00:00
|
|
|
displayName: (this.field === 'avatar' || this.field === 'displayname') ? t('core', 'Local') : t('core', 'Private'),
|
|
|
|
tooltip: (this.field === 'avatar' || this.field === 'displayname') ? t('core', 'Only visible to local users') : t('core', 'Only visible to you'),
|
2016-11-18 18:44:21 +00:00
|
|
|
icon: OC.imagePath('core', 'actions/password'),
|
|
|
|
active: false
|
2016-11-16 11:35:07 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'contacts',
|
|
|
|
displayName: t('core', 'Contacts'),
|
|
|
|
tooltip: t('core', 'Visible to local users and to trusted servers'),
|
2016-11-18 18:44:21 +00:00
|
|
|
icon: OC.imagePath('core', 'places/contacts-dark'),
|
|
|
|
active: false
|
2016-11-16 11:35:07 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'public',
|
|
|
|
displayName: t('core', 'Public'),
|
|
|
|
tooltip: t('core', 'Will be synced to a global and public address book'),
|
2016-11-18 18:44:21 +00:00
|
|
|
icon: OC.imagePath('core', 'places/link'),
|
|
|
|
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: {
|
|
|
|
'click a.action': '_onClickAction'
|
|
|
|
},
|
|
|
|
|
|
|
|
template: Handlebars.compile(TEMPLATE_MENU),
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Event handler whenever an action has been clicked within the menu
|
|
|
|
*
|
|
|
|
* @param {Object} event event object
|
|
|
|
*/
|
|
|
|
_onClickAction: function(event) {
|
|
|
|
var $target = $(event.currentTarget);
|
|
|
|
if (!$target.hasClass('menuitem')) {
|
|
|
|
$target = $target.closest('.menuitem');
|
|
|
|
}
|
|
|
|
|
|
|
|
this.trigger('select:scope', $target.data('action'));
|
|
|
|
|
|
|
|
OC.hideMenus();
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Renders the menu with the currently set items
|
|
|
|
*/
|
|
|
|
render: function() {
|
|
|
|
this.$el.html(this.template({
|
|
|
|
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
|
|
|
|
2016-11-16 15:03:11 +00:00
|
|
|
var $el = $(context.target);
|
|
|
|
var offsetIcon = $el.offset();
|
|
|
|
var offsetHeading = $el.closest('h2').offset();
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
})();
|