Sha256: 26826785fb22b699bb5ca46d7999616fac49a4bd54abe3ab8a37dc4612fe8914

Contents?: true

Size: 1.29 KB

Versions: 10

Compression:

Stored size: 1.29 KB

Contents

module Spree
  module Admin
    class ImagesController < ResourceController
      before_action :load_edit_data, except: :index
      before_action :load_index_data, only: :index

      create.before :set_viewable
      update.before :set_viewable

      private

      def location_after_destroy
        admin_product_images_url(@product)
      end

      def location_after_save
        admin_product_images_url(@product)
      end

      def load_index_data
        @product = Product.friendly.preload(*variant_index_includes).find(params[:product_id])
      end

      def load_edit_data
        @product = Product.friendly.preload(*variant_edit_includes).find(params[:product_id])
        @variants = @product.variants.map do |variant|
          [variant.sku_and_options_text, variant.id]
        end
        @variants.insert(0, [Spree.t(:all), @product.master_id])
      end

      def set_viewable
        @image.viewable_type = 'Spree::Variant'
        @image.viewable_id = params[:image][:viewable_id]
      end

      def variant_index_includes
        [
          variant_images: [viewable: { option_values: :option_type }]
        ]
      end

      def variant_edit_includes
        [
          variants_including_master: { option_values: :option_type, images: :viewable }
        ]
      end
    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
spree_backend-4.2.7 app/controllers/spree/admin/images_controller.rb
spree_backend-4.2.6 app/controllers/spree/admin/images_controller.rb
spree_backend-4.2.5 app/controllers/spree/admin/images_controller.rb
spree_backend-4.2.4 app/controllers/spree/admin/images_controller.rb
spree_backend-4.2.3.1 app/controllers/spree/admin/images_controller.rb
spree_backend-4.2.3 app/controllers/spree/admin/images_controller.rb
spree_backend-4.2.2 app/controllers/spree/admin/images_controller.rb
spree_backend-4.2.1 app/controllers/spree/admin/images_controller.rb
spree_backend-4.2.0 app/controllers/spree/admin/images_controller.rb
spree_backend-4.2.0.rc5 app/controllers/spree/admin/images_controller.rb