]> source.dussan.org Git - nextcloud-server.git/commitdiff
Adjust scopes menu based on conditions
authorVincent Petry <vincent@nextcloud.com>
Tue, 23 Mar 2021 10:38:25 +0000 (11:38 +0100)
committerbackportbot[bot] <backportbot[bot]@users.noreply.github.com>
Mon, 29 Mar 2021 07:03:31 +0000 (07:03 +0000)
Now not all fields have the "v2-private" option in place.
Fix dropdown issue when a scope was stored that is not listed after
disabling the lookup server.
Whenever the lookup server upload is disabled, the scope menu is now
displayed where it makes sense to allow switching between the two private
scopes.

Signed-off-by: Vincent Petry <vincent@nextcloud.com>
apps/settings/js/federationscopemenu.js
apps/settings/js/federationsettingsview.js
apps/settings/js/settings/personalInfo.js
apps/settings/templates/settings/personal/personal.info.php

index 1c854a7ee574ccae55e0351bf516d0054c2d83ea..b94e1686a4e8ba68c58740d69be74b956cd2d6a0 100644 (file)
@@ -57,7 +57,7 @@
                                }
                        ];
 
-                       if (options.excludedScopes) {
+                       if (options.excludedScopes && options.excludedScopes.length) {
                                this._scopes = this._scopes.filter(function(scopeEntry) {
                                        return options.excludedScopes.indexOf(scopeEntry.name) === -1;
                                })
                        var currentlyActiveValue = $('#'+context.target.closest('form').id).find('input[type="hidden"]')[0].value;
 
                        for(var i in this._scopes) {
-                               this._scopes[i].active = false;
-                       }
-
-                       switch (currentlyActiveValue) {
-                               case 'v2-private':
-                                       this._scopes[0].active = true;
-                                       break;
-                               case 'private':
-                                       this._scopes[1].active = true;
-                                       break;
-                               case 'contacts':
-                                       this._scopes[2].active = true;
-                                       break;
-                               case 'public':
-                                       this._scopes[3].active = true;
-                                       break;
+                               if (this._scopes[i].name === currentlyActiveValue) {
+                                       this._scopes[i].active = true;
+                               } else {
+                                       this._scopes[i].active = false;
+                               }
                        }
 
                        this.render();
index 293989baa0c3f21a96177ddcb5211ee57170d7ed..759bf85c3e1b827f9538786c426957da437a3561 100644 (file)
 (function(_, $, OC) {
        'use strict';
 
+       /**
+        * Construct a new FederationScopeMenu instance
+        * @constructs FederationScopeMenu
+        * @memberof OC.Settings
+        * @param {object} options
+        * @param {bool} [options.lookupServerUploadEnabled=false] whether uploading to the lookup server is enabled
+        */
        var FederationSettingsView = OC.Backbone.View.extend({
                _inputFields: undefined,
 
@@ -24,6 +31,7 @@
                        } else {
                                this._config = new OC.Settings.UserSettings();
                        }
+                       this.showFederationScopes = !!options.showFederationScopes;
 
                        this._inputFields = [
                                'displayname',
 
                        _.each(this._inputFields, function(field) {
                                var $icon = self.$('#' + field + 'form h3 > .federation-menu');
-                               var excludedScopes = null
+                               var excludedScopes = []
 
                                if (fieldsWithV2Private.indexOf(field) === -1) {
-                                       excludedScopes = ['v2-private']
+                                       excludedScopes.push('v2-private');
+                               }
+
+                               if (!self.showFederationScopes) {
+                                       excludedScopes.push('contacts');
+                                       excludedScopes.push('public');
                                }
 
                                var scopeMenu = new OC.Settings.FederationScopeMenu({
index a6055fd7a9490948503b639c822829ff1b2b383e..e71f48401235632ff4efd48052201afc4cd55971 100644 (file)
@@ -199,10 +199,12 @@ window.addEventListener('DOMContentLoaded', function () {
        });
 
 
+       var settingsEl = $('#personal-settings')
        var userSettings = new OC.Settings.UserSettings();
        var federationSettingsView = new OC.Settings.FederationSettingsView({
-               el: '#personal-settings',
-               config: userSettings
+               el: settingsEl,
+               config: userSettings,
+               showFederationScopes: !!settingsEl.data('lookup-server-upload-enabled'),
        });
 
        userSettings.on("sync", function() {
index 84198b3c0c43e6d3c9b6e88b9d6fb35d917e3048..60db8c8533343c84be41e3ca44479116f97f7ffd 100644 (file)
@@ -34,8 +34,8 @@ script('settings', [
 ]);
 ?>
 
-<div id="personal-settings">
-       <div id="personal-settings-avatar-container" class="personal-settings-container">
+<div id="personal-settings" data-lookup-server-upload-enabled="<?php p($_['lookupServerUploadEnabled'] ? 'true' : 'false') ?>">
+<div id="personal-settings-avatar-container" class="personal-settings-container">
                <div>
                        <form id="avatarform" class="section" method="post" action="<?php p(\OC::$server->getURLGenerator()->linkToRoute('core.avatar.postAvatar')); ?>">
                                <h3>
@@ -68,9 +68,7 @@ script('settings', [
                                </div>
                                <span class="icon-checkmark hidden"></span>
                                <span class="icon-error hidden" ></span>
-                               <?php if ($_['lookupServerUploadEnabled']) { ?>
                                <input type="hidden" id="avatarscope" value="<?php p($_['avatarScope']) ?>">
-                               <?php } ?>
                        </form>
                </div>
                <div class="personal-settings-setting-box personal-settings-group-box section">
@@ -125,7 +123,7 @@ script('settings', [
                                <span class="icon-checkmark hidden"></span>
                                <span class="icon-error hidden" ></span>
                                <?php if ($_['lookupServerUploadEnabled']) { ?>
-                                       <input type="hidden" id="displaynamescope" value="<?php p($_['displayNameScope']) ?>">
+                               <input type="hidden" id="displaynamescope" value="<?php p($_['displayNameScope']) ?>">
                                <?php } ?>
                        </form>
                </div>
@@ -198,9 +196,7 @@ script('settings', [
                                       autocomplete="on" autocapitalize="none" autocorrect="off" />
                                <span class="icon-checkmark hidden"></span>
                                <span class="icon-error hidden" ></span>
-                               <?php if ($_['lookupServerUploadEnabled']) { ?>
                                <input type="hidden" id="phonescope" value="<?php p($_['phoneScope']) ?>">
-                               <?php } ?>
                        </form>
                </div>
                <?php } ?>
@@ -223,9 +219,7 @@ script('settings', [
                                           autocomplete="on" autocapitalize="none" autocorrect="off" />
                                <span class="icon-checkmark hidden"></span>
                                <span class="icon-error hidden" ></span>
-                               <?php if ($_['lookupServerUploadEnabled']) { ?>
                                <input type="hidden" id="addressscope" value="<?php p($_['addressScope']) ?>">
-                               <?php } ?>
                        </form>
                </div>
                <?php } ?>
@@ -279,9 +273,7 @@ script('settings', [
                                />
                                <span class="icon-checkmark hidden"></span>
                                <span class="icon-error hidden" ></span>
-                               <?php if ($_['lookupServerUploadEnabled']) { ?>
                                <input type="hidden" id="websitescope" value="<?php p($_['websiteScope']) ?>">
-                               <?php } ?>
                        </form>
                </div>
                <?php } ?>
@@ -335,9 +327,7 @@ script('settings', [
                                />
                                <span class="icon-checkmark hidden"></span>
                                <span class="icon-error hidden" ></span>
-                               <?php if ($_['lookupServerUploadEnabled']) { ?>
                                <input type="hidden" id="twitterscope" value="<?php p($_['twitterScope']) ?>">
-                               <?php } ?>
                        </form>
                </div>
                <?php } ?>