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