mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-10 23:07:47 +00:00
Making turbo stream work with link_to helpers
This commit is contained in:
@@ -36,6 +36,8 @@ module Admin
|
||||
def clone
|
||||
@product = Spree::Product.find(params[:id])
|
||||
@cloned_product = @product.duplicate
|
||||
@product_index = params[:product_index]
|
||||
|
||||
raise "Clone failed" unless @cloned_product.save
|
||||
|
||||
respond_to(&:turbo_stream)
|
||||
|
||||
24
app/views/admin/products_v3/_product_form.html.haml
Normal file
24
app/views/admin/products_v3/_product_form.html.haml
Normal file
@@ -0,0 +1,24 @@
|
||||
= form.fields_for("products", product, index: product_index) do |product_form|
|
||||
%tbody.relaxed{ data: { 'record-id': product_form.object.id,
|
||||
controller: "nested-form product",
|
||||
action: 'rails-nested-form:add->bulk-form#registerElements' }, id: "product_#{product.id}" }
|
||||
%tr
|
||||
= render partial: 'product_row', locals: { product:, product_index:, f: product_form }
|
||||
|
||||
- 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{ 'data-controller': "variant" }
|
||||
= render partial: 'variant_row', locals: { variant:, f: variant_form }
|
||||
|
||||
= 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" }
|
||||
= render partial: 'variant_row', locals: { variant: new_variant_form.object, f: new_variant_form }
|
||||
|
||||
%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')
|
||||
@@ -42,7 +42,7 @@
|
||||
%td.align-right
|
||||
= render(VerticalEllipsisMenu::Component.new) do
|
||||
= link_to t('admin.products_page.actions.edit'), edit_admin_product_path(product), 'data-turbo': false
|
||||
= link_to t('admin.products_page.actions.clone'), admin_clone_product_path(product), method: :post, 'data-turbo-stream': true
|
||||
= link_to t('admin.products_page.actions.clone'), admin_clone_product_path(product, product_index:), 'data-turbo-method': 'post'
|
||||
%a{ "data-controller": "modal-link", "data-action": "click->modal-link#setModalDataSetOnConfirm click->modal-link#open",
|
||||
"data-modal-link-target-value": "product-delete-modal", "class": "delete",
|
||||
"data-modal-link-modal-dataset-value": {'data-current-id': product.id}.to_json }
|
||||
|
||||
@@ -62,6 +62,7 @@
|
||||
%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|
|
||||
<<<<<<< HEAD
|
||||
= form.fields_for("products", product, index: product_index) do |product_form|
|
||||
%tbody.relaxed{ data: { 'record-id': product_form.object.id,
|
||||
controller: "nested-form product",
|
||||
@@ -86,3 +87,6 @@
|
||||
%button.secondary.condensed.naked.icon-plus{ 'data-action': "nested-form#add",
|
||||
'aria-label': t('.new_variant') }
|
||||
=t('.new_variant')
|
||||
=======
|
||||
= render partial: 'product_form', locals: { product:, product_index:, form: }
|
||||
>>>>>>> 520db0ebf3 (Making turbo stream work with link_to helpers)
|
||||
|
||||
@@ -1,2 +1,2 @@
|
||||
= turbo_stream.replace "products-content" do
|
||||
%h1= "This is a test."
|
||||
= turbo_stream.before "product_#{@product.id}" do
|
||||
%p= "This is a test."
|
||||
Reference in New Issue
Block a user