Sha256: 7ae65322d48e62d141ed74485a94e6c2d7db91e3bfe7a98b14e77192c1b52417

Contents?: true

Size: 1.81 KB

Versions: 14

Compression:

Stored size: 1.81 KB

Contents

class Admin::OptionTypesController < Admin::ResourceController
  before_filter :load_product, :only => [:selected, :available, :remove]

  def available
    set_available_option_types
    render :layout => false
  end

  def selected
    @option_types = @product.option_types
  end

  def remove
    @product.option_types.delete(@option_type)
    @product.save
    flash.notice = I18n.t("notice_messages.option_type_removed")
    redirect_to selected_admin_product_option_types_url(@product)
  end

  def update_positions
    params[:positions].each do |id, index|
      OptionType.update_all(['position=?', index], ['id=?', id])
    end
    
    respond_to do |format|
      format.html { redirect_to admin_product_variants_url(params[:product_id]) }
      format.js  { render :text => 'Ok' }
    end
  end

  # AJAX method for selecting an existing option type and associating with the current product
  def select
    @product = Product.find_by_param!(params[:product_id])
    product_option_type = ProductOptionType.new(:product => @product, :option_type => OptionType.find(params[:id]))
    product_option_type.save
    @product.reload
    @option_types = @product.option_types
    set_available_option_types
  end

  protected
    
    def location_after_save
      if @option_type.created_at == @option_type.updated_at
        edit_admin_option_type_url(@option_type)
      else
        admin_option_types_url
      end
    end


  private
    def load_product
      @product = Product.find_by_param!(params[:product_id])
    end
  
    def set_available_option_types
      @available_option_types = OptionType.all
      selected_option_types = []
      @product.options.each do |option|
        selected_option_types << option.option_type
      end
      @available_option_types.delete_if {|ot| selected_option_types.include? ot}
    end
end

Version data entries

14 entries across 14 versions & 6 rubygems

Version Path
apispree_core-0.0.0 app/controllers/admin/option_types_controller.rb
My-Commerce_core-1.1.0 app/controllers/admin/option_types_controller.rb
My-Commerce_core-1.0.0 app/controllers/admin/option_types_controller.rb
MyCommerceapi-1.0.0 core/app/controllers/admin/option_types_controller.rb
MyCommerce-0.0.3 core/app/controllers/admin/option_types_controller.rb
rfcommerce_core-0.0.3 app/controllers/admin/option_types_controller.rb
spree_core-0.60.6 app/controllers/admin/option_types_controller.rb
spree_core-0.60.5 app/controllers/admin/option_types_controller.rb
spree_core-0.60.4 app/controllers/admin/option_types_controller.rb
spree_core-0.60.3 app/controllers/admin/option_types_controller.rb
spree_core-0.60.2 app/controllers/admin/option_types_controller.rb
spree_core-0.60.1 app/controllers/admin/option_types_controller.rb
spree_core-0.60.0 app/controllers/admin/option_types_controller.rb
spree_core-0.60.0.RC1 app/controllers/admin/option_types_controller.rb