Fix usage bar in drive and read only teams

pull/1/head
yflory 5 years ago
parent 9a4da6e6e0
commit 980baf9ce3

@ -2232,6 +2232,7 @@ define([
updateUsage(); updateUsage();
cb(null, $container); cb(null, $container);
return { return {
$container: $container,
stop: function () { stop: function () {
clearInterval(interval); clearInterval(interval);
} }

@ -538,10 +538,10 @@ define([
var metadataMgr = common.getMetadataMgr(); var metadataMgr = common.getMetadataMgr();
var sframeChan = common.getSframeChannel(); var sframeChan = common.getSframeChannel();
var priv = metadataMgr.getPrivateData(); var priv = metadataMgr.getPrivateData();
var user = metadataMgr.getUserData();
// Initialization // Initialization
Util.extend(APP, driveConfig.APP); Util.extend(APP, driveConfig.APP);
APP.$limit = driveConfig.$limit;
var proxy = driveConfig.proxy; var proxy = driveConfig.proxy;
var folders = driveConfig.folders; var folders = driveConfig.folders;
var files = proxy.drive; var files = proxy.drive;
@ -587,11 +587,6 @@ define([
// TOOLBAR // TOOLBAR
/* add a "change username" button */
if (!APP.readOnly) {
APP.$displayName.text(user.name || Messages.anonymous);
}
// DRIVE // DRIVE
var currentPath = APP.currentPath = LS.getLastOpenedFolder(); var currentPath = APP.currentPath = LS.getLastOpenedFolder();
if (APP.newSharedFolder) { if (APP.newSharedFolder) {

@ -177,6 +177,7 @@ define([
var sframeChan = common.getSframeChannel(); var sframeChan = common.getSframeChannel();
var metadataMgr = common.getMetadataMgr(); var metadataMgr = common.getMetadataMgr();
var privateData = metadataMgr.getPrivateData(); var privateData = metadataMgr.getPrivateData();
var user = metadataMgr.getUserData();
APP.disableSF = !privateData.enableSF && AppConfig.disableSharedFolders; APP.disableSF = !privateData.enableSF && AppConfig.disableSharedFolders;
if (APP.newSharedFolder && !APP.loggedIn) { if (APP.newSharedFolder && !APP.loggedIn) {
@ -204,13 +205,19 @@ define([
var $rightside = toolbar.$rightside; var $rightside = toolbar.$rightside;
$rightside.html(''); // Remove the drawer if we don't use it to hide the toolbar $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 */ /* add the usage */
var usageBar;
if (APP.loggedIn) { if (APP.loggedIn) {
common.createUsageBar(null, function (err, $limitContainer) { usageBar = common.createUsageBar(null, function (err, $limitContainer) {
if (err) { return void DriveUI.logError(err); } if (err) { return void DriveUI.logError(err); }
APP.$limit = $limitContainer;
}, true); }, true);
} }
@ -256,16 +263,12 @@ define([
.addClass('fa-ban'); .addClass('fa-ban');
} }
metadataMgr.onChange(function () {
var name = metadataMgr.getUserData().name || Messages.anonymous;
APP.$displayName.text(name);
});
$('body').css('display', ''); $('body').css('display', '');
if (!proxy.drive || typeof(proxy.drive) !== 'object') { if (!proxy.drive || typeof(proxy.drive) !== 'object') {
throw new Error("Corrupted drive"); throw new Error("Corrupted drive");
} }
var drive = DriveUI.create(common, { var drive = DriveUI.create(common, {
$limit: usageBar && usageBar.$container,
proxy: proxy, proxy: proxy,
folders: folders, folders: folders,
updateObject: updateObject, updateObject: updateObject,

@ -295,22 +295,28 @@ define([
if (!proxy.drive || typeof(proxy.drive) !== 'object') { if (!proxy.drive || typeof(proxy.drive) !== 'object') {
throw new Error("Corrupted drive"); throw new Error("Corrupted drive");
} }
driveAPP.team = id;
// Provide secondaryKey
var teamData = (privateData.teams || {})[id] || {};
driveAPP.readOnly = !teamData.hasSecondaryKey;
if (APP.usageBar) { APP.usageBar.stop(); } if (APP.usageBar) { APP.usageBar.stop(); }
APP.usageBar = undefined;
if (!driveAPP.readOnly) {
APP.usageBar = common.createUsageBar(APP.team, function (err, $limitContainer) { APP.usageBar = common.createUsageBar(APP.team, function (err, $limitContainer) {
if (err) { return void DriveUI.logError(err); } if (err) { return void DriveUI.logError(err); }
driveAPP.$limit = $limitContainer;
$limitContainer.attr('title', Messages.team_quota); $limitContainer.attr('title', Messages.team_quota);
}, true); }, true);
driveAPP.team = id; }
// Provide secondaryKey
var teamData = (privateData.teams || {})[id] || {};
driveAPP.readOnly = !teamData.hasSecondaryKey;
var drive = DriveUI.create(common, { var drive = DriveUI.create(common, {
proxy: proxy, proxy: proxy,
folders: folders, folders: folders,
updateObject: updateObject, updateObject: updateObject,
updateSharedFolders: updateSharedFolders, updateSharedFolders: updateSharedFolders,
$limit: APP.usageBar && APP.usageBar.$container,
APP: driveAPP, APP: driveAPP,
edPublic: APP.teamEdPublic, edPublic: APP.teamEdPublic,
editKey: teamData.secondaryKey editKey: teamData.secondaryKey
@ -1281,6 +1287,7 @@ define([
var sframeChan = common.getSframeChannel(); var sframeChan = common.getSframeChannel();
var metadataMgr = common.getMetadataMgr(); var metadataMgr = common.getMetadataMgr();
var privateData = metadataMgr.getPrivateData(); var privateData = metadataMgr.getPrivateData();
var user = metadataMgr.getUserData();
readOnly = driveAPP.readOnly = metadataMgr.getPrivateData().readOnly; readOnly = driveAPP.readOnly = metadataMgr.getPrivateData().readOnly;
@ -1305,11 +1312,12 @@ define([
var toolbar = Toolbar.create(configTb); var toolbar = Toolbar.create(configTb);
toolbar.$rightside.hide(); // hide the bottom part of the toolbar toolbar.$rightside.hide(); // hide the bottom part of the toolbar
// Update the name in the user menu // Update the name in the user menu
driveAPP.$displayName = $bar.find('.' + Toolbar.constants.username); var $displayName = $bar.find('.' + Toolbar.constants.username);
metadataMgr.onChange(function () { metadataMgr.onChange(function () {
var name = metadataMgr.getUserData().name || Messages.anonymous; var name = metadataMgr.getUserData().name || Messages.anonymous;
driveAPP.$displayName.text(name); $displayName.text(name);
}); });
$displayName.text(user.name || Messages.anonymous);
// Load the Team module // Load the Team module
var onEvent = function (obj) { var onEvent = function (obj) {

Loading…
Cancel
Save