wcs: display card variable in the link form (#72624)
gitea-wip/combo/pipeline/pr-main This commit looks good Details

This commit is contained in:
Lauréline Guérin 2023-01-13 16:39:09 +01:00
parent e9a5e14196
commit f6cfaff63e
No known key found for this signature in database
GPG Key ID: 1FAB9B9B4F93D473
4 changed files with 33 additions and 0 deletions

View File

@ -23,6 +23,7 @@ from django.core.exceptions import ValidationError
from django.forms import formset_factory
from django.template import Template, TemplateSyntaxError
from django.template.loader import TemplateDoesNotExist, get_template
from django.utils.safestring import mark_safe
from django.utils.translation import gettext_lazy as _
from combo import utils
@ -196,6 +197,12 @@ class PageEditLinkedCardForm(forms.ModelForm):
card_models = get_wcs_options('/api/cards/@list')
self.fields['carddef_reference'].choices = [('', '-----')] + card_models
self.help_texts = {}
for card_model in card_models:
sub_slug = card_model[0].split(':')[1].replace('-', '_')
self.help_texts[card_model[0]] = mark_safe(
_('The card identifier will be available in the variable <code>%s_id</code>.') % sub_slug
)
if self.instance.sub_slug:
result = get_wcs_matching_card_model(self.instance.sub_slug)

View File

@ -456,6 +456,13 @@ $(function() {
$('#id_form-' + form_num + '-value').val('');
total_form.val(form_num + 1);
})
$(document).on('change', '#linked-card-form #id_carddef_reference', function () {
$('#linked-card-variable span').hide();
if ($(this).val()) {
$('#linked-card-variable span[data-key="' + $(this).val() + '"]').show();
}
});
});

View File

@ -0,0 +1,18 @@
{% extends "combo/page_add.html" %}
{% load i18n %}
{% block content %}
<form method="post" enctype="multipart/form-data" id="linked-card-form">
{% csrf_token %}
{{ form.as_p }}
<p id="linked-card-variable">
{% for k, v in form.help_texts.items %}
<span data-key="{{ k }}" {% if form.initial.carddef_reference != k %}style="display: none"{% endif %}>{{ v }}</span>
{% endfor %}
</p>
<div class="buttons">
<button class="submit-button">{% trans "Save" %}</button>
<a class="cancel" href="{% url 'combo-manager-page-view' pk=object.id %}">{% trans 'Cancel' %}</a>
</div>
</form>
{% endblock %}

View File

@ -343,6 +343,7 @@ page_edit_slug = PageEditSlugView.as_view()
class PageEditLinkedCardView(PageEditView):
form_class = PageEditLinkedCardForm
comment = _('changed linked card')
template_name = 'combo/page_linked_card.html'
page_edit_linked_card = PageEditLinkedCardView.as_view()