parent
1287d9ee06
commit
c9275c5ea0
@ -159,12 +159,20 @@ class DynamicArrayWidgetTags(DynamicArrayWidget):
|
|||||||
class RecurrentImportForm(ModelForm):
|
class RecurrentImportForm(ModelForm):
|
||||||
required_css_class = 'required'
|
required_css_class = 'required'
|
||||||
|
|
||||||
|
defaultTags = MultipleChoiceField(
|
||||||
|
label=_("Tags"),
|
||||||
|
initial=None,
|
||||||
|
choices=[],
|
||||||
|
required=False
|
||||||
|
)
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
model = RecurrentImport
|
model = RecurrentImport
|
||||||
fields = "__all__"
|
fields = "__all__"
|
||||||
widgets = {
|
|
||||||
"defaultTags": DynamicArrayWidgetTags(),
|
def __init__(self, *args, **kwargs):
|
||||||
}
|
super().__init__(*args, **kwargs)
|
||||||
|
self.fields["defaultTags"].choices = Tag.get_tag_groups(all=True)
|
||||||
|
|
||||||
|
|
||||||
class CategorisationRuleImportForm(ModelForm):
|
class CategorisationRuleImportForm(ModelForm):
|
||||||
|
@ -6,6 +6,8 @@
|
|||||||
{% block configurer-bouton %}{% endblock %}
|
{% block configurer-bouton %}{% endblock %}
|
||||||
|
|
||||||
{% block entete_header %}
|
{% block entete_header %}
|
||||||
|
<script src="{% static 'choicejs/choices.min.js' %}"></script>
|
||||||
|
|
||||||
<script src="/static/admin/js/vendor/jquery/jquery.js"></script>
|
<script src="/static/admin/js/vendor/jquery/jquery.js"></script>
|
||||||
<script src="/static/admin/js/jquery.init.js"></script>
|
<script src="/static/admin/js/jquery.init.js"></script>
|
||||||
<link href="{% static 'css/django_better_admin_arrayfield.min.css' %}" type="text/css" media="all" rel="stylesheet">
|
<link href="{% static 'css/django_better_admin_arrayfield.min.css' %}" type="text/css" media="all" rel="stylesheet">
|
||||||
@ -26,4 +28,35 @@
|
|||||||
</form>
|
</form>
|
||||||
</article>
|
</article>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
show_firstgroup = {
|
||||||
|
choice(classes, choice) {
|
||||||
|
const i = Choices.defaults.templates.choice.call(this, classes, choice);
|
||||||
|
if (this.first_group !== null && choice.groupId == this.first_group)
|
||||||
|
i.classList.add("visible");
|
||||||
|
return i;
|
||||||
|
},
|
||||||
|
choiceGroup(classes, group) {
|
||||||
|
const g = Choices.defaults.templates.choiceGroup.call(this, classes, group);
|
||||||
|
if (this.first_group === undefined && group.value == "Suggestions")
|
||||||
|
this.first_group = group.id;
|
||||||
|
if (this.first_group !== null && group.id == this.first_group)
|
||||||
|
g.classList.add("visible");
|
||||||
|
return g;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const tags = document.querySelector('#id_defaultTags');
|
||||||
|
const choices_tags = new Choices(tags,
|
||||||
|
{
|
||||||
|
placeholderValue: 'Sélectionner les étiquettes par défaut',
|
||||||
|
allowHTML: true,
|
||||||
|
delimiter: ',',
|
||||||
|
removeItemButton: true,
|
||||||
|
shouldSort: false,
|
||||||
|
callbackOnCreateTemplates: () => (show_firstgroup)
|
||||||
|
}
|
||||||
|
);
|
||||||
|
</script>
|
||||||
|
|
||||||
{% endblock %}
|
{% endblock %}
|
Loading…
Reference in New Issue
Block a user