Browse Source

Merge pull request #55467 from nextcloud/carl/remove-old-federation-settings

refactor: Remove old unused js files for federation settings
pull/55475/head
Carl Schwan 5 days ago
committed by GitHub
parent
commit
3d6699d685
No known key found for this signature in database GPG Key ID: B5690EEEBB952194
  1. 143
      apps/settings/js/federationscopemenu.js
  2. 278
      apps/settings/js/federationsettingsview.js
  3. 107
      apps/settings/js/settings/personalInfo.js
  4. 3
      apps/settings/templates/settings/personal/personal.info.php

143
apps/settings/js/federationscopemenu.js

@ -1,143 +0,0 @@
/**
* SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
* SPDX-FileCopyrightText: 2016 ownCloud, Inc.
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
/* 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;
})();

278
apps/settings/js/federationsettingsview.js

@ -1,278 +0,0 @@
/* global OC, result, _ */
/**
* SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
* SPDX-FileCopyrightText: 2016 ownCloud, Inc.
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
(function(_, $, OC) {
'use strict';
/**
* Construct a new FederationScopeMenu instance
* @constructs FederationScopeMenu
* @memberof OC.Settings
* @param {object} options
* @param {boolean} [options.showFederatedScope=false] whether show the
* "v2-federated" scope or not
* @param {boolean} [options.showPublishedScope=false] whether show the
* "v2-published" scope or not
*/
var FederationSettingsView = OC.Backbone.View.extend({
_inputFields: undefined,
/** @var Backbone.Model */
_config: undefined,
initialize: function(options) {
options = options || {};
if (options.config) {
this._config = options.config;
} else {
this._config = new OC.Settings.UserSettings();
}
this.showFederatedScope = !!options.showFederatedScope;
this.showPublishedScope = !!options.showPublishedScope;
this._inputFields = [
'displayname',
'phone',
'email',
'website',
'twitter',
'address',
'avatar'
];
var self = this;
_.each(this._inputFields, function(field) {
var scopeOnly = field === 'avatar';
// Initialize config model
if (!scopeOnly) {
self._config.set(field, $('#' + field).val());
}
self._config.set(field + 'Scope', $('#' + field + 'scope').val());
// Set inputs whenever model values change
if (!scopeOnly) {
self.listenTo(self._config, 'change:' + field, function() {
self.$('#' + field).val(self._config.get(field));
});
}
self.listenTo(self._config, 'change:' + field + 'Scope', function() {
self._setFieldScopeIcon(field, self._config.get(field + 'Scope'));
});
});
this._registerEvents();
},
render: function() {
var self = this;
var fieldsWithV2Private = [
'avatar',
'phone',
'twitter',
'website',
'address',
];
_.each(this._inputFields, function(field) {
var $icon = self.$('#' + field + 'form .headerbar-label > .federation-menu');
var excludedScopes = []
if (fieldsWithV2Private.indexOf(field) === -1) {
excludedScopes.push('v2-private');
}
if (!self.showFederatedScope) {
excludedScopes.push('v2-federated');
}
if (!self.showPublishedScope) {
excludedScopes.push('v2-published');
}
var scopeMenu = new OC.Settings.FederationScopeMenu({
field: field,
excludedScopes: excludedScopes,
});
self.listenTo(scopeMenu, 'select:scope', function(scope) {
self._onScopeChanged(field, scope);
});
$icon.append(scopeMenu.$el);
$icon.attr('aria-expanded', 'false');
$icon.on('click', _.bind(scopeMenu.show, scopeMenu));
$icon.on('keydown', function(e) {
if (e.keyCode === 32) {
// Open the menu when the user presses the space bar
e.preventDefault();
scopeMenu.show(e);
} else if (e.keyCode === 27) {
// Close the menu again if opened
OC.hideMenus();
}
}.bind(this));
// Restore initial state
self._setFieldScopeIcon(field, self._config.get(field + 'Scope'));
});
},
_registerEvents: function() {
var self = this;
_.each(this._inputFields, function(field) {
if (
field === 'avatar' ||
field === 'email' ||
field === 'displayname' ||
field === 'twitter' ||
field === 'address' ||
field === 'website' ||
field === 'phone'
) {
return;
}
self.$('#' + field).keyUpDelayedOrEnter(_.bind(self._onInputChanged, self), true);
});
},
_onInputChanged: function(e) {
var self = this;
var $dialog = $('.oc-dialog:visible');
if (OC.PasswordConfirmation.requiresPasswordConfirmation()) {
if($dialog.length === 0) {
OC.PasswordConfirmation.requirePasswordConfirmation(_.bind(this._onInputChanged, this, e));
}
return;
}
var $target = $(e.target);
var value = $target.val();
var field = $target.attr('id');
this._config.set(field, value);
var savingData = this._config.save({
error: function(jqXHR) {
OC.msg.finishedSaving('#personal-settings-container .msg', jqXHR);
}
});
$.when(savingData).done(function(data) {
if (data.status === "success") {
self._showInputChangeSuccess(field);
} else {
self._showInputChangeFail(field);
}
});
},
_onScopeChanged: function(field, scope) {
var $dialog = $('.oc-dialog:visible');
if (OC.PasswordConfirmation.requiresPasswordConfirmation()) {
if($dialog.length === 0) {
OC.PasswordConfirmation.requirePasswordConfirmation(_.bind(this._onScopeChanged, this, field, scope));
}
return;
}
this._config.set(field + 'Scope', scope);
$('#' + field + 'scope').val(scope);
// TODO: user loading/success feedback
this._config.save();
this._setFieldScopeIcon(field, scope);
this._updateVerifyButton(field, scope);
},
_updateVerifyButton: function(field, scope) {
// show verification button if the value is set and the scope is 'public'
if (field === 'twitter' || field === 'website'|| field === 'email') {
var verify = this.$('#' + field + 'form > .verify');
var scope = this.$('#' + field + 'scope').val();
var value = this.$('#' + field).val();
if (scope === 'public' && value !== '') {
verify.removeClass('hidden');
return true;
} else {
verify.addClass('hidden');
}
}
return false;
},
_showInputChangeSuccess: function(field) {
var $icon = this.$('#' + field + 'form > .icon-checkmark');
$icon.fadeIn(200);
setTimeout(function() {
$icon.fadeOut(300);
}, 2000);
var scope = this.$('#' + field + 'scope').val();
var verifyAvailable = this._updateVerifyButton(field, scope);
// change verification buttons from 'verify' to 'verifying...' on value change
if (verifyAvailable) {
if (field === 'twitter' || field === 'website') {
var verifyStatus = this.$('#' + field + 'form > .verify > #verify-' + field);
verifyStatus.attr('data-origin-title', t('settings', 'Verify'));
verifyStatus.attr('src', OC.imagePath('core', 'actions/verify.svg'));
verifyStatus.data('status', '0');
verifyStatus.addClass('verify-action');
} else if (field === 'email') {
var verifyStatus = this.$('#' + field + 'form > .verify > #verify-' + field);
verifyStatus.attr('data-origin-title', t('settings', 'Verifying …'));
verifyStatus.data('status', '1');
verifyStatus.attr('src', OC.imagePath('core', 'actions/verifying.svg'));
}
}
},
_showInputChangeFail: function(field) {
var $icon = this.$('#' + field + 'form > .icon-error');
$icon.fadeIn(200);
setTimeout(function() {
$icon.fadeOut(300);
}, 2000);
},
_setFieldScopeIcon: function(field, scope) {
var $icon = this.$('#' + field + 'form > .headerbar-label .icon-federation-menu');
$icon.removeClass('icon-phone');
$icon.removeClass('icon-password');
$icon.removeClass('icon-contacts-dark');
$icon.removeClass('icon-link');
$icon.addClass('hidden');
switch (scope) {
case 'v2-private':
$icon.addClass('icon-phone');
$icon.removeClass('hidden');
break;
case 'v2-local':
$icon.addClass('icon-password');
$icon.removeClass('hidden');
break;
case 'v2-federated':
$icon.addClass('icon-contacts-dark');
$icon.removeClass('hidden');
break;
case 'v2-published':
$icon.addClass('icon-link');
$icon.removeClass('hidden');
break;
}
}
});
OC.Settings = OC.Settings || {};
OC.Settings.FederationSettingsView = FederationSettingsView;
})(_, $, OC);

