Merge branch 'staging' into newDrive
This commit is contained in:
@@ -30,7 +30,9 @@ define([
|
||||
Clipboard: Clipboard,
|
||||
donateURL: 'https://accounts.cryptpad.fr/#/donate?on=' + origin,
|
||||
upgradeURL: 'https://accounts.cryptpad.fr/#/?on=' + origin,
|
||||
account: {},
|
||||
account: {
|
||||
usage: 0,
|
||||
},
|
||||
};
|
||||
|
||||
// constants
|
||||
@@ -721,7 +723,11 @@ define([
|
||||
|
||||
common.getPinnedUsage = function (cb) {
|
||||
if (!pinsReady()) { return void cb('[RPC_NOT_READY]'); }
|
||||
rpc.getFileListSize(cb);
|
||||
|
||||
rpc.getFileListSize(function (err, bytes) {
|
||||
common.account.usage = typeof(bytes) === 'number'? bytes: 0;
|
||||
cb(err, bytes);
|
||||
});
|
||||
};
|
||||
|
||||
common.getFileSize = function (href, cb) {
|
||||
@@ -736,6 +742,9 @@ define([
|
||||
if (!pinsReady()) { return void cb('[RPC_NOT_READY]'); }
|
||||
rpc.updatePinLimits(function (e, limit, plan, note) {
|
||||
if (e) { return cb(e); }
|
||||
common.account.limit = limit;
|
||||
common.account.plan = plan;
|
||||
common.account.note = note;
|
||||
cb(e, limit, plan, note);
|
||||
});
|
||||
};
|
||||
@@ -744,6 +753,9 @@ define([
|
||||
if (!pinsReady()) { return void cb('[RPC_NOT_READY]'); }
|
||||
rpc.getLimit(function (e, limit, plan, note) {
|
||||
if (e) { return cb(e); }
|
||||
common.account.limit = limit;
|
||||
common.account.plan = plan;
|
||||
common.account.note = note;
|
||||
cb(void 0, limit, plan, note);
|
||||
});
|
||||
};
|
||||
@@ -760,8 +772,8 @@ define([
|
||||
return void cb (null, false, data);
|
||||
};
|
||||
var todo = function (e, used) {
|
||||
usage = used; //common.bytesToMegabytes(used);
|
||||
if (e) { return void cb(e); }
|
||||
usage = used;
|
||||
common.getPinLimit(andThen);
|
||||
};
|
||||
common.getPinnedUsage(todo);
|
||||
@@ -783,41 +795,63 @@ define([
|
||||
};
|
||||
|
||||
var LIMIT_REFRESH_RATE = 30000; // milliseconds
|
||||
common.createUsageBar = function (cb, alwaysDisplayUpgrade) {
|
||||
var todo = function (err, state, data) {
|
||||
common.createUsageBar = function (cb) {
|
||||
// getPinnedUsage updates common.account.usage, and other values
|
||||
// so we can just use those and only check for errors
|
||||
var todo = function (err) {
|
||||
var $container = $('<span>', {'class':'limit-container'});
|
||||
if (!data) {
|
||||
if (err) {
|
||||
return void window.setTimeout(function () {
|
||||
common.isOverPinLimit(todo);
|
||||
common.getPinnedUsage(todo);
|
||||
}, LIMIT_REFRESH_RATE);
|
||||
}
|
||||
|
||||
var unit = Util.magnitudeOfBytes(data.limit);
|
||||
var unit = Util.magnitudeOfBytes(common.account.limit);
|
||||
|
||||
var usage = unit === 'GB'? Util.bytesToGigabytes(data.usage):
|
||||
Util.bytesToMegabytes(data.usage);
|
||||
var limit = unit === 'GB'? Util.bytesToGigabytes(data.limit):
|
||||
Util.bytesToMegabytes(data.limit);
|
||||
var usage = unit === 'GB'? Util.bytesToGigabytes(common.account.usage):
|
||||
Util.bytesToMegabytes(common.account.usage);
|
||||
var limit = unit === 'GB'? Util.bytesToGigabytes(common.account.limit):
|
||||
Util.bytesToMegabytes(common.account.limit);
|
||||
|
||||
var $limit = $('<span>', {'class': 'cryptpad-limit-bar'}).appendTo($container);
|
||||
var quota = usage/limit;
|
||||
var width = Math.floor(Math.min(quota, 1)*200); // the bar is 200px width
|
||||
var $usage = $('<span>', {'class': 'usage'}).css('width', width+'px');
|
||||
|
||||
if (Config.noSubscriptionButton !== true &&
|
||||
(quota >= 0.8 || alwaysDisplayUpgrade) &&
|
||||
data.plan !== "power")
|
||||
{
|
||||
// TODO show donate url if applicable
|
||||
var makeDonateButton = function () {
|
||||
var $upgradeLink = $('<a>', {
|
||||
href: common.upgradeLink,
|
||||
href: common.donateURL,
|
||||
rel: "noreferrer noopener",
|
||||
target: "_blank",
|
||||
}).appendTo($container);
|
||||
$('<button>', {
|
||||
'class': 'upgrade buttonSuccess',
|
||||
}).text(Messages.supportCryptpad).appendTo($upgradeLink);
|
||||
};
|
||||
|
||||
var makeUpgradeButton = function () {
|
||||
var $upgradeLink = $('<a>', {
|
||||
href: common.upgradeURL,
|
||||
rel: "noreferrer noopener",
|
||||
target: "_blank",
|
||||
}).appendTo($container);
|
||||
$('<button>', {
|
||||
'class': 'upgrade buttonSuccess',
|
||||
title: Messages.upgradeTitle
|
||||
}).text(Messages.upgrade).appendTo($upgradeLink);
|
||||
}).text(Messages.upgradeAccount).appendTo($upgradeLink);
|
||||
};
|
||||
|
||||
if (!Config.removeDonateButton) {
|
||||
if (!common.isLoggedIn() || !Config.allowSubscriptions) {
|
||||
// user is not logged in, or subscriptions are disallowed
|
||||
makeDonateButton();
|
||||
} else if (!common.account.plan) {
|
||||
// user is logged in and subscriptions are allowed
|
||||
// and they don't have one. show upgrades
|
||||
makeUpgradeButton();
|
||||
} else {
|
||||
// they have a plan. show nothing
|
||||
}
|
||||
}
|
||||
|
||||
var prettyUsage;
|
||||
@@ -838,11 +872,11 @@ define([
|
||||
$text.text(usage + ' / ' + prettyLimit);
|
||||
$limit.append($usage).append($text);
|
||||
window.setTimeout(function () {
|
||||
common.isOverPinLimit(todo);
|
||||
common.getPinnedUsage(todo);
|
||||
}, LIMIT_REFRESH_RATE);
|
||||
cb(err, $container);
|
||||
};
|
||||
common.isOverPinLimit(todo);
|
||||
common.getPinnedUsage(todo);
|
||||
};
|
||||
|
||||
common.createButton = function (type, rightside, data, callback) {
|
||||
|
||||
Reference in New Issue
Block a user