Allow to restrict availability of variations by date, sales channel, and voucher (#2202)

This commit is contained in:
Raphael Michel
2021-09-15 12:04:17 +02:00
committed by GitHub
parent 4789d82c4e
commit 17adde99fa
20 changed files with 583 additions and 52 deletions

View File

@@ -0,0 +1,58 @@
/*global $, Morris, gettext*/
$(function () {
// Question view
if (!$("#item_variations").length) {
return;
}
function update_variation_summary($el) {
var var_name = $el.find("input[name*=-value_]").filter(function () {return !!this.value}).first().val();
var price = $el.find("input[name*=-default_price]").val();
$el.find(".variation-name").text(var_name);
$el.find(".variation-price").text(price);
$el.find(".variation-timeframe").toggleClass("variation-icon-hidden", !(
!!$el.find("input[name$=-available_from_0]").val() ||
!!$el.find("input[name$=-available_until_0]").val()
));
$el.find(".variation-name").toggleClass("variation-disabled", !(
!!$el.find("input[name$=-active]").prop("checked")
));
$el.find(".variation-voucher").toggleClass("variation-icon-hidden", !(
!!$el.find("input[name$=-hide_without_voucher]").prop("checked")
));
$el.find(".variation-membership").toggleClass("variation-icon-hidden", !(
!!$el.find("input[name$=-require_membership]").prop("checked")
));
$el.find(".variation-warning").toggleClass("hidden", !(
$el.find(".alert-warning").length
));
$el.find(".variation-error").toggleClass("hidden", !(
$el.find(".alert-danger, .has-error").length
));
$el.find("input[name$=-sales_channels]").each(function () {
$el.find(".variation-channel-" + $(this).val()).toggleClass("variation-icon-hidden", !(
$(this).prop("checked") && $("input[name=sales_channels][value=" + $(this).val() + "]").prop("checked")
));
})
}
$("#item_variations [data-formset-form]").each(function () {
var $el = $(this);
update_variation_summary($el);
$(this).on("change dp.change", "input", function () {update_variation_summary($el)});
});
$("input[name=sales_channels]").on("change", function() {
$("#item_variations [data-formset-form]").each(function () {
update_variation_summary($(this));
});
});
$("#item_variations").on("formAdded", "details", function (event) {
console.log("added", event.target)
var $el = $(event.target);
update_variation_summary($el);
$(this).on("change dp.change", "input", function () {update_variation_summary($el)});
setup_collapsible_details($("#item_variations"));
});
});

View File

@@ -46,7 +46,7 @@ td > .form-group > .checkbox {
@include box-shadow(none);
}
div[data-formset-body], div[data-formset-form], div[data-nested-formset-form], div[data-nested-formset-body] {
div[data-formset-body], div[data-formset-form], div[data-nested-formset-form], div[data-nested-formset-body], details[data-formset-form] {
width: 100%;
}
@@ -813,3 +813,26 @@ table td > .checkbox input[type="checkbox"] {
font-weight: normal;
}
}
details {
summary .chevron::before {
content: $fa-var-caret-right;
}
&[open] .chevron::before {
content: $fa-var-caret-down;
}
}
#item_variations {
summary small {
display: inline-block;
margin-left: 2.1em;
}
.variation-icon-hidden {
opacity: 0;
pointer-events: none;
}
.variation-disabled {
text-decoration: line-through;
}
}