diff --git a/app/resources/views/ventas/reservations/modal/add.blade.php b/app/resources/views/ventas/reservations/modal/add.blade.php index 5e9f2fd..c95f2e4 100644 --- a/app/resources/views/ventas/reservations/modal/add.blade.php +++ b/app/resources/views/ventas/reservations/modal/add.blade.php @@ -238,6 +238,7 @@ } } class AddModalUnits { + parent = null ids = { buttons_holder: '', units: '' @@ -252,7 +253,8 @@ units: null, } - constructor() { + constructor(parent) { + this.parent = parent this.ids = { buttons_holder: 'add_unit_buttons', units: 'add_units' @@ -265,6 +267,9 @@ } this.setup() } + get promotions() { + return this.parent.data.promotions[this.parent.data.current_project] + } draw = { button: type => { return [ @@ -295,7 +300,24 @@ this.components.units.innerHTML = this.data.units.map(unit => { return this.draw.unit(unit) }).join('') - this.components.units.querySelectorAll('.dropdown').forEach(dropdown => { + this.components.units.querySelectorAll('.dropdown.add_units').forEach(dropdown => { + $(dropdown).dropdown({ + onChange: (value, text, $selectedItem) => { + const unitPromotions = this.promotions.filter(promotion => promotion.units.length > 0) + const promotions = unitPromotions.filter(promotion => promotion.units.filter(unit => unit.id === parseInt(value)).length > 0) + console.debug($selectedItem.parent().parent().parent().parent().find('.add_promotions_unit')) + $selectedItem.parent().parent().parent().parent().find('.add_promotions_unit') + .dropdown('change values', promotions.map(promotion => { + return { + value: promotion.id, + name: promotion.description, + text: promotion.description, + } + })) + } + }) + }) + this.components.units.querySelectorAll('.dropdown.add_promotions_unit').forEach(dropdown => { $(dropdown).dropdown() }) this.components.units.querySelectorAll('.remove_unit').forEach(button => { @@ -308,24 +330,26 @@ unit: unit => { let promotions = '' if (unit.type === 'departamento') { - promotions = [ - '
', - '', - '', - '
Promociones
', - '' - ].join('') + '
' + ].join('') + } } return [ '
', '
', ``, - `