Class: Admin::TaxonsController

Inherits:
BaseController
  • Object
show all
Includes:
Railslove::Plugins::FindByParam::SingletonMethods
Defined in:
app/controllers/admin/taxons_controller.rb

Instance Method Summary collapse

Instance Method Details

#availableObject



119
120
121
122
123
124
125
# File 'app/controllers/admin/taxons_controller.rb', line 119

def available
  @product = load_product
  @taxons = params[:q].blank? ? [] : Taxon.where('lower(name) LIKE ?', "%#{params[:q].mb_chars.downcase}%")
  @taxons.delete_if { |taxon| @product.taxons.include?(taxon) }

  respond_with(:admin, @taxons)
end

#batch_selectObject



147
148
149
150
151
152
153
# File 'app/controllers/admin/taxons_controller.rb', line 147

def batch_select
  @product = load_product
  @taxons = params[:taxon_ids].map{|id| Taxon.find(id)}.compact
  @product.taxons = @taxons
  @product.save
  redirect_to selected_admin_product_taxons_url(@product)
end

#createObject



6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'app/controllers/admin/taxons_controller.rb', line 6

def create
@taxonomy = Taxonomy.find(params[:taxonomy_id])
#~ @taxon = @taxonomy.taxons.build(params[:taxon])
#~ if @taxon.save
  respond_with(@taxon) do |format|
    format.json {render :json => @taxon.to_json }
  end
else
  flash[:error] = I18n.t('errors.messages.could_not_create_taxon')
  respond_with(@taxon) do |format|
    format.html { redirect_to @taxonomy ? edit_admin_taxonomy_url(@taxonomy) : admin_taxonomies_url }
  end
end

#destroyObject



106
107
108
109
110
# File 'app/controllers/admin/taxons_controller.rb', line 106

def destroy
  @taxon = Taxon.find(params[:id])
  @taxon.destroy
  respond_with(@taxon) { |format| format.json { render :json => '' } }
end

#editObject



30
31
32
33
34
35
36
# File 'app/controllers/admin/taxons_controller.rb', line 30

def edit
  @taxonomy = Taxonomy.find(params[:taxonomy_id])
  @taxon = @taxonomy.taxons.find(params[:id])
  @permalink_part = @taxon.permalink.split("/").last

  respond_with(:admin, @taxon) 
end

#removeObject



127
128
129
130
131
132
133
134
135
# File 'app/controllers/admin/taxons_controller.rb', line 127

def remove
  @product = load_product
  @taxon = Taxon.find(params[:id])
  @product.taxons.delete(@taxon)
  @product.save
  @taxons = @product.taxons

  respond_with(@taxon) { |format| format.js { render_js_for_destroy } }
end

#selectObject



137
138
139
140
141
142
143
144
145
# File 'app/controllers/admin/taxons_controller.rb', line 137

def select
  @product = load_product
  @taxon = Taxon.find(params[:id])
  @product.taxons << @taxon
  @product.save
  @taxons = @product.taxons

  respond_with(:admin, @taxons)
end

#selectedObject



112
113
114
115
116
117
# File 'app/controllers/admin/taxons_controller.rb', line 112

def selected
  @product = load_product
  @taxons = @product.taxons

  respond_with(:admin, @taxons)
end

#updateObject



21
22
23
24
25
26
27
28
# File 'app/controllers/admin/taxons_controller.rb', line 21

def update
  update_before
  update_after
  respond_with(@taxon) do |format|
    format.html { redirect_to edit_admin_taxonomy_url(@taxonomy) }
    format.json { render :json => @taxon.to_json }
  end
end