From 21c47f5e57fe38ca44420f00f88fa1dc176e1a26 Mon Sep 17 00:00:00 2001 From: yflory Date: Tue, 1 Jun 2021 14:20:20 +0200 Subject: [PATCH] Realtime part of the description block in forms --- www/form/inner.js | 44 ++++++++++++++++++++++++++++++++++++++------ www/form/main.js | 31 ++++++++++++++++++++++++++++--- 2 files changed, 66 insertions(+), 9 deletions(-) diff --git a/www/form/inner.js b/www/form/inner.js index 893e5eddb..941cdfd4c 100644 --- a/www/form/inner.js +++ b/www/form/inner.js @@ -646,7 +646,6 @@ define([ return { tag: tag, edit: function (cb, tmp) { - // XXX use tmp and cursor getter var t = h('textarea'); var block = h('div.cp-form-edit-options-block', [t]); var cm = SFCodeMirror.create("gfm", CMeditor, t); @@ -655,9 +654,23 @@ define([ editor.setOption('lineWrapping', true); editor.setOption('styleActiveLine', true); editor.setOption('readOnly', false); - console.warn(APP.common); + + var text = opts.text; + var cursor; + if (tmp && tmp.content && tmp.old.text === text) { + text = tmp.content.text; + cursor = tmp.cursor; + } + setTimeout(function () { - editor.setValue(opts.text); + editor.setValue(text); + if (cursor) { + if (Sortify(cursor.start) === Sortify(cursor.end)) { + editor.setCursor(cursor.start); + } else { + editor.setSelection(cursor.start, cursor.end); + } + } editor.refresh(); editor.save(); editor.focus(); @@ -676,12 +689,31 @@ define([ h('i.fa.fa-floppy-o'), h('span', Messages.settings_save) ]); + + var getContent = function () { + return { + text: editor.getValue() + }; + }; $(saveBlock).click(function () { $(saveBlock).attr('disabled', 'disabled'); - cb({ - text: editor.getValue() - }); + cb(getContent()); }); + + cursorGetter = function () { + if (document.activeElement && block.contains(document.activeElement)) { + cursor = { + start: editor.getCursor('from'), + end: editor.getCursor('to') + } + } + return { + old: opts, + content: getContent(), + cursor: cursor + }; + }; + return [ block, h('div', [cancelBlock, saveBlock]) diff --git a/www/form/main.js b/www/form/main.js index cd96a3367..dd6bc0009 100644 --- a/www/form/main.js +++ b/www/form/main.js @@ -71,19 +71,24 @@ define([ curvePublic: publicKey, }; }; - sframeChan.on('Q_FORM_FETCH_ANSWERS', function (data, cb) { + sframeChan.on('Q_FORM_FETCH_ANSWERS', function (data, _cb) { + var cb = Utils.Util.once(_cb); var myKeys = {}; var myFormKeys; - var CPNetflux; + var accessKeys; + var CPNetflux, Pinpad; var network; nThen(function (w) { require([ '/bower_components/chainpad-netflux/chainpad-netflux.js', - ], w(function (_CPNetflux) { + '/common/pinpad.js', + ], w(function (_CPNetflux, _Pinpad) { CPNetflux = _CPNetflux; + Pinpad = _Pinpad; })); Cryptpad.getAccessKeys(w(function (_keys) { if (!Array.isArray(_keys)) { return; } + accessKeys = _keys; _keys.some(function (_k) { if ((!Cryptpad.initialTeam && !_k.id) || Cryptpad.initialTeam === _k.id) { @@ -122,6 +127,26 @@ define([ // XXX Cache }; var results = {}; + config.onError = function (info) { + cb({ error: info.type }); + }; + config.onRejected = function (data, cb) { + if (!Array.isArray(data) || !data.length || data[0].length !== 16) { + return void cb(true); + } + if (!Array.isArray(accessKeys)) { return void cb(true); } + network.historyKeeper = data[0]; + nThen(function (waitFor) { + accessKeys.forEach(function (obj) { + Pinpad.create(network, obj, waitFor(function (e) { + console.log('done', obj); + if (e) { console.error(e); } + })); + }); + }).nThen(function () { + cb(); + }); + }; config.onReady = function () { var myKey; // If we have submitted an anonymous answer, retrieve it