Improve condition selector in forms

pull/1/head
yflory 4 years ago
parent ef0e1c8eaf
commit a6794c5cee

@ -112,9 +112,11 @@
border-radius: 0; border-radius: 0;
transition: none; transition: none;
.fa, .cptools { i, .fa, .cptools {
&:not(:last-child) {
margin-right: 5px; margin-right: 5px;
} }
}
.cptools { .cptools {
vertical-align: middle; vertical-align: middle;
} }

@ -2935,11 +2935,11 @@ define([
}; };
if (type === 'radio') { if (type === 'radio') {
obj.values = block.opts ? block.opts.values obj.values = block.opts ? block.opts.values
: TYPES.radio.defaultOpts.values : TYPES.radio.defaultOpts.values;
} }
if (type === 'checkbox') { if (type === 'checkbox') {
obj.values = block.opts ? block.opts.values obj.values = block.opts ? block.opts.values
: TYPES.checkbox.defaultOpts.values : TYPES.checkbox.defaultOpts.values;
} }
return obj; return obj;
}).filter(Boolean); }).filter(Boolean);
@ -2964,6 +2964,9 @@ define([
$container.append(btn); $container.append(btn);
}; };
getConditions = function ($container, isNew, rules, condition) { getConditions = function ($container, isNew, rules, condition) {
Messages.form_condition_q = "Choose a question"; // XXX
Messages.form_condition_v = "Choose a value"; // XXX
var content = h('div.cp-form-condition'); var content = h('div.cp-form-condition');
var $content = $(content); var $content = $(content);
var values = getConditionsValues(); var values = getConditionsValues();
@ -2979,7 +2982,7 @@ define([
}; };
}); });
var qConfig = { var qConfig = {
text: '', // Button initial text text: Messages.form_condition_q, // Button initial text
options: qOptions, // Entries displayed in the menu options: qOptions, // Entries displayed in the menu
isSelect: true, isSelect: true,
caretDown: true, caretDown: true,
@ -3017,7 +3020,16 @@ define([
iSelect.setValue(isOn ? 1 : 0); iSelect.setValue(isOn ? 1 : 0);
$(iSelect).hide(); $(iSelect).hide();
$content.append(qSelect).append(iSelect); var remove = h('button.btn.btn-danger-alt.cp-condition-remove', [
h('i.fa.fa-times')
]);
$(remove).on('click', function () {
$content.remove();
if ($container.is(':empty')) { $container.remove(); }
$addC.show();
});
$content.append(qSelect).append(iSelect).append(remove);
if ($container.find('button.cp-form-add-and').length) { if ($container.find('button.cp-form-add-and').length) {
$container.find('button.cp-form-add-and').before($content); $container.find('button.cp-form-add-and').before($content);
} else { } else {
@ -3060,7 +3072,7 @@ define([
}; };
}); });
var vConfig = { var vConfig = {
text: '', // Button initial text text: Messages.form_condition_v, // Button initial text
options: vOptions, // Entries displayed in the menu options: vOptions, // Entries displayed in the menu
//left: true, // Open to the left of the button //left: true, // Open to the left of the button
//container: $(type), //container: $(type),
@ -3070,11 +3082,7 @@ define([
}; };
var vSelect = UIElements.createDropdown(vConfig); var vSelect = UIElements.createDropdown(vConfig);
vSelect.addClass('cp-form-condition-values'); vSelect.addClass('cp-form-condition-values');
if ($content.find('.cp-condition-remove').length) { $content.append(vSelect).append(remove);
$content.find('.cp-condition-remove').before(vSelect);
} else {
$content.append(vSelect);
}
var onChange = function () { var onChange = function () {
var w = block.opts.when = block.opts.when || []; var w = block.opts.when = block.opts.when || [];
@ -3112,11 +3120,7 @@ define([
iSelect.onChange.reg(isChange); iSelect.onChange.reg(isChange);
vSelect.onChange.reg(function () { vSelect.onChange.reg(function () {
if (!$content.find('.cp-condition-remove').length) { $(remove).off('click').click(function () {
var remove = h('button.btn.btn-danger-alt.cp-condition-remove', [
h('i.fa.fa-times')
]);
$(remove).click(function () {
var w = block.opts.when = block.opts.when || []; var w = block.opts.when = block.opts.when || [];
var deleteRule = false; var deleteRule = false;
if (rules.length === 1) { if (rules.length === 1) {
@ -3136,7 +3140,6 @@ define([
$content.remove(); $content.remove();
}); });
}).appendTo($content); }).appendTo($content);
}
onChange(); onChange();
}); });

Loading…
Cancel
Save