Don't store a pad in the drive if the limit has been reached

pull/1/head
yflory 8 years ago
parent bf7c7c45d0
commit a165332c15

@ -162,6 +162,7 @@
font-size: 20px;
}
.cryptpad-toolbar .cryptpad-limit span {
cursor: pointer;
margin: auto;
}
.cryptpad-toolbar .cryptpad-lag {

@ -56,8 +56,10 @@ define(function () {
out.redLight = "Vous êtes déconnectés de la session";
out.pinLimitReached = "Vous avez atteint votre limite de stockage";
out.pinLimitReachedAlert = "Vous avez atteint votre limite de stockage. Ce pad ne sera pas enregistré dans votre CrypDrive.<br>" +
out.pinLimitReachedAlert = "Vous avez atteint votre limite de stockage. Les nouveaux pads ne seront pas enregistrés dans votre CrypDrive.<br>" +
"Pour résoudre ce problème, vous pouvez soit supprimer des pads de votre CryptDrive (y compris la corbeille), soit vous abonner à une offre premium pour augmenter la limite maximale.";
out.pinLimitNotPinned = "Vous avez atteint votre limite de stockage.<br>"+
"Ce pad n'est pas enregistré dans votre CryptDrive.";
out.importButtonTitle = 'Importer un pad depuis un fichier local';

@ -58,8 +58,10 @@ define(function () {
out.redLight = "You are disconnected from the session";
out.pinLimitReached = "You've reached your storage limit";
out.pinLimitReachedAlert = "You've reached your storage limit. This pad won't be stored in your CryptDrive.<br>" +
out.pinLimitReachedAlert = "You've reached your storage limit. New pads won't be stored in your CryptDrive.<br>" +
"To fix this problem, you can either remove pads from your CryptDrive (including the trash) or subscribe to a premium offer to increase your limit.";
out.pinLimitNotPinned = "You've reached your storage limit.<br>"+
"This pad is not stored in your CryptDrive.";
out.importButtonTitle = 'Import a pad from a local file';

@ -570,8 +570,16 @@ define([
if (!contains) {
var data = makePad(href, name);
getStore().pushData(data);
getStore().addPad(data, common.initialPath);
getStore().pushData(data, function (e, state) {
if (e) {
if (e === 'E_OVER_LIMIT') {
Cryptpad.alert(Messages.pinLimitNotPinned, null, true);
return;
}
else { throw new Error("Cannot push this pad to CryptDrive", e); }
}
getStore().addPad(data, common.initialPath);
});
}
if (updateWeaker.length > 0) {
updateWeaker.forEach(function (obj) {
@ -709,7 +717,23 @@ define([
};
var getPinLimit = common.getPinLimit = function (cb) {
cb(void 0, 10);
cb(void 0, 1000);
};
var isOverPinLimit = common.isOverPinLimit = function (cb) {
var andThen = function (e, limit) {
if (e) { return void cb(e); }
if (usage > limit) {
return void cb (null, true);
}
return void cb (null, false);
};
var todo = function (e, used) {
usage = common.bytesToMegabytes(used);
if (e) { return void cb(e); }
common.getPinLimit(andThen);
};
common.getPinnedUsage(todo);
};
var createButton = common.createButton = function (type, rightside, data, callback) {

@ -497,19 +497,15 @@ define([
'class': LIMIT_ELEM_CLS,
'title': Messages.pinLimitReached
}).append($limitIcon).hide().appendTo($userContainer);
var andThen = function (e, limit) {
if (usage > limit) {
var todo = function (e, overLimit) {
if (e) { return void console.error("Unable tog et the pinned usage"); }
if (overLimit) {
$limit.show().click(function () {
Cryptpad.alert(Messages.pinLimitReachedAlert, null, true);
});
}
};
var todo = function (e, used) {
usage = Cryptpad.bytesToMegabytes(used);
if (e) { console.error("Unable tog et the pinned usage"); return; }
Cryptpad.getPinLimit(andThen);
};
Cryptpad.getPinnedUsage(todo);
Cryptpad.isOverPinLimit(todo);
}
if (config.displayed.indexOf('newpad') !== -1) {

@ -1,6 +1,7 @@
define([
'jquery',
], function ($) {
'/customize/application_config.js'
], function ($, AppConfig) {
var module = {};
var ROOT = module.ROOT = "root";
@ -427,19 +428,25 @@ define([
};
// FILES DATA
var pushFileData = exp.pushData = function (data) {
var pushFileData = exp.pushData = function (data, cb) {
if (typeof cb !== "function") { cb = function () {}; }
var todo = function () {
files[FILES_DATA].push(data);
cb();
};
if (!Cryptpad.isLoggedIn() || !AppConfig.enablePinning) { todo(); }
Cryptpad.pinPads([Cryptpad.hrefToHexChannelId(data.href)], function (e, hash) {
if (e) { console.log(e); return; }
console.log(hash);
if (e) { return void cb(e); }
cb('E_OVER_LIMIT'); return; //TODO
todo();
});
files[FILES_DATA].push(data);
};
var spliceFileData = exp.removeData = function (idx) {
var data = files[FILES_DATA][idx];
if (typeof data === "object") {
if (typeof data === "object" && Cryptpad.isLoggedIn() && AppConfig.enablePinning) {
Cryptpad.unpinPads([Cryptpad.hrefToHexChannelId(data.href)], function (e, hash) {
if (e) { console.log(e); return; }
console.log(hash);
if (e) { return void logError(e); }
debug('UNPIN', hash);
});
}
files[FILES_DATA].splice(idx, 1);

@ -2392,7 +2392,7 @@ define([
var userList = APP.userList = info.userList;
var config = {
displayed: ['useradmin', 'spinner', 'lag', 'state'],
displayed: ['useradmin', 'spinner', 'lag', 'state', 'limit'],
readOnly: readOnly,
ifrw: window,
common: Cryptpad,

@ -578,7 +578,7 @@ define([
userList = info.userList;
var configTb = {
displayed: ['useradmin', 'spinner', 'lag', 'state', 'share', 'userlist', 'newpad'],
displayed: ['useradmin', 'spinner', 'lag', 'state', 'share', 'userlist', 'newpad', 'limit'],
userData: userData,
readOnly: readOnly,
ifrw: ifrw,

@ -733,7 +733,7 @@ define([
userList = APP.userList = info.userList;
var config = {
displayed: ['useradmin', 'spinner', 'lag', 'state', 'share', 'userlist', 'newpad'],
displayed: ['useradmin', 'spinner', 'lag', 'state', 'share', 'userlist', 'newpad', 'limit'],
userData: userData,
readOnly: readOnly,
share: {

@ -513,7 +513,7 @@ define([
userList = info.userList;
var configTb = {
displayed: ['useradmin', 'spinner', 'lag', 'state', 'share', 'userlist', 'newpad'],
displayed: ['useradmin', 'spinner', 'lag', 'state', 'share', 'userlist', 'newpad', 'limit'],
userData: userData,
readOnly: readOnly,
ifrw: ifrw,

@ -334,7 +334,7 @@ window.canvas = canvas;
var onInit = config.onInit = function (info) {
userList = info.userList;
var config = {
displayed: ['useradmin', 'spinner', 'lag', 'state', 'share', 'userlist', 'newpad'],
displayed: ['useradmin', 'spinner', 'lag', 'state', 'share', 'userlist', 'newpad', 'limit'],
userData: userData,
readOnly: readOnly,
share: {

Loading…
Cancel
Save