Merge branch 'forms2' into formColor

pull/1/head
yflory 3 years ago
commit 9051a5e65d

@ -299,7 +299,7 @@
@cp_usergrid-selected-fg: @cryptpad_color_white;
// Other
@cp_shadow-color: fade(@cryptpad_color_black, 40%);
@cp_shadow-color: fade(@cryptpad_color_black, 30%);
// Apps
@cp_app-bg: @cryptpad_color_grey_100;
@ -428,8 +428,8 @@
@cp_calendar-now-fg: @cryptpad_color_grey_200;
// Forms
@cp_form-bg1: @cryptpad_color_grey_200;
@cp_form-bg2: @cryptpad_color_grey_100;
@cp_form-bg1: @cryptpad_color_grey_50;
@cp_form-bg2: @cryptpad_color_grey_200;
@cp_form-border: @cryptpad_color_grey_200;
@cp_form-poll-color: @cryptpad_color_grey_800;
@cp_form-poll-no: fade(@cryptpad_color_light_red, 75%);

@ -141,8 +141,19 @@
width: 100% !important;
.cp-form-creator-settings {
display: flex;
justify-content: space-evenly;
justify-content: space-between;
flex-wrap: wrap;
div {
flex-basis: 33.333333%;
padding-right: 20px;
}
}
}
@media screen and (max-width: 600px) {
.cp-form-creator-settings {
div {
flex-basis: 50%;
}
}
}
}
@ -206,6 +217,19 @@
}
}
}
div.cp-form-creator-results {
.cp-form-block {
.cp-form-block-content {
overflow-x: auto;
}
}
.cp-form-creator-results-timeline {
margin-bottom: 20px;
table.cp-charts.column {
overflow-x: initial;
}
}
}
div.cp-form-creator-content, div.cp-form-creator-results {
max-width: 1000px;
min-width: 300px;
@ -331,6 +355,10 @@
color: @cryptpad_color_link;
}
}
.alert-danger {
font-size: 1rem;
padding: 10px;
}
}
.cp-form-anon-answer {
text-align: center;
@ -344,6 +372,10 @@
margin-left: 10px;
}
}
.cp-form-anon-answer-registered {
font-style: italic;
margin-left: 10px;
}
}
}
@ -371,6 +403,7 @@
.cp-form-block {
background: @cp_form-bg1;
padding: 10px;
box-shadow: 0px 0px 15px @cp_shadow-color;
&:not(:last-child) {
margin-bottom: 20px;
}
@ -434,7 +467,6 @@
}
}
.cp-form-block-content {
overflow-x: auto;
p {
a {
color: @cryptpad_color_link;
@ -600,6 +632,16 @@
align-items: center;
justify-content: center;
flex: 1;
flex-flow: column;
.cp-form-submit-actions {
button:not(:last-child) {
margin-right: 10px;
}
}
.cp-form-view-logo {
margin-top: 100px;
padding-bottom: 20px;
}
}
div.cp-form-creator-results {
display: flex;
@ -620,7 +662,6 @@
.cp-form-creator-results-controls {
margin-bottom: 20px;
margin-top: 20px;
//background: @cp_form-bg1;
//padding: 10px;
button {
@ -683,20 +724,28 @@
}
.cp-form-results-type-radio-data {
display: table-row;
border: 1px solid @cp_form-border;
border: 1px solid transparent;
& > span {
.cp-form-results-cell();
&.cp-value {
max-width: 200px;
min-width: 200px;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}
&.cp-bar-container {
width: 99%;
padding: 0px;
position: relative;
background: transparent;
border-left-width: 15px;
border-right-width: 15px;
.cp-bar {
position: absolute;
background: @cryptpad_color_brand;
height: 100%;
background: fade(@cryptpad_text_col, 50%);
height: 50%;
top: 25%;
}
}
}
@ -729,7 +778,7 @@
margin-top: -10px;
margin-right: -10px;
i { margin-right: 5px; }
background: fade(@cryptpad_text_col, 15%);
background: fade(@cryptpad_text_col, 10%);
}
}

@ -157,7 +157,7 @@ define([
h('span', Messages.form_textType),
typeSelect[0]
]);
typeSelect.onChange.reg(evOnSave.fire());
typeSelect.onChange.reg(evOnSave.fire);
}
setCursorGetter(function () {
@ -1020,7 +1020,7 @@ define([
var itemScale = (itemCount / max);
rows.push(h('div.cp-form-results-type-radio-data', [
h('span.cp-value', value),
h('span.cp-value', {'title': value}, value),
h('span.cp-count', itemCount),
showBar? barGraphic(itemScale): undefined,
]));
@ -2175,10 +2175,18 @@ define([
}
};
var addResultsButton = function (framework, content) {
var $res = $(h('button.cp-toolbar-appmenu.cp-toolbar-form-button', [
var getAnswersLength = function (answers) {
return Object.keys(answers || {}).filter(function (key) {
return key && key.slice(0,1) !== "_";
}).length;
};
Messages.form_results = "Responses ({0})"; // XXX update key
var addResultsButton = function (framework, content, answers) {
var $container = $('.cp-forms-results-participant');
var l = getAnswersLength(answers);
var $res = $(h('button.btn.btn-default.cp-toolbar-form-button', [
h('i.fa.fa-bar-chart'),
h('span.cp-button-name', Messages.form_results)
h('span.cp-button-name', Messages._getKey('form_results', [l])),
]));
$res.click(function () {
$res.attr('disabled', 'disabled');
@ -2190,30 +2198,49 @@ define([
$('body').addClass('cp-app-form-results');
renderResults(content, answers);
$res.remove();
var $editor = $(h('button.cp-toolbar-appmenu', [
var $editor = $(h('button.btn.btn-default', [
h('i.fa.fa-pencil'),
h('span.cp-button-name', APP.isEditor ? Messages.form_editor : Messages.form_form)
h('span.cp-button-name', Messages.form_editor)
]));
$editor.click(function () {
$('body').removeClass('cp-app-form-results');
$editor.remove();
addResultsButton(framework, content);
sframeChan.query("Q_FORM_FETCH_ANSWERS", content.answers, function (err, obj) {
var answers = obj && obj.results;
addResultsButton(framework, content, answers);
});
});
framework._.toolbar.$bottomL.append($editor);
$container.prepend($editor);
});
});
framework._.toolbar.$bottomL.append($res);
$container.prepend($res);
};
var getLogo = function () {
var logo = h('div.cp-form-view-logo', [
h('img', {
src:'/customize/CryptPad_logo_grey.svg?'+ApiConfig.requireConf.urlArgs,
alt:'CryptPad_logo'
}),
h('span', 'CryptPad')
]);
$(logo).click(function () {
APP.framework._.sfCommon.gotoURL('/');
});
return logo;
};
Messages.form_alreadyAnswered = "You've responded to this form on {0}"; // XXX
Messages.form_editAnswer = "Edit my responses"; // XXX
Messages.form_viewAnswer = "View my responses"; // XXX
var showAnsweredPage = function (framework, content, answers) {
if (APP.submitPage) { return; }
APP.submitPage = true;
var $formContainer = $('div.cp-form-creator-content').hide();
var $container = $('div.cp-form-creator-answered').empty().css('display', '');
var viewOnly = content.answers.cantEdit;
var viewOnly = content.answers.cantEdit || APP.isClosed;
var action = h('button.btn.btn-primary', [
viewOnly ? h('i.fa.fa-bar-chart') : h('i.fa.fa-pencil'),
h('span', viewOnly ? Messages.form_viewAnswer : Messages.form_editAnswer)
@ -2238,9 +2265,18 @@ define([
// If responses are public, show button to view them
var responses;
if (content.answers.privateKey) {
responses = h('button.btn.btn-default', Messages.form_results);
var l = getAnswersLength(answers);
responses = h('button.btn.btn-default', [
h('i.fa.fa-bar-chart'),
h('span.cp-button-name', Messages._getKey('form_results', [l]))
]);
var sframeChan = framework._.sfCommon.getSframeChannel();
sframeChan.query("Q_FORM_FETCH_ANSWERS", content.answers, function (err, obj) {
var answers = obj && obj.results;
var l = getAnswersLength(answers);
$(responses).find('.cp-button-name').text(Messages._getKey('form_results', [l]));
});
$(responses).click(function () {
var sframeChan = framework._.sfCommon.getSframeChannel();
sframeChan.query("Q_FORM_FETCH_ANSWERS", content.answers, function (err, obj) {
var answers = obj && obj.results;
if (answers) { APP.answers = answers; }
@ -2265,11 +2301,12 @@ define([
var title = framework._.title.title || framework._.title.defaultTitle;
$container.append(h('div.cp-form-submit-success', [
h('h3.cp-form-view-title', title),
description,
h('div.alert.alert-info', Messages._getKey('form_alreadyAnswered', [
new Date(APP.lastAnswerTime).toLocaleString()])),
description,
actions
]));
$container.append(getLogo());
};
var getFormResults = function () {
@ -2309,6 +2346,7 @@ define([
} else if (content.answers.anonymous) {
// Answers aren't anonymous and guests are allowed
// Guests can set a username and logged in users can answer anonymously
var $anon;
if (!loggedIn) {
anonName = h('div.cp-form-anon-answer-input', [
Messages.form_answerAs,
@ -2318,15 +2356,24 @@ define([
})
]);
$anonName = $(anonName).hide();
$anonBox.on('change', function () {
if (Util.isChecked($anonBox)) { $anonName.hide(); }
else { $anonName.show(); }
});
} else if (APP.cantAnon) {
// You've already answered with your credentials
$cbox.hide();
$anonBox.attr('disabled', 'disabled').prop('checked', false);
}
if (!anonName) {
anonName = h('div.cp-form-anon-answer-input', [
Messages.form_answerAs,
h('span.cp-form-anon-answer-registered', user.name || Messages.anonymous)
]);
}
if (!APP.cantAnon) {
var $anon = $(anonName).hide();
$anonBox.on('change', function () {
if (Util.isChecked($anonBox)) { $anon.hide(); }
else { $anon.show(); }
});
}
} else {
// Answers don't have to be anonymous and only logged in users can answer
// ==> they have to answer with their keys so we know their name too
@ -2337,6 +2384,10 @@ define([
$cbox.after(h('div.alert.alert-info', Messages.form_authAnswer));
});
}
if (update && content.answers.cantEdit || APP.isClosed) {
$cbox.hide();
anonName = undefined;
}
var send = h('button.cp-open.btn.btn-primary', update ? Messages.form_update : Messages.form_submit);
var reset = h('button.cp-open.cp-reset-button.btn.btn-danger-alt', Messages.form_reset);
@ -2383,15 +2434,16 @@ define([
}
evOnChange.fire(false, true);
window.onbeforeunload = undefined;
if (!update && content.answers.privateKey) {
// Add results button
addResultsButton(framework, content);
}
$send.removeAttr('disabled');
//UI.alert(Messages.form_sent); // XXX not needed anymore?
$send.text(Messages.form_update);
APP.hasAnswered = true;
showAnsweredPage(framework, content, { '_time': +new Date() });
if (content.answers.cantEdit) {
$cbox.hide();
if ($anonName) { $anonName.hide(); }
}
});
});
@ -2475,8 +2527,10 @@ define([
});
var list = h('ul', lis);
var divContent = [
h('span', Messages.form_requiredWarning),
list
h('div.alert.alert-danger', [
Messages.form_requiredWarning,
list
])
];
$errors.empty().append(divContent);
});
@ -2505,7 +2559,7 @@ define([
var color = content.answers.color || 'nocolor';
$container.addClass('cp-form-palette-'+color);
if (APP.isClosed && content.answers.privateKey && !APP.isEditor) {
if (APP.isClosed && content.answers.privateKey && !APP.isEditor && !APP.hasAnswered) {
var sframeChan = framework._.sfCommon.getSframeChannel();
sframeChan.query("Q_FORM_FETCH_ANSWERS", content.answers, function (err, obj) {
var answers = obj && obj.results;
@ -2967,6 +3021,7 @@ define([
updateAddInline();
if (editable) {
if (APP.mainSortable) { APP.mainSortable.destroy(); }
APP.mainSortable = Sortable.create($container[0], {
direction: "vertical",
filter: "input, button, .CodeMirror, .cp-form-type-sort, .cp-form-block-type.editable",
@ -2996,6 +3051,13 @@ define([
new Date(answers._time || APP.lastAnswerTime).toLocaleString()])));
}
if (APP.isClosed) {
APP.formBlocks.forEach(function (b) {
if (!b.setEditable) { return; }
b.setEditable(false);
});
}
// In view mode, add "Submit" and "reset" buttons
$container.append(makeFormControls(framework, content, Boolean(answers), evOnChange));
@ -3024,17 +3086,7 @@ define([
// at the bottom
var title = framework._.title.title || framework._.title.defaultTitle;
$container.prepend(h('h1.cp-form-view-title', title));
var logo = h('div.cp-form-view-logo', [
h('img', {
src:'/customize/CryptPad_logo_grey.svg?'+ApiConfig.requireConf.urlArgs,
alt:'CryptPad_logo'
}),
h('span', 'CryptPad')
]);
$(logo).click(function () {
framework._.sfCommon.gotoURL('/drive/');
});
$container.append(logo);
$container.append(getLogo());
if (!answers) {
$container.find('.cp-reset-button').attr('disabled', 'disabled');
@ -3070,10 +3122,11 @@ define([
var $toolbarContainer = $('#cp-toolbar');
if (APP.isEditor || priv.form_auditorKey) {
var helpMenu = framework._.sfCommon.createHelpMenu(['text', 'pad']);
$toolbarContainer.after(helpMenu.menu);
framework._.toolbar.$drawer.append(helpMenu.button);
var helpMenu = framework._.sfCommon.createHelpMenu(['text', 'pad']);
$toolbarContainer.after(helpMenu.menu);
framework._.toolbar.$drawer.append(helpMenu.button);
if (!APP.isEditor && !priv.form_auditorKey) {
$(helpMenu.menu).hide();
}
var offlineEl = h('div.alert.alert-danger.cp-burn-after-reading', Messages.disconnected);
@ -3123,7 +3176,7 @@ define([
});
});
Messages.form_makePublicWarning = "Are you sure you want to make responses to this form public? Past and future responses will be visible by participants. This cannot be undone." // XXX existing key
Messages.form_makePublicWarning = "Are you sure you want to make responses to this form public? Past and future responses will be visible by participants. This cannot be undone."; // XXX existing key
// Private / public status
var resultsType = h('div.cp-form-results-type-container');
var $results = $(resultsType);
@ -3351,6 +3404,9 @@ define([
});
var save = h('button.btn.btn-primary', Messages.settings_save);
$(save).click(function () {
if (dataPicker.value === '') {
return void refreshEndDate();
}
var d = picker.parseDate(datePicker.value);
content.answers.endDate = +d;
framework.localChange();
@ -3358,9 +3414,13 @@ define([
refreshEndDate();
});
});
var cancel = h('button.btn.btn-danger', h('i.fa.fa-times'));
$(cancel).click(function () {
refreshEndDate();
});
var confirmContent = h('div', [
h('div', Messages.form_setEnd),
h('div.cp-form-input-block', [datePicker, save]),
h('div.cp-form-input-block', [datePicker, save, cancel]),
]);
$button.after(confirmContent);
$button.remove();
@ -3593,7 +3653,6 @@ define([
}
if (APP.isEditor) {
addResultsButton(framework, content);
sframeChan.query("Q_FORM_FETCH_ANSWERS", {
channel: content.answers.channel,
validateKey: content.answers.validateKey,
@ -3601,6 +3660,7 @@ define([
cantEdit: content.answers.cantEdit
}, function (err, obj) {
var answers = obj && obj.results;
addResultsButton(framework, content, answers);
if (answers) { APP.answers = answers; }
checkIntegrity(false);
updateForm(framework, content, true);
@ -3654,9 +3714,6 @@ define([
// If we have a non-anon answer, we can't answer anonymously later
if (answers[curve1]) { APP.cantAnon = true; }
// Add results button
if (myAnswers) { addResultsButton(framework, content); }
updateForm(framework, content, false, myAnswers);
});
return;
@ -3684,9 +3741,6 @@ define([
APP.hasAnswered = true;
// If we have a non-anon answer, we can't answer anonymously later
if (!obj._isAnon) { APP.cantAnon = true; }
// Add results button
if (content.answers.privateKey) { addResultsButton(framework, content); }
}
checkIntegrity(false);
updateForm(framework, content, false, answers);

@ -221,8 +221,7 @@ define([
delete results[parsed._proof.key];
}
}
// XXX If "allow edition" is disabled, don't override here?
// if (data.cantEdit && results[senderCurve]) { return; }
if (data.cantEdit && results[senderCurve]) { return; }
results[senderCurve] = {
msg: parsed,
hash: hash,

Loading…
Cancel
Save