Show edit form for new images

This commit is contained in:
David Cook
2024-05-22 16:54:41 +10:00
parent 3fcc9ac1fa
commit 536b5608ab
4 changed files with 22 additions and 5 deletions

View File

@@ -2,6 +2,8 @@
module Admin
class ProductsV3Controller < Spree::Admin::BaseController
helper ProductsHelper
before_action :init_filters_params
before_action :init_pagination_params

View File

@@ -17,7 +17,10 @@ module Spree
def new
@url_filters = ::ProductFilters.new.extract(request.query_parameters)
render layout: !request.xhr?
respond_with do |format|
format.turbo_stream { render :edit }
format.all { render layout: !request.xhr? }
end
end
def edit

View File

@@ -0,0 +1,13 @@
# frozen_string_literal: true
module Admin
module ProductsHelper
def product_image_form_path(product)
if product.image.present?
edit_admin_product_image_path(product.id, product.image.id)
else
new_admin_product_image_path(product.id)
end
end
end
end

View File

@@ -1,8 +1,7 @@
%td.with-image{ id: "image-#{product.id}" }
- if product.image.present? # todo: handle blank img
%a.image-field{ href: edit_admin_product_image_path(product.id, product.image.id), 'data-turbo-stream': true }
= image_tag product.image&.url(:mini) || Spree::Image.default_image_url(:mini), width: 40, height: 40
.button.secondary.mini= t('admin.products_page.image.edit')
%a.image-field{ href: product_image_form_path(product), 'data-turbo-stream': true }
= image_tag product.image&.url(:mini) || Spree::Image.default_image_url(:mini), width: 40, height: 40
.button.secondary.mini= t('admin.products_page.image.edit')
%td.field.align-left.header.naked_inputs
= f.hidden_field :id
= f.text_field :name, 'aria-label': t('admin.products_page.columns.name')