From 980baf9ce310d91cd4f0a95e3f20f21400ac1377 Mon Sep 17 00:00:00 2001 From: yflory Date: Fri, 27 Mar 2020 15:06:15 +0100 Subject: [PATCH] Fix usage bar in drive and read only teams --- www/common/common-ui-elements.js | 1 + www/common/drive-ui.js | 7 +------ www/drive/inner.js | 19 +++++++++++-------- www/teams/inner.js | 24 ++++++++++++++++-------- 4 files changed, 29 insertions(+), 22 deletions(-) diff --git a/www/common/common-ui-elements.js b/www/common/common-ui-elements.js index 1e320c100..f535ad4a5 100644 --- a/www/common/common-ui-elements.js +++ b/www/common/common-ui-elements.js @@ -2232,6 +2232,7 @@ define([ updateUsage(); cb(null, $container); return { + $container: $container, stop: function () { clearInterval(interval); } diff --git a/www/common/drive-ui.js b/www/common/drive-ui.js index 2619f2419..81f7a6e54 100644 --- a/www/common/drive-ui.js +++ b/www/common/drive-ui.js @@ -538,10 +538,10 @@ define([ var metadataMgr = common.getMetadataMgr(); var sframeChan = common.getSframeChannel(); var priv = metadataMgr.getPrivateData(); - var user = metadataMgr.getUserData(); // Initialization Util.extend(APP, driveConfig.APP); + APP.$limit = driveConfig.$limit; var proxy = driveConfig.proxy; var folders = driveConfig.folders; var files = proxy.drive; @@ -587,11 +587,6 @@ define([ // TOOLBAR - /* add a "change username" button */ - if (!APP.readOnly) { - APP.$displayName.text(user.name || Messages.anonymous); - } - // DRIVE var currentPath = APP.currentPath = LS.getLastOpenedFolder(); if (APP.newSharedFolder) { diff --git a/www/drive/inner.js b/www/drive/inner.js index 720ac562d..fc21a2006 100644 --- a/www/drive/inner.js +++ b/www/drive/inner.js @@ -177,6 +177,7 @@ define([ var sframeChan = common.getSframeChannel(); var metadataMgr = common.getMetadataMgr(); var privateData = metadataMgr.getPrivateData(); + var user = metadataMgr.getUserData(); APP.disableSF = !privateData.enableSF && AppConfig.disableSharedFolders; if (APP.newSharedFolder && !APP.loggedIn) { @@ -204,13 +205,19 @@ define([ var $rightside = toolbar.$rightside; $rightside.html(''); // Remove the drawer if we don't use it to hide the toolbar - APP.$displayName = APP.$bar.find('.' + Toolbar.constants.username); + var $displayName = APP.$bar.find('.' + Toolbar.constants.username); + metadataMgr.onChange(function () { + var name = metadataMgr.getUserData().name || Messages.anonymous; + $displayName.text(name); + }); + $displayName.text(user.name || Messages.anonymous); + /* add the usage */ + var usageBar; if (APP.loggedIn) { - common.createUsageBar(null, function (err, $limitContainer) { + usageBar = common.createUsageBar(null, function (err, $limitContainer) { if (err) { return void DriveUI.logError(err); } - APP.$limit = $limitContainer; }, true); } @@ -256,16 +263,12 @@ define([ .addClass('fa-ban'); } - metadataMgr.onChange(function () { - var name = metadataMgr.getUserData().name || Messages.anonymous; - APP.$displayName.text(name); - }); - $('body').css('display', ''); if (!proxy.drive || typeof(proxy.drive) !== 'object') { throw new Error("Corrupted drive"); } var drive = DriveUI.create(common, { + $limit: usageBar && usageBar.$container, proxy: proxy, folders: folders, updateObject: updateObject, diff --git a/www/teams/inner.js b/www/teams/inner.js index c42e05489..0eb649252 100644 --- a/www/teams/inner.js +++ b/www/teams/inner.js @@ -295,22 +295,28 @@ define([ if (!proxy.drive || typeof(proxy.drive) !== 'object') { throw new Error("Corrupted drive"); } - if (APP.usageBar) { APP.usageBar.stop(); } - APP.usageBar = common.createUsageBar(APP.team, function (err, $limitContainer) { - if (err) { return void DriveUI.logError(err); } - driveAPP.$limit = $limitContainer; - $limitContainer.attr('title', Messages.team_quota); - }, true); driveAPP.team = id; // Provide secondaryKey var teamData = (privateData.teams || {})[id] || {}; driveAPP.readOnly = !teamData.hasSecondaryKey; + + if (APP.usageBar) { APP.usageBar.stop(); } + APP.usageBar = undefined; + if (!driveAPP.readOnly) { + APP.usageBar = common.createUsageBar(APP.team, function (err, $limitContainer) { + if (err) { return void DriveUI.logError(err); } + $limitContainer.attr('title', Messages.team_quota); + }, true); + } + var drive = DriveUI.create(common, { proxy: proxy, folders: folders, updateObject: updateObject, updateSharedFolders: updateSharedFolders, + + $limit: APP.usageBar && APP.usageBar.$container, APP: driveAPP, edPublic: APP.teamEdPublic, editKey: teamData.secondaryKey @@ -1281,6 +1287,7 @@ define([ var sframeChan = common.getSframeChannel(); var metadataMgr = common.getMetadataMgr(); var privateData = metadataMgr.getPrivateData(); + var user = metadataMgr.getUserData(); readOnly = driveAPP.readOnly = metadataMgr.getPrivateData().readOnly; @@ -1305,11 +1312,12 @@ define([ var toolbar = Toolbar.create(configTb); toolbar.$rightside.hide(); // hide the bottom part of the toolbar // Update the name in the user menu - driveAPP.$displayName = $bar.find('.' + Toolbar.constants.username); + var $displayName = $bar.find('.' + Toolbar.constants.username); metadataMgr.onChange(function () { var name = metadataMgr.getUserData().name || Messages.anonymous; - driveAPP.$displayName.text(name); + $displayName.text(name); }); + $displayName.text(user.name || Messages.anonymous); // Load the Team module var onEvent = function (obj) {