Sha256: c5b239fd790be3246647d5962da633399ce5a4f2456a0f0137ef9316505f205e

Contents?: true

Size: 1.05 KB

Versions: 5

Compression:

Stored size: 1.05 KB

Contents

# frozen_string_literal: true

module SolidusAdmin
  class OptionTypesController < SolidusAdmin::BaseController
    include SolidusAdmin::ControllerHelpers::Search

    before_action :load_option_type, only: [:move]

    def index
      option_types = apply_search_to(
        Spree::OptionType.all,
        param: :q,
      )

      set_page_and_extract_portion_from(option_types)

      respond_to do |format|
        format.html { render component('option_types/index').new(page: @page) }
      end
    end

    def move
      @option_type.insert_at(params[:position].to_i)

      respond_to do |format|
        format.js { head :no_content }
      end
    end

    def destroy
      @option_types = Spree::OptionType.where(id: params[:id])

      Spree::OptionType.transaction { @option_types.destroy_all }

      flash[:notice] = t('.success')
      redirect_back_or_to option_types_path, status: :see_other
    end

    private

    def load_option_type
      @option_type = Spree::OptionType.find(params[:id])
      authorize! action_name, @option_type
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
solidus_admin-0.3.2 app/controllers/solidus_admin/option_types_controller.rb
solidus_admin-0.3.1 app/controllers/solidus_admin/option_types_controller.rb
solidus_admin-0.3.0 app/controllers/solidus_admin/option_types_controller.rb
solidus_admin-0.2.0 app/controllers/solidus_admin/option_types_controller.rb
solidus_admin-0.1.0 app/controllers/solidus_admin/option_types_controller.rb