Make choice updating after dish change smoother

This commit is contained in:
Midgard 2020-03-04 22:35:55 +01:00
parent 54dc1f23bf
commit 0f9a816eea
Signed by: midgard
GPG key ID: 511C112F1331BBB4
2 changed files with 12 additions and 1 deletions

View file

@ -293,4 +293,8 @@ h1, h2, h3, h4, h5, h6{
#dish_choices {
margin: 0.5em 1em 1.5em;
transition: opacity 0.2s;
}
#dish_choices.loading {
opacity: 0.2;
}

View file

@ -207,10 +207,14 @@
{% if order.location %}
function updateChoices() {
$("#submit-reveals-options-msg").hide(0);
$dish_choices = $("#dish_choices");
$dish_choices.addClass("loading");
var dish_id = $("#dish_id").val();
var url = "{{ url_for('general_bp.location_dish', location_id=order.location.id, dish_id='DISHID') }}".replace("DISHID", encodeURI(dish_id));
$dish_choices = $("#dish_choices");
$dish_choices.find("select").attr("disabled", "disabled");
$.get(url)
.done(function(data) {
$dish_choices.html("");
@ -254,8 +258,11 @@
);
choiceSelect.select2({"sorter": sortArg});
}
$dish_choices.removeClass("loading");
}).fail(function() {
$("#dish_choices").html("Could not load choices");
$dish_choices.removeClass("loading");
$("#submit-reveals-options-msg").show(0);
});
}
$("#dish_id").on("change", updateChoices);