diff --git a/src/pretix/static/pretixpresale/js/widget/widget.js b/src/pretix/static/pretixpresale/js/widget/widget.js index b7667f3ab1..b7ca374813 100644 --- a/src/pretix/static/pretixpresale/js/widget/widget.js +++ b/src/pretix/static/pretixpresale/js/widget/widget.js @@ -203,10 +203,10 @@ Vue.component('availbox', { + '' + '
' + '' + '' + '
' + ''), @@ -214,7 +214,32 @@ Vue.component('availbox', { item: Object, variation: Object }, + mounted: function() { + if (this.item.has_variations) { + this.$set(this.variation, 'amount_selected', 0); + } else { + // Automatically set the only available item to be selected. + this.$set(this.item, 'amount_selected', this.$root.itemnum === 1 ? 1 : 0); + } + this.$root.$emit('amounts_changed') + }, computed: { + amount_selected: { + get() { + return this.item.has_variations ? this.variation.amount_selected : this.item.amount_selected + }, + set(value) { + // Unary operator to force boolean to integer conversion, as the HTML form submission + // needs the value to be integer for all products. + value = (+value); + if (this.item.has_variations) { + this.variation.amount_selected = value; + } else { + this.item.amount_selected = value; + } + this.$root.$emit("amounts_changed") + } + }, input_name: function () { if (this.item.has_variations) { return 'variation_' + this.item.id + '_' + this.variation.id; @@ -222,7 +247,7 @@ Vue.component('availbox', { return 'item_' + this.item.id; } }, - order_max: function () { + order_max: function () { return this.item.has_variations ? this.variation.order_max : this.item.order_max; }, avail: function () { @@ -726,7 +751,7 @@ Vue.component('pretix-widget-event-form', { + '' + '' + '
' - + '' + + '' + '
' + '' + '
' + '' ), + data: function () { + return { + buy_disabled: true + } + }, + mounted: function() { + this.$root.$on('amounts_changed', this.calculate_buy_disabled) + this.calculate_buy_disabled() + }, + beforeDestroy: function() { + this.$root.$off('amounts_changed', this.calculate_buy_disabled) + }, computed: { buy_label: function () { var i, j, k, all_free = true; @@ -790,6 +827,28 @@ Vue.component('pretix-widget-event-form', { } else { this.$root.view = "weeks"; } + }, + calculate_buy_disabled: function() { + var i, j, k; + for (i = 0; i < this.$root.categories.length; i++) { + var cat = this.$root.categories[i]; + for (j = 0; j < cat.items.length; j++) { + var item = cat.items[j]; + if (item.has_variations) { + for (k = 0; k < item.variations.length; k++) { + var v = item.variations[k]; + if (v.amount_selected) { + this.buy_disabled = false; + return; + } + } + } else if (item.amount_selected) { + this.buy_disabled = false; + return; + } + } + } + this.buy_disabled = true; } } }); diff --git a/src/pretix/static/pretixpresale/scss/widget.scss b/src/pretix/static/pretixpresale/scss/widget.scss index 7bf581c5c5..6436bcd367 100644 --- a/src/pretix/static/pretixpresale/scss/widget.scss +++ b/src/pretix/static/pretixpresale/scss/widget.scss @@ -56,6 +56,13 @@ @include tab-focus; } } + &.disabled, + &[disabled], + fieldset[disabled] & { + cursor: $cursor-disabled; + @include opacity(.65); + @include box-shadow(none); + } } input[type="text"], input[type="number"] { line-height: normal;