Form fixes and improvements

pull/1/head
yflory 3 years ago
parent 511ec211c1
commit 212b3d4884

@ -1925,7 +1925,6 @@ define([
var cryptputCfg = $.extend(true, {}, rtConfig, {password: password}); var cryptputCfg = $.extend(true, {}, rtConfig, {password: password});
if (data.templateContent) { if (data.templateContent) {
Cryptget.put(currentPad.hash, JSON.stringify(data.templateContent), function () { Cryptget.put(currentPad.hash, JSON.stringify(data.templateContent), function () {
console.error(arguments);
startRealtime(); startRealtime();
cb(); cb();
}, cryptputCfg); }, cryptputCfg);

@ -247,6 +247,14 @@
.cp-form-anon-answer { .cp-form-anon-answer {
text-align: center; text-align: center;
margin: 20px 0 30px 0; margin: 20px 0 30px 0;
.cp-form-anon-answer-input {
display: flex;
white-space: nowrap;
align-items: center;
input {
margin-left: 10px;
}
}
} }
} }
@ -669,6 +677,12 @@
.avatar_main(30px); .avatar_main(30px);
margin-right: 10px; margin-right: 10px;
} }
&.cp-clickable {
cursor: pointer;
&:hover {
transform: scale(1.1);
}
}
} }
.cp-poll-time-day { .cp-poll-time-day {
flex-basis: 100px; flex-basis: 100px;

@ -588,7 +588,9 @@ define([
return weekDays.map(function (day) { return day.replace(/^./, function (str) { return str.toUpperCase(); }); }); return weekDays.map(function (day) { return day.replace(/^./, function (str) { return str.toUpperCase(); }); });
}; };
var makePollTable = function (answers, opts) { // "resultsPageObj" is an object with "content" and "answers"
// only available when viewing the Responses page
var makePollTable = function (answers, opts, resultsPageObj) {
// Sort date values // Sort date values
if (opts.type !== "text") { if (opts.type !== "text") {
opts.values.sort(function (a, b) { opts.values.sort(function (a, b) {
@ -607,7 +609,7 @@ define([
_date = new Date(data); _date = new Date(data);
data = Flatpickr.formatDate(_date, timeFormat); data = Flatpickr.formatDate(_date, timeFormat);
} }
var day = allDays[_date.getDay()]; var day = _date && allDays[_date.getDay()];
return h('div.cp-poll-cell.cp-form-poll-option', { return h('div.cp-poll-cell.cp-form-poll-option', {
title: Util.fixHTML(data) title: Util.fixHTML(data)
}, [ }, [
@ -667,13 +669,19 @@ define([
}, v); }, v);
return cell; return cell;
}); });
els.unshift(h('div.cp-poll-cell.cp-poll-answer-name', { var nameCell;
els.unshift(nameCell = h('div.cp-poll-cell.cp-poll-answer-name', {
title: Util.fixHTML(name) title: Util.fixHTML(name)
}, [ }, [
avatar, avatar,
h('span', name) h('span', name)
])); ]));
bodyEls.push(h('div', els)); bodyEls.push(h('div', els));
if (resultsPageObj && (APP.isEditor || APP.isAuditor)) {
$(nameCell).addClass('cp-clickable').click(function () {
APP.renderResults(resultsPageObj.content, resultsPageObj.answers, answerObj.curve);
});
}
}); });
} }
var body = h('div.cp-form-poll-body', bodyEls); var body = h('div.cp-form-poll-body', bodyEls);
@ -815,6 +823,7 @@ define([
if (filterCurve && user === filterCurve) { return; } if (filterCurve && user === filterCurve) { return; }
try { try {
return { return {
curve: user,
user: answers[user].msg._userdata, user: answers[user].msg._userdata,
results: answers[user].msg[uid] results: answers[user].msg[uid]
}; };
@ -1615,7 +1624,7 @@ define([
if (!opts) { opts = TYPES.poll.defaultOpts; } if (!opts) { opts = TYPES.poll.defaultOpts; }
if (!Array.isArray(opts.values)) { return; } if (!Array.isArray(opts.values)) { return; }
var lines = makePollTable(answers, opts); var lines = makePollTable(answers, opts, false);
// Add form // Add form
var addLine = opts.values.map(function (data) { var addLine = opts.values.map(function (data) {
@ -1699,10 +1708,16 @@ define([
}; };
}, },
printResults: function (answers, uid, form) { printResults: function (answers, uid, form, content) {
var opts = form[uid].opts || TYPES.poll.defaultOpts; var opts = form[uid].opts || TYPES.poll.defaultOpts;
var _answers = getBlockAnswers(answers, uid); var _answers = getBlockAnswers(answers, uid);
var lines = makePollTable(_answers, opts);
// If content is defined, we'll be able to click on a row to display
// all the answers of this user
var lines = makePollTable(_answers, opts, content && {
content: content,
answers: answers
});
var total = makePollTotal(_answers, opts); var total = makePollTotal(_answers, opts);
if (total) { lines.push(h('div', total)); } if (total) { lines.push(h('div', total)); }
@ -1723,7 +1738,7 @@ define([
}, },
}; };
var renderResults = function (content, answers) { var renderResults = APP.renderResults = function (content, answers, showUser) {
var $container = $('div.cp-form-creator-results').empty(); var $container = $('div.cp-form-creator-results').empty();
if (!Object.keys(answers || {}).length) { if (!Object.keys(answers || {}).length) {
@ -1767,7 +1782,9 @@ define([
var type = block.type; var type = block.type;
var model = TYPES[type]; var model = TYPES[type];
if (!model || !model.printResults) { return; } if (!model || !model.printResults) { return; }
var print = model.printResults(answers, uid, form);
// Only use content if we're not viewing individual answers
var print = model.printResults(answers, uid, form, !header && content);
var q = h('div.cp-form-block-question', block.q || Messages.form_default); var q = h('div.cp-form-block-question', block.q || Messages.form_default);
@ -1861,10 +1878,19 @@ define([
e.preventDefault(); e.preventDefault();
APP.common.openURL(Hash.hashToHref(ud.profile, 'profile')); APP.common.openURL(Hash.hashToHref(ud.profile, 'profile'));
}); });
if (showUser === curve) {
setTimeout(function () {
showUser = undefined;
$(viewButton).click();
});
}
return div; return div;
}); });
$results.append(els); $results.append(els);
}); });
if (showUser) {
$s.click();
}
}; };
var addResultsButton = function (framework, content) { var addResultsButton = function (framework, content) {
@ -1910,16 +1936,34 @@ define([
var makeFormControls = function (framework, content, update, evOnChange) { var makeFormControls = function (framework, content, update, evOnChange) {
var loggedIn = framework._.sfCommon.isLoggedIn(); var loggedIn = framework._.sfCommon.isLoggedIn();
var metadataMgr = framework._.cpNfInner.metadataMgr; var metadataMgr = framework._.cpNfInner.metadataMgr;
var user = metadataMgr.getUserData();
if (!loggedIn && !content.answers.anonymous) { return; } if (!loggedIn && !content.answers.anonymous) { return; }
var cbox; var cbox;
var anonName, $anonName;
cbox = UI.createCheckbox('cp-form-anonymous', cbox = UI.createCheckbox('cp-form-anonymous',
Messages.form_anonymousBox, true, { mark: { tabindex:1 } }); Messages.form_anonymousBox, true, { mark: { tabindex:1 } });
var $anonBox = $(cbox).find('input');
if (loggedIn) { if (loggedIn) {
if (!content.answers.anonymous || APP.cantAnon) { if (!content.answers.anonymous || APP.cantAnon) {
$(cbox).hide().find('input').attr('disabled', 'disabled').prop('checked', false); $(cbox).hide().find('input').attr('disabled', 'disabled').prop('checked', false);
} }
} else {
Messages.form_anonName = "Your username"; // XXX
Messages.form_answerAs = "Answer as"; // XXX
anonName = h('div.cp-form-anon-answer-input', [
Messages.form_answerAs,
h('input', {
value: user.name || '',
placeholder: Messages.form_anonName
})
])
$anonName = $(anonName).hide();
$anonBox.on('change', function () {
if (Util.isChecked($anonBox)) { $anonName.hide(); }
else { $anonName.show(); }
});
} }
var send = h('button.cp-open.btn.btn-primary', update ? Messages.form_update : Messages.form_submit); var send = h('button.cp-open.btn.btn-primary', update ? Messages.form_update : Messages.form_submit);
@ -1937,14 +1981,16 @@ define([
if (!results) { return; } if (!results) { return; }
var user = metadataMgr.getUserData(); var user = metadataMgr.getUserData();
if (!Util.isChecked($(cbox).find('input'))) { if (!Util.isChecked($anonBox)) {
results._userdata = loggedIn ? { results._userdata = loggedIn ? {
avatar: user.avatar, avatar: user.avatar,
name: user.name, name: user.name,
notifications: user.notifications, notifications: user.notifications,
curvePublic: user.curvePublic, curvePublic: user.curvePublic,
profile: user.profile profile: user.profile
} : { name: user.name }; } : {
name: $anonName ? $anonName.find('input').val() : user.name
};
} }
var sframeChan = framework._.sfCommon.getSframeChannel(); var sframeChan = framework._.sfCommon.getSframeChannel();
@ -2024,7 +2070,10 @@ define([
return h('div.cp-form-send-container', [ return h('div.cp-form-send-container', [
invalid, invalid,
cbox ? h('div.cp-form-anon-answer', cbox) : undefined, cbox ? h('div.cp-form-anon-answer', [
cbox,
anonName
]) : undefined,
reset, send reset, send
]); ]);
}; };

Loading…
Cancel
Save