Skip to content
Snippets Groups Projects
Commit 484af6d1 authored by Hangzhi Yu's avatar Hangzhi Yu
Browse files

Views: add property has_children to AJAX request

rebus.html template: merge the ability to show/hide the next select field into setNextProperties function, automatically does not display next field if there are no children present
parent abfa9b49
No related branches found
No related tags found
1 merge request!8Resolve "Rewrite REBUS with django-select2"
......@@ -82,7 +82,7 @@
}
});
$.fn.setNextProperties = function (field_id, icon_id, next_field_name) {
$.fn.setNextProperties = function (field_id, next_field_id, icon_id, next_field_name) {
var category = $('#' + field_id).find(':selected').text();
$.ajax({
url: '{% url "rebus-get-next-properties" %}',
......@@ -94,22 +94,22 @@
$(icon_id).html("<i class=\"material-icons prefix small\">" + data.icon + "</i>");
$("[name=" + next_field_name + "]").djangoSelect2({tags: data.tagging});
$("[name=" + next_field_name + "]").next("span.select2:first").find("span.select2-selection__placeholder").html(data.placeholder);
if (($(next_field_id).is(':hidden')) && ((data.tagging == true) || ( data.has_children))) {
$(next_field_id).show();
} else if (!data.has_children) {
$(next_field_id).hide();
}
}
});
}
$("#{{ form.bug_category_1.auto_id }}").on('input', function() {
$.fn.setNextProperties(this.id, "#bug_category_2_icon", "bug_category_2")
if ($("#{{ form.bug_category_2.auto_id }}").is(':hidden')) {
$("#{{ form.bug_category_2.auto_id }}").show();
} else if ($("#{{ form.bug_category_3.auto_id }}").is(':visible')) {
$.fn.setNextProperties(this.id, "#{{ form.bug_category_2.auto_id }}", "#bug_category_2_icon", "bug_category_2")
if ($("#{{ form.bug_category_3.auto_id }}").is(':visible')) {
$("#{{ form.bug_category_3.auto_id }}").hide();
}
});
$("#{{ form.bug_category_2.auto_id }}").on('input', function() {
$.fn.setNextProperties(this.id, "#bug_category_3_icon", "bug_category_3")
if ($("#{{ form.bug_category_3.auto_id }}").is(':hidden')) {
$("#{{ form.bug_category_3.auto_id }}").show();
}
$.fn.setNextProperties(this.id, "#{{ form.bug_category_3.auto_id }}", "#bug_category_3_icon", "bug_category_3")
});
</script>
......
......@@ -71,7 +71,7 @@ def add_arrows(array: list):
def rebus_get_next_properties(request):
category = request.GET.get("category", None)
next_properties = {"icon": REBUSCategory.objects.get(name=category).icon, "tagging": REBUSCategory.objects.get(name=category).tagging, "placeholder": REBUSCategory.objects.get(name=category).placeholder}
next_properties = {"icon": REBUSCategory.objects.get(name=category).icon, "tagging": REBUSCategory.objects.get(name=category).tagging, "placeholder": REBUSCategory.objects.get(name=category).placeholder, "has_children": REBUSCategory.objects.get(name=category).children.exists()}
return JsonResponse(next_properties)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment