Display an upgrade button in the settings page
parent
c1b43db363
commit
87fa28180a
5
rpc.js
5
rpc.js
|
@ -497,7 +497,8 @@ var updateLimits = function (config, publicKey, cb) {
|
|||
var l;
|
||||
if (publicKey) {
|
||||
var limit = limits[publicKey];
|
||||
l = limit && typeof limit.limit === "number" ? limit.limit : DEFAULT_LIMIT;
|
||||
l = limit && typeof limit.limit === "number" ?
|
||||
[limit.limit, limit.plan] : [DEFAULT_LIMIT, ''];
|
||||
}
|
||||
cb(void 0, l);
|
||||
} catch (e) {
|
||||
|
@ -519,7 +520,7 @@ var getLimit = function (publicKey, cb) {
|
|||
var limit = limits[unescapedKey];
|
||||
|
||||
var toSend = limit && typeof(limit.limit) === "number"?
|
||||
limit.limit : DEFAULT_LIMIT;
|
||||
[limit.limit, limit.plan] : [DEFAULT_LIMIT, ''];
|
||||
|
||||
cb(void 0, toSend);
|
||||
};
|
||||
|
|
|
@ -744,28 +744,28 @@ define([
|
|||
|
||||
common.updatePinLimit = function (cb) {
|
||||
if (!pinsReady()) { return void cb('[RPC_NOT_READY]'); }
|
||||
rpc.updatePinLimits(function (e, limit) {
|
||||
rpc.updatePinLimits(function (e, limit, plan) {
|
||||
if (e) { return cb(e); }
|
||||
var MB = common.bytesToMegabytes(limit);
|
||||
cb(e, MB);
|
||||
cb(e, MB, plan);
|
||||
});
|
||||
};
|
||||
|
||||
common.getPinLimit = function (cb) {
|
||||
if (!pinsReady()) { return void cb('[RPC_NOT_READY]'); }
|
||||
rpc.getLimit(function (e, limit) {
|
||||
rpc.getLimit(function (e, limit, plan) {
|
||||
if (e) { return cb(e); }
|
||||
var MB = common.bytesToMegabytes(limit);
|
||||
cb(void 0, MB);
|
||||
cb(void 0, MB, plan);
|
||||
});
|
||||
};
|
||||
|
||||
common.isOverPinLimit = function (cb) {
|
||||
if (!common.isLoggedIn() || !AppConfig.enablePinLimit) { return void cb(null, false); }
|
||||
var usage;
|
||||
var andThen = function (e, limit) {
|
||||
var andThen = function (e, limit, plan) {
|
||||
if (e) { return void cb(e); }
|
||||
var data = {usage: usage, limit: limit};
|
||||
var data = {usage: usage, limit: limit, plan: plan};
|
||||
if (usage > limit) {
|
||||
return void cb (null, true, data);
|
||||
}
|
||||
|
@ -780,7 +780,7 @@ define([
|
|||
};
|
||||
|
||||
var LIMIT_REFRESH_RATE = 30000; // milliseconds
|
||||
common.createUsageBar = function (cb) {
|
||||
common.createUsageBar = function (cb, alwaysDisplayUpgrade) {
|
||||
var todo = function (err, state, data) {
|
||||
var $container = $('<span>', {'class':'limit-container'});
|
||||
if (!data) {
|
||||
|
@ -796,10 +796,10 @@ define([
|
|||
var width = Math.floor(Math.min(quota, 1)*200); // the bar is 200px width
|
||||
var $usage = $('<span>', {'class': 'usage'}).css('width', width+'px');
|
||||
|
||||
if (quota >= 0.8) {
|
||||
if ((quota >= 0.8 || alwaysDisplayUpgrade) && data.plan !== "power") {
|
||||
var origin = encodeURIComponent(window.location.origin);
|
||||
var $upgradeLink = $('<a>', {
|
||||
href: "https://account.cryptpad.fr/#!on=" + origin,
|
||||
href: "https://accounts.cryptpad.fr/#!on=" + origin,
|
||||
rel: "noreferrer noopener",
|
||||
target: "_blank",
|
||||
}).appendTo($container);
|
||||
|
|
|
@ -126,7 +126,7 @@ define([
|
|||
rpc.send('UPDATE_LIMITS', undefined, function (e, response) {
|
||||
if (e) { return void cb(e); }
|
||||
if (response && response.length && typeof(response[0]) === "number") {
|
||||
cb (void 0, response);
|
||||
cb (void 0, response[0], response[1]);
|
||||
} else {
|
||||
cb('INVALID_RESPONSE');
|
||||
}
|
||||
|
@ -137,7 +137,7 @@ define([
|
|||
rpc.send('GET_LIMIT', undefined, function (e, response) {
|
||||
if (e) { return void cb(e); }
|
||||
if (response && response.length && typeof(response[0]) === "number") {
|
||||
cb (void 0, response[0]);
|
||||
cb (void 0, response[0], response[1]);
|
||||
} else {
|
||||
cb('INVALID_RESPONSE');
|
||||
}
|
||||
|
|
|
@ -60,7 +60,6 @@ define([
|
|||
$div.append('<br>').append($pubLabel).append($pubKey);
|
||||
}
|
||||
|
||||
|
||||
return $div;
|
||||
};
|
||||
|
||||
|
@ -234,7 +233,7 @@ define([
|
|||
$div.find('.limit-container').remove();
|
||||
$bar.find('.upgrade').addClass('btn btn-success');
|
||||
$div.append($bar);
|
||||
});
|
||||
}, true);
|
||||
return $div;
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in New Issue