Merge branch 'autostore' into staging

This commit is contained in:
yflory
2018-08-30 10:26:19 +02:00
17 changed files with 529 additions and 98 deletions

View File

@@ -879,5 +879,52 @@ define([
UI.createRadio = Pages.createRadio;
UI.cornerPopup = function (text, actions, footer, startHidden) {
var minimize = h('div.cp-corner-minimize.fa.fa-window-minimize');
var maximize = h('div.cp-corner-maximize.fa.fa-window-maximize');
var popup = h('div.cp-corner-container', [
minimize,
maximize,
h('div.cp-corner-filler', { style: "width:130px;" }),
h('div.cp-corner-filler', { style: "width:90px;" }),
h('div.cp-corner-filler', { style: "width:60px;" }),
h('div.cp-corner-filler', { style: "width:40px;" }),
h('div.cp-corner-filler', { style: "width:20px;" }),
h('div.cp-corner-text', text),
h('div.cp-corner-actions', actions),
Pages.setHTML(h('div.cp-corner-footer'), footer)
]);
$(minimize).click(function () {
$(popup).addClass('cp-minimized');
});
$(maximize).click(function () {
$(popup).removeClass('cp-minimized');
});
if (startHidden) {
$(popup).addClass('cp-minimized');
}
var hide = function () {
$(popup).hide();
};
var show = function () {
$(popup).show();
};
var deletePopup = function () {
$(popup).remove();
};
$('body').append(popup);
return {
popup: popup,
hide: hide,
show: show,
delete: deletePopup
};
};
return UI;
});

View File

