Class: Spree::Admin::OptionTypesController

Inherits:
ResourceController show all
Defined in:
app/controllers/spree/admin/option_types_controller.rb

Instance Attribute Summary

Attributes included from Core::ControllerHelpers

#title

Instance Method Summary collapse

Methods inherited from ResourceController

belongs_to, create, #create, destroy, #destroy, #edit, #new, new_action, #update, update

Methods included from Core::ControllerHelpers

#access_forbidden, included

Instance Method Details

#availableObject



7
8
9
10
# File 'app/controllers/spree/admin/option_types_controller.rb', line 7

def available
  set_available_option_types
  render :layout => false
end

#removeObject



16
17
18
19
20
21
# File 'app/controllers/spree/admin/option_types_controller.rb', line 16

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

#selectObject

AJAX method for selecting an existing option type and associating with the current product



46
47
48
49
50
51
# File 'app/controllers/spree/admin/option_types_controller.rb', line 46

def select
  @product.option_types << OptionType.find(params[:id])
  @product.reload
  @option_types = @product.option_types
  set_available_option_types
end

#selectedObject



12
13
14
# File 'app/controllers/spree/admin/option_types_controller.rb', line 12

def selected
  @option_types = @product.option_types
end

#update_positionsObject



23
24
25
26
27
28
29
30
31
32
# File 'app/controllers/spree/admin/option_types_controller.rb', line 23

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

#update_values_positionsObject



34
35
36
37
38
39
40
41
42
43
# File 'app/controllers/spree/admin/option_types_controller.rb', line 34

def update_values_positions
  params[:positions].each do |id, index|
    OptionValue.where(:id => id).update_all(:position => index)
  end

  respond_to do |format|
    format.html { redirect_to admin_product_variants_url(params[:product_id]) }
    format.js  { render :text => 'Ok' }
  end
end