Realtime part of the description block in forms

This commit is contained in:
yflory 2021-06-01 14:20:20 +02:00
parent ce6879fd68
commit 21c47f5e57
2 changed files with 66 additions and 9 deletions

View File

@ -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])

View File

@ -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