mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-13 13:54:23 +00:00
improve layout of export
The filters and aggregators form are now displayed only if the form is checked.
This commit is contained in:
parent
d33500f764
commit
34c0ff3ba1
@ -355,6 +355,60 @@ var chill = function() {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function _displayHideTargetWithCheckbox(checkbox) {
|
||||||
|
var target = checkbox.dataset.displayTarget,
|
||||||
|
hideableElements;
|
||||||
|
|
||||||
|
hideableElements = document.querySelectorAll('[data-display-show-hide="' + target + '"]');
|
||||||
|
|
||||||
|
if (checkbox.checked) {
|
||||||
|
for (let i=0; i < hideableElements.length; i = i+1) {
|
||||||
|
hideableElements[i].style.display = "unset";
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
for (let i=0; i < hideableElements.length; i = i+1) {
|
||||||
|
hideableElements[i].style.display = "none";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* create an interaction between a checkbox and element to show if the
|
||||||
|
* checkbox is checked, or hide if the checkbox is not checked.
|
||||||
|
*
|
||||||
|
* The checkbox must have the data `data-display-target` with an id,
|
||||||
|
* and the parts to show/hide must have the data `data-display-show-hide`
|
||||||
|
* with the same value.
|
||||||
|
*
|
||||||
|
* Example :
|
||||||
|
*
|
||||||
|
* ```
|
||||||
|
* <input data-display-target="export_abc" value="1" type="checkbox">
|
||||||
|
*
|
||||||
|
* <div data-display-show-hide="export_abc">
|
||||||
|
* <!-- your content here will be hidden / shown according to checked state -->
|
||||||
|
* </div>
|
||||||
|
* ```
|
||||||
|
*
|
||||||
|
* Hint: for forms in symfony, you could use the `id` of the form element,
|
||||||
|
* accessible through `{{ form.vars.id }}`. This id should be unique.
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* @returns {undefined}
|
||||||
|
*/
|
||||||
|
function listenerDisplayCheckbox() {
|
||||||
|
var elements = document.querySelectorAll("[data-display-target]");
|
||||||
|
|
||||||
|
for (let i=0; i < elements.length; i = i+1) {
|
||||||
|
elements[i].addEventListener("change", function(e) {
|
||||||
|
_displayHideTargetWithCheckbox(e.target);
|
||||||
|
});
|
||||||
|
// initial display-hide
|
||||||
|
_displayHideTargetWithCheckbox(elements[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
initPikaday: initPikaday,
|
initPikaday: initPikaday,
|
||||||
@ -364,5 +418,6 @@ var chill = function() {
|
|||||||
displayAlertWhenLeavingUnsubmittedForm: displayAlertWhenLeavingUnsubmittedForm,
|
displayAlertWhenLeavingUnsubmittedForm: displayAlertWhenLeavingUnsubmittedForm,
|
||||||
checkNullValuesInChoices: checkNullValuesInChoices,
|
checkNullValuesInChoices: checkNullValuesInChoices,
|
||||||
categoryLinkParentChildSelect: categoryLinkParentChildSelect,
|
categoryLinkParentChildSelect: categoryLinkParentChildSelect,
|
||||||
|
listenerDisplayCheckbox: listenerDisplayCheckbox,
|
||||||
};
|
};
|
||||||
} ();
|
} ();
|
||||||
|
@ -20,6 +20,12 @@
|
|||||||
|
|
||||||
{% block title %}{{ export.title|trans }}{% endblock %}
|
{% block title %}{{ export.title|trans }}{% endblock %}
|
||||||
|
|
||||||
|
{% block js %}
|
||||||
|
<script type="text/javascript">
|
||||||
|
window.addEventListener("DOMContentLoaded", chill.listenerDisplayCheckbox);
|
||||||
|
</script>
|
||||||
|
{% endblock js %}
|
||||||
|
|
||||||
{% block layout_wvm_content %}
|
{% block layout_wvm_content %}
|
||||||
|
|
||||||
<h1>{{ export.title|trans }}</h1>
|
<h1>{{ export.title|trans }}</h1>
|
||||||
@ -32,14 +38,16 @@
|
|||||||
<div style="clear:both; padding-top: 1.5em;">
|
<div style="clear:both; padding-top: 1.5em;">
|
||||||
<h2>{{ 'Filters'| trans }}</h2>
|
<h2>{{ 'Filters'| trans }}</h2>
|
||||||
{% for filter_form in form.children.export.children.filters %}
|
{% for filter_form in form.children.export.children.filters %}
|
||||||
|
<div>
|
||||||
<p>
|
<p>
|
||||||
{{ form_widget(filter_form.enabled, { 'attr' : { 'style' : 'vertical-align: middle;' } }) }}
|
{{ form_widget(filter_form.enabled, { 'attr' : { 'style' : 'vertical-align: middle;', 'data-display-target': filter_form.vars.id } }) }}
|
||||||
<span class="force-inline-label">{{ form_label(filter_form) }}</span>
|
<span class="force-inline-label">{{ form_label(filter_form) }}</span>
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
<div>
|
<div data-display-show-hide="{{ filter_form.vars.id }}">
|
||||||
{{ form_widget(filter_form.form) }}
|
{{ form_widget(filter_form.form) }}
|
||||||
</div>
|
</div>
|
||||||
|
</div>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</div>
|
</div>
|
||||||
{% else %}
|
{% else %}
|
||||||
@ -51,12 +59,16 @@
|
|||||||
<div style="clear:both; padding-top: 1.5em;">
|
<div style="clear:both; padding-top: 1.5em;">
|
||||||
<h2>{{ 'Aggregators'| trans }}</h2>
|
<h2>{{ 'Aggregators'| trans }}</h2>
|
||||||
{% for aggregator_form in form.children.export.children.aggregators %}
|
{% for aggregator_form in form.children.export.children.aggregators %}
|
||||||
|
<div>
|
||||||
<p>
|
<p>
|
||||||
{{ form_widget(aggregator_form.enabled, { 'attr' : { 'style' : 'vertical-align: middle;' } }) }}
|
{{ form_widget(aggregator_form.enabled, { 'attr' : { 'style' : 'vertical-align: middle;', 'data-display-target': aggregator_form.vars.id } }) }}
|
||||||
<span class="force-inline-label">{{ form_label(aggregator_form) }}</span>
|
<span class="force-inline-label">{{ form_label(aggregator_form) }}</span>
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
|
<div data-display-show-hide="{{ aggregator_form.vars.id }}">
|
||||||
{{ form_widget(aggregator_form.form) }}
|
{{ form_widget(aggregator_form.form) }}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</div>
|
</div>
|
||||||
{% else %}
|
{% else %}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user