Sha256: 6547cc836d4995855e0776526a0c34508306c0972fce85aca8eae5ce69cdb13f

Contents?: true

Size: 1.78 KB

Versions: 62

Compression:

Stored size: 1.78 KB

Contents

module Workarea
  module Admin
    class CatalogProductImagesController < Admin::ApplicationController
      required_permissions :catalog
      before_action :find_product

      def index
        @images = ProductImagesViewModel.new(@product)
      end

      def create
        @image = @product.images.build(params[:image])

        if @image.save
          flash[:success] = t('workarea.admin.catalog_product_images.flash_messages.created')
          redirect_to catalog_product_images_path(@product)
        else
          render :index, status: :unprocessable_entity
        end
      end

      def edit
        @image = @product.images.find(params[:id])
      end

      def update
        image = @product.images.find(params[:id])

        if image.update_attributes(params[:image])
          flash[:success] = t('workarea.admin.catalog_product_images.flash_messages.updated')
          redirect_to catalog_product_images_path(@product)
        else
          render :index, status: :unprocessable_entity
        end
      end

      def positions
        positions = params.fetch(:order, [])

        @product.images.each do |image|
          image.position = positions.index(image.id.to_s) || 999
        end

        @product.save!

        head :ok
      end

      def options
        @image_options ||= Catalog::Product.autocomplete_image_options(params[:q])
      end

      def destroy
        @product.images.find(params[:id]).destroy
        flash[:success] = t('workarea.admin.catalog_product_images.flash_messages.removed')
        redirect_to catalog_product_images_path(@product)
      end

      private

      def find_product
        model = Catalog::Product.find_by(slug: params[:catalog_product_id])
        @product = ProductViewModel.wrap(model, view_model_options)
      end
    end
  end
end

Version data entries

62 entries across 62 versions & 1 rubygems

Version Path
workarea-admin-3.5.27 app/controllers/workarea/admin/catalog_product_images_controller.rb
workarea-admin-3.5.26 app/controllers/workarea/admin/catalog_product_images_controller.rb
workarea-admin-3.4.45 app/controllers/workarea/admin/catalog_product_images_controller.rb
workarea-admin-3.5.25 app/controllers/workarea/admin/catalog_product_images_controller.rb
workarea-admin-3.5.23 app/controllers/workarea/admin/catalog_product_images_controller.rb
workarea-admin-3.4.44 app/controllers/workarea/admin/catalog_product_images_controller.rb
workarea-admin-3.5.22 app/controllers/workarea/admin/catalog_product_images_controller.rb
workarea-admin-3.4.43 app/controllers/workarea/admin/catalog_product_images_controller.rb
workarea-admin-3.5.21 app/controllers/workarea/admin/catalog_product_images_controller.rb
workarea-admin-3.4.42 app/controllers/workarea/admin/catalog_product_images_controller.rb
workarea-admin-3.5.20 app/controllers/workarea/admin/catalog_product_images_controller.rb
workarea-admin-3.4.41 app/controllers/workarea/admin/catalog_product_images_controller.rb
workarea-admin-3.5.19 app/controllers/workarea/admin/catalog_product_images_controller.rb
workarea-admin-3.4.40 app/controllers/workarea/admin/catalog_product_images_controller.rb
workarea-admin-3.5.18 app/controllers/workarea/admin/catalog_product_images_controller.rb
workarea-admin-3.4.39 app/controllers/workarea/admin/catalog_product_images_controller.rb
workarea-admin-3.5.17 app/controllers/workarea/admin/catalog_product_images_controller.rb
workarea-admin-3.4.38 app/controllers/workarea/admin/catalog_product_images_controller.rb
workarea-admin-3.5.16 app/controllers/workarea/admin/catalog_product_images_controller.rb
workarea-admin-3.4.37 app/controllers/workarea/admin/catalog_product_images_controller.rb