From aaed6b7d770d3c8df70b39c835f996ef6cc5da9c Mon Sep 17 00:00:00 2001 From: yflory Date: Fri, 24 Sep 2021 16:31:26 +0200 Subject: [PATCH] Apply form results to new sheet --- www/common/common-ui-elements.js | 9 +++++++++ www/common/onlyoffice/inner.js | 10 ++++++++++ www/common/sframe-common-outer.js | 8 ++++++++ www/form/inner.js | 7 ++++++- www/form/main.js | 9 ++++++++- 5 files changed, 41 insertions(+), 2 deletions(-) diff --git a/www/common/common-ui-elements.js b/www/common/common-ui-elements.js index 08e0bcf07..4be00efec 100644 --- a/www/common/common-ui-elements.js +++ b/www/common/common-ui-elements.js @@ -2268,6 +2268,7 @@ define([ var type = metadataMgr.getMetadataLazy().type || privateData.app; var fromFileData = privateData.fromFileData; + var fromContent = privateData.fromContent; var $body = $('body'); var $creationContainer = $('
', { id: 'cp-creation-container' }).appendTo($body); @@ -2524,6 +2525,14 @@ define([ todo(res.data); }); } + else if (fromContent) { + allData = [{ + name: fromContent.title, + id: 0, + icon: h('span.cptools.cptools-poll'), + }]; + redraw(0); + } else { redraw(0); } diff --git a/www/common/onlyoffice/inner.js b/www/common/onlyoffice/inner.js index 7bbfc7d0d..e1ee042ee 100644 --- a/www/common/onlyoffice/inner.js +++ b/www/common/onlyoffice/inner.js @@ -1440,11 +1440,16 @@ define([ // to be downloaded and decrypted before converting to xlsx var downloadImages = {}; + var firstOO = true; startOO = function (blob, file, force) { if (APP.ooconfig && !force) { return void console.error('already started'); } var url = URL.createObjectURL(blob); var lock = !APP.history && (APP.migrate); + var fromContent = metadataMgr.getPrivateData().fromContent; + if (!firstOO) { fromContent = undefined; } + firstOO = false; + // Starting from version 3, we can use the view mode again // defined but never used //var mode = (content && content.version > 2 && lock) ? "view" : "edit"; @@ -1606,6 +1611,11 @@ define([ } } + if (fromContent && !lock && Array.isArray(fromContent.content)) { + console.warn(fromContent); + makePatch(fromContent.content); + } + if (APP.isDownload) { var bin = getContent(); if (!supportsXLSX()) { diff --git a/www/common/sframe-common-outer.js b/www/common/sframe-common-outer.js index 21344cd3f..bce02657b 100644 --- a/www/common/sframe-common-outer.js +++ b/www/common/sframe-common-outer.js @@ -300,6 +300,13 @@ define([ })); }; + if (sessionStorage.CP_formExportSheet && parsed.type === 'sheet') { + try { + Cryptpad.fromContent = JSON.parse(sessionStorage.CP_formExportSheet); + } catch (e) { console.error(e); } + delete sessionStorage.CP_formExportSheet; + } + // New pad options var options = parsed.getOptions(); if (options.newPadOpts) { @@ -639,6 +646,7 @@ define([ fromFileData: Cryptpad.fromFileData ? (isOO ? Cryptpad.fromFileData : { title: Cryptpad.fromFileData.title }) : undefined, + fromContent: Cryptpad.fromContent, burnAfterReading: burnAfterReading, storeInTeam: Cryptpad.initialTeam || (Cryptpad.initialPath ? -1 : undefined), supportsWasm: Utils.Util.supportsWasm() diff --git a/www/form/inner.js b/www/form/inner.js index c46ccb43a..0920bfa5f 100644 --- a/www/form/inner.js +++ b/www/form/inner.js @@ -2647,7 +2647,12 @@ define([ $(export2Button).click(function () { var arr = Exporter.results(content, answers, TYPES, true); if (!arr) { return void UI.warn(Messages.error); } - console.error(arr); + var sframeChan = framework._.sfCommon.getSframeChannel(); + var title = framework._.title.title || framework._.title.defaultTitle; + sframeChan.event('EV_EXPORT_SHEET', { + title: title, + content: arr + }); }); var summary = true; diff --git a/www/form/main.js b/www/form/main.js index 7204435d2..8993749fb 100644 --- a/www/form/main.js +++ b/www/form/main.js @@ -51,7 +51,14 @@ define([ Cryptpad.setPadAttribute('answersChannel', data.channel, function () {}); }); }); - + }); + sframeChan.on('EV_EXPORT_SHEET', function (data) { + if (!data || !Array.isArray(data.content)) { return; } + sessionStorage.CP_formExportSheet = JSON.stringify(data); + var href = Utils.Hash.hashToHref('', 'sheet'); + var a = window.open(href); + if (!a) { sframeChan.event('EV_POPUP_BLOCKED'); } + delete sessionStorage.CP_formExportSheet; }); var getAnonymousKeys = function (formSeed, channel) { var array = Nacl.util.decodeBase64(formSeed + channel);