107
apps/settings/js/settings/personalInfo.js

@ -1,107 +0,0 @@
/* global OC */
/**
* SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
* SPDX-FileCopyrightText: 2011-2016 ownCloud, Inc.
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
OC.Settings = OC.Settings || {};
/**
* The callback will be fired as soon as enter is pressed by the
* user or 1 second after the last data entry
*
* @param {any} callback -
* @param allowEmptyValue if this is set to true the callback is also called when the value is empty
*/
jQuery.fn.keyUpDelayedOrEnter = function (callback, allowEmptyValue) {
var cb = callback;
var that = this;
this.on('input', _.debounce(function (event) {
// enter is already handled in keypress
if (event.keyCode === 13) {
return;
}
if (allowEmptyValue || that.val() !== '') {
cb(event);
}
}, 1000));
this.keypress(function (event) {
if (event.keyCode === 13 && (allowEmptyValue || that.val() !== '')) {
event.preventDefault();
cb(event);
}
});
};
window.addEventListener('DOMContentLoaded', function () {
if($('#pass2').length) {
$('#pass2').showPassword().keyup();
}
var showVerifyDialog = function(dialog, howToVerify, verificationCode) {
var dialogContent = dialog.children('.verification-dialog-content');
dialogContent.children(".explainVerification").text(howToVerify);
dialogContent.children(".verificationCode").text(verificationCode);
dialog.css('display', 'block');
};
$(".verify").click(function (event) {
event.stopPropagation();
var verify = $(this);
var indicator = $(this).children('img');
var accountId = indicator.attr('id');
var status = indicator.data('status');
var onlyVerificationCode = false;
if (parseInt(status) === 1) {
onlyVerificationCode = true;
}
if (indicator.hasClass('verify-action')) {
$.ajax(
OC.generateUrl('/settings/users/{account}/verify', {account: accountId}),
{
method: 'GET',
data: {onlyVerificationCode: onlyVerificationCode}
}
).done(function (data) {
var dialog = verify.children('.verification-dialog');
showVerifyDialog($(dialog), data.msg, data.code);
indicator.attr('data-origin-title', t('settings', 'Verifying …'));
indicator.attr('src', OC.imagePath('core', 'actions/verifying.svg'));
indicator.data('status', '1');
});
}
});
// When the user clicks anywhere outside of the verification dialog we close it
$(document).click(function(event){
var element = event.target;
var isDialog = $(element).hasClass('verificationCode')
|| $(element).hasClass('explainVerification')
|| $(element).hasClass('verification-dialog-content')
|| $(element).hasClass('verification-dialog');
if (!isDialog) {
$(document).find('.verification-dialog').css('display', 'none');
}
});
var settingsEl = $('#personal-settings')
var userSettings = new OC.Settings.UserSettings();
var federationSettingsView = new OC.Settings.FederationSettingsView({
el: settingsEl,
config: userSettings,
showFederatedScope: !!settingsEl.data('federation-enabled'),
showPublishedScope: !!settingsEl.data('lookup-server-upload-enabled'),
});
federationSettingsView.render();
});

3
apps/settings/templates/settings/personal/personal.info.php

@ -11,9 +11,6 @@
script('settings', [
'usersettings',
'templates',
'federationsettingsview',
'federationscopemenu',
'settings/personalInfo',
'vue-settings-personal-info',
]);
?>

Loading…
Cancel
Save