@@ -722,27 +722,32 @@ define([
button
.click(common.prepareFeedback(type))
.click(function() {
sframeChan.query('Q_IS_ONLY_IN_SHARED_FOLDER', null, function (err, res) {
if (err || res.error) { return void console.log(err || res.error); }
var msg = Messages.forgetPrompt;
if (res) {
UI.alert(Messages.sharedFolders_forget);
return;
} else if (!common.isLoggedIn()) {
msg = Messages.fm_removePermanentlyDialog;
common.isPadStored(function (err, data) {
if (!data) {
return void UI.alert(Messages.autostore_notAvailable);
}
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();
sframeChan.query('Q_IS_ONLY_IN_SHARED_FOLDER', null, function (err, res) {
if (err || res.error) { return void console.log(err || res.error); }
var msg = Messages.forgetPrompt;
if (res) {
UI.alert(Messages.sharedFolders_forget);
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;
@@ -807,7 +812,14 @@ define([
title: Messages.tags_title,
})
.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;
case 'toggle':
button = $('<button>', {
@@ -844,11 +856,16 @@ define([
.text(Messages.propertiesButton))
.click(common.prepareFeedback(type))
.click(function () {
getPropertiesData(common, function (e, data) {
if (e) { return void console.error(e); }
UIElements.getProperties(common, data, function (e, $prop) {
common.isPadStored(function (err, data) {
if (!data) {
return void UI.alert(Messages.autostore_notAvailable);
}
getPropertiesData(common, function (e, data) {
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);
});
});
});
});
@@ -2308,5 +2325,44 @@ define([
$(password).find('.cp-password-input').focus();
};
var storePopupState = false;
UIElements.displayStorePadPopup = function (common, data) {
if (storePopupState) { return; }
storePopupState = true;
var text = Messages.autostore_notstored;
var footer = Messages.autostore_settings;
var hide = h('button.cp-corner-cancel', Messages.autostore_hide);
var store = h('button.cp-corner-primary', Messages.autostore_store);
var actions = h('div', [
store,
hide,
]);
var initialHide = data && data.autoStore && data.autoStore === -1;
var modal = UI.cornerPopup(text, actions, footer, initialHide);
$(modal.popup).find('.cp-corner-footer a').click(function (e) {
e.preventDefault();
common.openURL('/settings/');
});
$(hide).click(function () {
modal.delete();
});
$(store).click(function () {
modal.delete();
common.getSframeChannel().query("Q_AUTOSTORE_STORE", null, function (err, obj) {
if (err || (obj && obj.error)) {
console.error(err || obj.error);
return void UI.warn(Messages.autostore_error);
}
UI.log(Messages.autostore_saved);
});
});
};
return UIElements;
});

View File

@@ -547,7 +547,7 @@ define([
postMessage("SET_PAD_TITLE", data, function (obj) {
if (obj && obj.error) {
console.log("unable to set pad title");
if (obj.error !== "EAUTH") { console.log("unable to set pad title"); }
return void cb(obj.error);
}
cb();
@@ -925,6 +925,10 @@ define([
common.loading = {};
common.loading.onDriveEvent = Util.mkEvent();
// (Auto)store pads
common.autoStore = {};
common.autoStore.onStoreRequest = Util.mkEvent();
common.getFullHistory = function (data, cb) {
postMessage("GET_FULL_HISTORY", data, cb);
};
@@ -1070,7 +1074,9 @@ define([
// Account deletion
DELETE_ACCOUNT: common.startAccountDeletion,
// Loading
LOADING_DRIVE: common.loading.onDriveEvent.fire
LOADING_DRIVE: common.loading.onDriveEvent.fire,
// AutoStore
AUTOSTORE_DISPLAY_POPUP: common.autoStore.onStoreRequest.fire,
};
common.hasCSSVariables = function () {

View File

@@ -772,22 +772,32 @@ define([
// Add the pad if it does not exist in our drive
if (!contains) {
var roHref;
if (h.mode === "view") {
roHref = href;
href = undefined;
var autoStore = Util.find(store.proxy, ['settings', 'general', 'autostore']);
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
postMessage(clientId, "AUTOSTORE_DISPLAY_POPUP", {
autoStore: autoStore
});
return void cb();
} else {
var roHref;
if (h.mode === "view") {
roHref = href;
href = undefined;
}
Store.addPad(clientId, {
href: href,
roHref: roHref,
channel: channel,
title: title,
owners: owners,
expire: expire,
password: data.password,
path: data.path
}, cb);
return;
}
Store.addPad(clientId, {
href: href,
roHref: roHref,
channel: channel,
title: title,
owners: owners,
expire: expire,
password: data.password,
path: data.path
}, cb);
return;
} else {
sendDriveEvent('DRIVE_CHANGE', {
path: ['drive', UserObject.FILES_DATA]

View File

@@ -17,6 +17,7 @@ define([
var path = file.path;
var password = file.password;
var forceSave = file.forceSave;
var hash, secret, key, id, href;
var getNewHash = function () {
@@ -93,7 +94,8 @@ define([
path: path,
password: password,
channel: id,
owners: metadata.owners
owners: metadata.owners,
forceSave: forceSave
};
common.setPadTitle(data, function (err) {
if (err) { return void console.error(err); }

View File

@@ -233,6 +233,13 @@ define([
return q;
};
var privateData = common.getMetadataMgr().getPrivateData();
var autoStore = Util.find(privateData, ['settings', 'general', 'autostore']) || 0;
var manualStore = autoStore === 1 ? undefined :
UI.createCheckbox('cp-upload-store', Messages.autostore_forceSave, true, {
input: { disabled: true }
});
// Ask for name, password and owner
var content = h('div', [
h('h4', Messages.upload_modal_title),
@@ -247,8 +254,18 @@ define([
UI.createCheckbox('cp-upload-owned', Messages.upload_modal_owner, true),
createHelper('/faq.html#keywords-owned', Messages.creation_owned1)
]),
manualStore
]);
$(content).find('#cp-upload-owned').on('change', function () {
var val = $(content).find('#cp-upload-owned').is(':checked');
if (val) {
$(content).find('#cp-upload-store').prop('checked', true).prop('disabled', true);
} else {
$(content).find('#cp-upload-store').prop('disabled', false);
}
});
UI.confirm(content, function (yes) {
if (!yes) { return void cb(); }
@@ -256,6 +273,7 @@ define([
var newName = $(content).find('#cp-upload-name').val();
var password = $(content).find('#cp-upload-password').val() || undefined;
var owned = $(content).find('#cp-upload-owned').is(':checked');
var forceSave = owned || $(content).find('#cp-upload-store').is(':checked');
// Add extension to the name if needed
if (!newName || !newName.trim()) { newName = file.name; }
@@ -266,7 +284,8 @@ define([
cb({
name: newName,
password: password,
owned: owned
owned: owned,
forceSave: forceSave
});
});
};
@@ -284,6 +303,7 @@ define([
var name = file.name;
var password;
var owned = true;
var forceSave;
var finish = function (abort) {
if (!abort) {
var metadata = {
@@ -296,6 +316,7 @@ define([
metadata: metadata,
password: password,
owned: owned,
forceSave: forceSave,
dropEvent: e
});
}
@@ -316,6 +337,7 @@ define([
name = obj.name;
password = obj.password;
owned = obj.owned;
forceSave = obj.forceSave;
finish();
});
};

View File

@@ -358,6 +358,27 @@ define([
setDocumentTitle();
});
Cryptpad.autoStore.onStoreRequest.reg(function (data) {
sframeChan.event("EV_AUTOSTORE_DISPLAY_POPUP", data);
});
sframeChan.on('Q_AUTOSTORE_STORE', function (obj, cb) {
var data = {
password: password,
title: currentTitle,
channel: secret.channel,
path: initialPathInDrive, // Where to store the pad if we don't have it in our drive
forceSave: true
};
Cryptpad.setPadTitle(data, function (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) {
Cryptpad.setDisplayName(newName, function (err) {
@@ -399,6 +420,7 @@ define([
Cryptpad.saveAsTemplate(Cryptget.put, data, cb);
});
// Messaging
sframeChan.on('Q_SEND_FRIEND_REQUEST', function (netfluxId, cb) {
Cryptpad.inviteFromUserlist(netfluxId, cb);
});
@@ -411,6 +433,7 @@ define([
sframeChan.event('EV_FRIEND_REQUEST', data);
});
// History
sframeChan.on('Q_GET_FULL_HISTORY', function (data, cb) {
var crypto = Crypto.createEncryptor(secret.keys);
Cryptpad.getFullHistory({
@@ -452,6 +475,7 @@ define([
});
});
// Store
sframeChan.on('Q_GET_PAD_ATTRIBUTE', function (data, cb) {
var href;
if (readOnly && hashes.editHash) {

View File

@@ -206,6 +206,12 @@ define([
}, 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) {
ctx.sframeChan.query('Q_ANON_RPC_MESSAGE', {
msg: msg,
@@ -452,6 +458,10 @@ define([
UI.errorLoadingScreen($err, true, true);
});
ctx.sframeChan.on('EV_AUTOSTORE_DISPLAY_POPUP', function (data) {
UIElements.displayStorePadPopup(funcs, data);
});
ctx.metadataMgr.onReady(waitFor());
}).nThen(function () {
try {

View File

@@ -257,4 +257,8 @@ define({
// Get all existing tags
'Q_GET_ALL_TAGS': true,
// Store pads in the drive
'EV_AUTOSTORE_DISPLAY_POPUP': true,
'Q_AUTOSTORE_STORE': true,
'Q_IS_PAD_STORED': true,
});