From df2bad9b8f5cca1ffa941a775805439a5dab43ca Mon Sep 17 00:00:00 2001 From: Ahmed Ejaz Date: Mon, 17 Jun 2024 21:59:07 +0500 Subject: [PATCH] 11987: add product_variant_row partial --- .../_product_variant_row.html.haml | 24 ++++++++++++++++++ app/views/admin/products_v3/_table.html.haml | 25 +------------------ 2 files changed, 25 insertions(+), 24 deletions(-) create mode 100644 app/views/admin/products_v3/_product_variant_row.html.haml diff --git a/app/views/admin/products_v3/_product_variant_row.html.haml b/app/views/admin/products_v3/_product_variant_row.html.haml new file mode 100644 index 0000000000..298bca3d71 --- /dev/null +++ b/app/views/admin/products_v3/_product_variant_row.html.haml @@ -0,0 +1,24 @@ += form.fields_for("products", product, index: product_index) do |product_form| + %tbody.relaxed{ id: dom_id(product), data: { 'record-id': product_form.object.id, + controller: "nested-form product", + action: 'rails-nested-form:add->bulk-form#registerElements rails-nested-form:remove->bulk-form#toggleFormChanged' } } + %tr + = render partial: 'product_row', locals: { f: product_form, product:, producer_options:, product_index: } + + - product.variants.each_with_index do |variant, variant_index| + = form.fields_for("products][#{product_index}][variants_attributes][", variant, index: variant_index) do |variant_form| + %tr.condensed{ id: dom_id(variant), 'data-controller': "variant", 'class': "nested-form-wrapper", 'data-new-record': variant.new_record? ? "true" : false } + = render partial: 'variant_row', locals: { variant:, f: variant_form, category_options:, tax_category_options: } + + = form.fields_for("products][#{product_index}][variants_attributes][NEW_RECORD", product.variants.build) do |new_variant_form| + %template{ 'data-nested-form-target': "template" } + %tr.condensed{ 'data-controller': "variant", 'class': "nested-form-wrapper", 'data-new-record': "true" } + = render partial: 'variant_row', locals: { variant: new_variant_form.object, f: new_variant_form, category_options:, tax_category_options: } + + %tr{ 'data-nested-form-target': "target" } + %tr.condensed + %td + %td{ colspan: 11 } + %button.secondary.condensed.naked.icon-plus{ 'data-action': "nested-form#add", + 'aria-label': t('.new_variant') } + =t('.new_variant') diff --git a/app/views/admin/products_v3/_table.html.haml b/app/views/admin/products_v3/_table.html.haml index 464130d181..ba0a3c9f35 100644 --- a/app/views/admin/products_v3/_table.html.haml +++ b/app/views/admin/products_v3/_table.html.haml @@ -62,27 +62,4 @@ %th.align-left= t('admin.products_page.columns.inherits_properties') %th.align-right= t('admin.products_page.columns.actions') - products.each_with_index do |product, product_index| - = form.fields_for("products", product, index: product_index) do |product_form| - %tbody.relaxed{ id: dom_id(product), data: { 'record-id': product_form.object.id, - controller: "nested-form product", - action: 'rails-nested-form:add->bulk-form#registerElements rails-nested-form:remove->bulk-form#toggleFormChanged' } } - %tr - = render partial: 'product_row', locals: { f: product_form, product:, producer_options: } - - - product.variants.each_with_index do |variant, variant_index| - = form.fields_for("products][#{product_index}][variants_attributes][", variant, index: variant_index) do |variant_form| - %tr.condensed{ id: dom_id(variant), 'data-controller': "variant", 'class': "nested-form-wrapper", 'data-new-record': variant.new_record? ? "true" : false } - = render partial: 'variant_row', locals: { variant:, f: variant_form, category_options:, tax_category_options: } - - = form.fields_for("products][#{product_index}][variants_attributes][NEW_RECORD", product.variants.build) do |new_variant_form| - %template{ 'data-nested-form-target': "template" } - %tr.condensed{ 'data-controller': "variant", 'class': "nested-form-wrapper", 'data-new-record': "true" } - = render partial: 'variant_row', locals: { variant: new_variant_form.object, f: new_variant_form, category_options:, tax_category_options: } - - %tr{ 'data-nested-form-target': "target" } - %tr.condensed - %td - %td{ colspan: 11 } - %button.secondary.condensed.naked.icon-plus{ 'data-action': "nested-form#add", - 'aria-label': t('.new_variant') } - =t('.new_variant') + = render partial: 'product_variant_row', locals: { form:, product:, product_index:, producer_options:, category_options:, tax_category_options: }