From e8a5244362ffc9bf59f0a53b4d89874c33a2e385 Mon Sep 17 00:00:00 2001 From: yflory Date: Mon, 27 Aug 2018 14:58:09 +0200 Subject: [PATCH] Autostore base --- customize.dist/src/less2/include/corner.less | 75 +++++++++++++++++++ .../src/less2/include/framework.less | 3 + customize.dist/translations/messages.js | 6 ++ www/common/common-interface.js | 32 ++++++++ www/common/common-ui-elements.js | 34 +++++++++ www/common/cryptpad-common.js | 10 ++- www/common/outer/async-store.js | 40 ++++++---- www/common/outer/upload.js | 3 +- www/common/sframe-common-outer.js | 19 +++++ www/common/sframe-common.js | 4 + www/common/sframe-protocol.js | 3 + 11 files changed, 211 insertions(+), 18 deletions(-) create mode 100644 customize.dist/src/less2/include/corner.less diff --git a/customize.dist/src/less2/include/corner.less b/customize.dist/src/less2/include/corner.less new file mode 100644 index 000000000..5b140d217 --- /dev/null +++ b/customize.dist/src/less2/include/corner.less @@ -0,0 +1,75 @@ +@import (reference) "./colortheme-all.less"; + +.corner_main() { + --LessLoader_require: LessLoader_currentFile(); +}; +& { + @corner-button-ok: #2c9b00; + @corner-button-cancel: #990000; + + @keyframes appear { + 0% { + transform: scale(0.1); + } + 100% { + transform: scale(1.0); + } + } + + .cp-corner-container { + position: absolute; + right: 0; + bottom: 0; + width: 300px; + height: 200px; + border-top-left-radius: 200px; + padding: 15px; + text-align: right; + background-color: @colortheme_logo-1; + color: @colortheme_base; + z-index: 999; + scale: 0.1; + transform-origin: bottom right; + animation: appear 0.8s ease-in-out; + + .cp-corner-filler { + float: left; + clear: left; + height: 21px; + } + .cp-corner-text { + + } + .cp-corner-actions { + min-height: 30px; + margin: 15px auto; + display: inline-block; + } + .cp-corner-footer { + font-style: italic; + font-size: 0.8em; + } + + button { + color: white; + border: 0px; + padding: 5px; + color: @colortheme_base; + &.cp-corner-primary { + background-color: @corner-button-ok; + font-weight: bold; + &:hover { + background-color: lighten(@corner-button-ok, 10%); + } + } + &.cp-corner-cancel { + background-color: @corner-button-cancel; + margin-left: 10px; + &:hover { + background-color: lighten(@corner-button-cancel, 10%); + } + } + } + } +} + diff --git a/customize.dist/src/less2/include/framework.less b/customize.dist/src/less2/include/framework.less index 5caa847f4..f46018b8c 100644 --- a/customize.dist/src/less2/include/framework.less +++ b/customize.dist/src/less2/include/framework.less @@ -2,6 +2,7 @@ @import (reference) "./toolbar.less"; @import (reference) './fileupload.less'; @import (reference) './alertify.less'; +@import (reference) './corner.less'; @import (reference) './tokenfield.less'; @import (reference) './creation.less'; @import (reference) './tippy.less'; @@ -27,6 +28,7 @@ @color: @color ); .alertify_main(); + .corner_main(); .fileupload_main(); .tokenfield_main(); .tippy_main(); @@ -60,6 +62,7 @@ ); .fileupload_main(); .alertify_main(); + .corner_main(); .tippy_main(); .checkmark_main(20px); .password_main(); diff --git a/customize.dist/translations/messages.js b/customize.dist/translations/messages.js index f29290bff..c812f095b 100644 --- a/customize.dist/translations/messages.js +++ b/customize.dist/translations/messages.js @@ -1226,5 +1226,11 @@ define(function () { out.sharedFolders_create_password = "Folder password"; out.sharedFolders_share = "Share this URL with other registered users to give them access to the shared folder. Once they open this URL, the shared folder will be added to the root directory of their CryptDrive."; + // Manual pad storage popup + out.manual_notstored = "This pad is not stored in your drive. Do you want to store it now?"; // XXX + out.manual_settings = "You can enable automatic pad storage in your Settings page!"; // XXX + out.manual_store = "Store"; + out.manual_hide = "Don't store"; + return out; }); diff --git a/www/common/common-interface.js b/www/common/common-interface.js index a6bc0aec3..07ec891ef 100644 --- a/www/common/common-interface.js +++ b/www/common/common-interface.js @@ -879,5 +879,37 @@ define([ UI.createRadio = Pages.createRadio; + UI.cornerPopup = function (text, actions, footer) { + // XXX create "minimize" icon + var popup = h('div.cp-corner-container', [ + 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), + h('div.cp-corner-footer', footer) + ]); + + var hide = function () { + $(popup).hide(); + }; + var show = function () { + $(popup).show(); + }; + var deletePopup = function () { + $(popup).remove(); + }; + + $('body').append(popup); + + return { + hide: hide, + show: show, + delete: deletePopup + }; + }; + return UI; }); diff --git a/www/common/common-ui-elements.js b/www/common/common-ui-elements.js index fc54da947..8087f5af9 100644 --- a/www/common/common-ui-elements.js +++ b/www/common/common-ui-elements.js @@ -2308,5 +2308,39 @@ define([ $(password).find('.cp-password-input').focus(); }; + var storePopupState = false; + UIElements.displayStorePadPopup = function (common) { + if (storePopupState) { return; } + storePopupState = true; + + var text = Messages.manual_notstored; + var footer = Messages.manual_settings; + + var hide = h('button.cp-corner-cancel', Messages.manual_hide); + var store = h('button.cp-corner-primary', Messages.manual_store); + var actions = h('div', [ + store, + hide, + ]); + + console.log(text, footer); + var modal = UI.cornerPopup(text, actions, footer); + + $(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("Error"); // XXX + } + UI.log("Saved"); // XXX + }); + }); + + }; + return UIElements; }); diff --git a/www/common/cryptpad-common.js b/www/common/cryptpad-common.js index 4652c104f..2c2f8b00b 100644 --- a/www/common/cryptpad-common.js +++ b/www/common/cryptpad-common.js @@ -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); }; @@ -1060,7 +1064,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 () { diff --git a/www/common/outer/async-store.js b/www/common/outer/async-store.js index 4cb0503bb..368a0b7e9 100644 --- a/www/common/outer/async-store.js +++ b/www/common/outer/async-store.js @@ -765,22 +765,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']); + if (autoStore !== 1 && !data.forceSave && !data.path) { + // XXX + // send event to inner to display the corner popup + postMessage(clientId, "AUTOSTORE_DISPLAY_POPUP", { + autoStore: autoStore + }); + return void cb({error: "EAUTH"}); + } 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] diff --git a/www/common/outer/upload.js b/www/common/outer/upload.js index 25029ed69..f2faefbe0 100644 --- a/www/common/outer/upload.js +++ b/www/common/outer/upload.js @@ -93,7 +93,8 @@ define([ path: path, password: password, channel: id, - owners: metadata.owners + owners: metadata.owners, + // XXX FORCESAVE ?? }; common.setPadTitle(data, function (err) { if (err) { return void console.error(err); } diff --git a/www/common/sframe-common-outer.js b/www/common/sframe-common-outer.js index 0761f1034..64c3581cb 100644 --- a/www/common/sframe-common-outer.js +++ b/www/common/sframe-common-outer.js @@ -358,6 +358,22 @@ 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_SETTINGS_SET_DISPLAY_NAME', function (newName, cb) { Cryptpad.setDisplayName(newName, function (err) { @@ -399,6 +415,7 @@ define([ Cryptpad.saveAsTemplate(Cryptget.put, data, cb); }); + // Messaging sframeChan.on('Q_SEND_FRIEND_REQUEST', function (netfluxId, cb) { Cryptpad.inviteFromUserlist(netfluxId, cb); }); @@ -411,6 +428,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 +470,7 @@ define([ }); }); + // Store sframeChan.on('Q_GET_PAD_ATTRIBUTE', function (data, cb) { var href; if (readOnly && hashes.editHash) { diff --git a/www/common/sframe-common.js b/www/common/sframe-common.js index 8331e5f60..64070a8c8 100644 --- a/www/common/sframe-common.js +++ b/www/common/sframe-common.js @@ -452,6 +452,10 @@ define([ UI.errorLoadingScreen($err, true, true); }); + ctx.sframeChan.on('EV_AUTOSTORE_DISPLAY_POPUP', function () { + UIElements.displayStorePadPopup(funcs); + }); + ctx.metadataMgr.onReady(waitFor()); }).nThen(function () { try { diff --git a/www/common/sframe-protocol.js b/www/common/sframe-protocol.js index fbe311ba8..8e3b4d035 100644 --- a/www/common/sframe-protocol.js +++ b/www/common/sframe-protocol.js @@ -254,4 +254,7 @@ define({ // Get all existing tags 'Q_GET_ALL_TAGS': true, + // Store pads in the drive + 'EV_AUTOSTORE_DISPLAY_POPUP': true, + 'Q_AUTOSTORE_STORE': true, });