Disable some toolbar features not available if the pad is not stored

This commit is contained in:
yflory 2018-08-28 12:12:47 +02:00
parent 9ebb598467
commit d201e9a0cd
6 changed files with 54 additions and 23 deletions

View File

@ -1242,6 +1242,7 @@ define(function () {
out.autostore_error = "Unexpected error: we were unable to store this pad, please try again."; out.autostore_error = "Unexpected error: we were unable to store this pad, please try again.";
out.autostore_saved = "The pad was successfully stored in your CryptDrive!"; out.autostore_saved = "The pad was successfully stored in your CryptDrive!";
out.autostore_forceSave = "Store the file in CryptDrive"; // File upload modal out.autostore_forceSave = "Store the file in CryptDrive"; // File upload modal
out.autostore_notAvailable = "You must store this pad in your CryptDrive before being able to use this feature."; // Properties/tags/move to trash
return out; return out;
}); });

View File

@ -722,27 +722,32 @@ define([
button button
.click(common.prepareFeedback(type)) .click(common.prepareFeedback(type))
.click(function() { .click(function() {
sframeChan.query('Q_IS_ONLY_IN_SHARED_FOLDER', null, function (err, res) { common.isPadStored(function (err, data) {
if (err || res.error) { return void console.log(err || res.error); } if (!data) {
var msg = Messages.forgetPrompt; return void UI.alert(Messages.autostore_notAvailable);
if (res) {
UI.alert(Messages.sharedFolders_forget);
return;
} else if (!common.isLoggedIn()) {
msg = Messages.fm_removePermanentlyDialog;
} }
UI.confirm(msg, function (yes) { sframeChan.query('Q_IS_ONLY_IN_SHARED_FOLDER', null, function (err, res) {
if (!yes) { return; } if (err || res.error) { return void console.log(err || res.error); }
sframeChan.query('Q_MOVE_TO_TRASH', null, function (err) { var msg = Messages.forgetPrompt;
if (err) { return void callback(err); } if (res) {
var cMsg = common.isLoggedIn() ? Messages.movedToTrash : Messages.deleted; UI.alert(Messages.sharedFolders_forget);
var msg = common.fixLinks($('<div>').html(cMsg));
UI.alert(msg);
callback();
return; return;
} else if (!common.isLoggedIn()) {
msg = Messages.fm_removePermanentlyDialog;
}
UI.confirm(msg, function (yes) {
if (!yes) { return; }
sframeChan.query('Q_MOVE_TO_TRASH', null, function (err) {
if (err) { return void callback(err); }
var cMsg = common.isLoggedIn() ? Messages.movedToTrash : Messages.deleted;
var msg = common.fixLinks($('<div>').html(cMsg));
UI.alert(msg);
callback();
return;
});
}); });
});
});
}); });
}); });
break; break;
@ -807,7 +812,14 @@ define([
title: Messages.tags_title, title: Messages.tags_title,
}) })
.click(common.prepareFeedback(type)) .click(common.prepareFeedback(type))
.click(function () { UIElements.updateTags(common, null); }); .click(function () {
common.isPadStored(function (err, data) {
if (!data) {
return void UI.alert(Messages.autostore_notAvailable);
}
UIElements.updateTags(common, null);
});
});
break; break;
case 'toggle': case 'toggle':
button = $('<button>', { button = $('<button>', {
@ -844,11 +856,16 @@ define([
.text(Messages.propertiesButton)) .text(Messages.propertiesButton))
.click(common.prepareFeedback(type)) .click(common.prepareFeedback(type))
.click(function () { .click(function () {
getPropertiesData(common, function (e, data) { common.isPadStored(function (err, data) {
if (e) { return void console.error(e); } if (!data) {
UIElements.getProperties(common, data, function (e, $prop) { return void UI.alert(Messages.autostore_notAvailable);
}
getPropertiesData(common, function (e, data) {
if (e) { return void console.error(e); } if (e) { return void console.error(e); }
UI.alert($prop[0], undefined, true); UIElements.getProperties(common, data, function (e, $prop) {
if (e) { return void console.error(e); }
UI.alert($prop[0], undefined, true);
});
}); });
}); });
}); });

View File

@ -766,7 +766,8 @@ define([
// Add the pad if it does not exist in our drive // Add the pad if it does not exist in our drive
if (!contains) { if (!contains) {
var autoStore = Util.find(store.proxy, ['settings', 'general', 'autostore']); var autoStore = Util.find(store.proxy, ['settings', 'general', 'autostore']);
if (autoStore !== 1 && !data.forceSave && !data.path) { var ownedByMe = Array.isArray(owners) && owners.indexOf(store.proxy.edPublic) !== -1;
if (autoStore !== 1 && !data.forceSave && !data.path && !ownedByMe) {
// send event to inner to display the corner popup // send event to inner to display the corner popup
postMessage(clientId, "AUTOSTORE_DISPLAY_POPUP", { postMessage(clientId, "AUTOSTORE_DISPLAY_POPUP", {
autoStore: autoStore autoStore: autoStore

View File

@ -373,6 +373,11 @@ define([
cb(err); cb(err);
}); });
}); });
sframeChan.on('Q_IS_PAD_STORED', function (data, cb) {
Cryptpad.getPadAttribute('title', function (err, data) {
cb (!err && typeof (data) === "string");
});
});
sframeChan.on('Q_SETTINGS_SET_DISPLAY_NAME', function (newName, cb) { sframeChan.on('Q_SETTINGS_SET_DISPLAY_NAME', function (newName, cb) {

View File

@ -206,6 +206,12 @@ define([
}, cb); }, cb);
}; };
funcs.isPadStored = function (cb) {
ctx.sframeChan.query("Q_IS_PAD_STORED", null, function (err, obj) {
cb (err || (obj && obj.error), obj);
});
};
funcs.sendAnonRpcMsg = function (msg, content, cb) { funcs.sendAnonRpcMsg = function (msg, content, cb) {
ctx.sframeChan.query('Q_ANON_RPC_MESSAGE', { ctx.sframeChan.query('Q_ANON_RPC_MESSAGE', {
msg: msg, msg: msg,

View File

@ -257,4 +257,5 @@ define({
// Store pads in the drive // Store pads in the drive
'EV_AUTOSTORE_DISPLAY_POPUP': true, 'EV_AUTOSTORE_DISPLAY_POPUP': true,
'Q_AUTOSTORE_STORE': true, 'Q_AUTOSTORE_STORE': true,
'Q_IS_PAD_STORED': true,
}); });