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.4.27 app/controllers/workarea/admin/catalog_product_images_controller.rb
workarea-admin-3.5.4 app/controllers/workarea/admin/catalog_product_images_controller.rb
workarea-admin-3.4.26 app/controllers/workarea/admin/catalog_product_images_controller.rb
workarea-admin-3.5.3 app/controllers/workarea/admin/catalog_product_images_controller.rb
workarea-admin-3.4.25 app/controllers/workarea/admin/catalog_product_images_controller.rb
workarea-admin-3.5.2 app/controllers/workarea/admin/catalog_product_images_controller.rb
workarea-admin-3.4.24 app/controllers/workarea/admin/catalog_product_images_controller.rb
workarea-admin-3.5.1 app/controllers/workarea/admin/catalog_product_images_controller.rb
workarea-admin-3.4.23 app/controllers/workarea/admin/catalog_product_images_controller.rb
workarea-admin-3.4.22 app/controllers/workarea/admin/catalog_product_images_controller.rb
workarea-admin-3.5.0 app/controllers/workarea/admin/catalog_product_images_controller.rb
workarea-admin-3.4.21 app/controllers/workarea/admin/catalog_product_images_controller.rb
workarea-admin-3.5.0.beta.1 app/controllers/workarea/admin/catalog_product_images_controller.rb
workarea-admin-3.4.20 app/controllers/workarea/admin/catalog_product_images_controller.rb
workarea-admin-3.4.19 app/controllers/workarea/admin/catalog_product_images_controller.rb
workarea-admin-3.4.18 app/controllers/workarea/admin/catalog_product_images_controller.rb
workarea-admin-3.4.17 app/controllers/workarea/admin/catalog_product_images_controller.rb
workarea-admin-3.4.16 app/controllers/workarea/admin/catalog_product_images_controller.rb
workarea-admin-3.4.15 app/controllers/workarea/admin/catalog_product_images_controller.rb
workarea-admin-3.4.14 app/controllers/workarea/admin/catalog_product_images_controller.rb