Sha256: 1c66c936438d6fa9032332b6f5841053477f87f7a425393ecb07183484409ec7

Contents?: true

Size: 1.4 KB

Versions: 5

Compression:

Stored size: 1.4 KB

Contents

class Admin::ImagesController < Admin::BaseController
  resource_controller
  before_filter :load_data

  new_action.response do |wants|
    wants.html {render :action => :new, :layout => false}
  end

  create.response do |wants|
    wants.html {redirect_to admin_product_images_url(@product)}
  end

  update.response do |wants|
    wants.html {redirect_to admin_product_images_url(@product)}
  end

  create.before :set_viewable
  update.before :set_viewable
  destroy.before :destroy_before

  destroy.response do |wants|
    wants.html do
      render :text => ""
    end
  end

  def update_positions
    params[:positions].each do |id, index|
      Image.update_all(['position=?', index], ['id=?', id])
    end

    respond_to do |format|
      format.js  { render :text => 'Ok' }
    end
  end

  private

  def load_data
    @product = Product.find_by_permalink(params[:product_id])
    @variants = @product.variants.collect do |variant|
      [variant.options_text, variant.id ]
    end
    @variants.insert(0, [I18n.t("all"), "All"])
  end

  def set_viewable
    if params[:image].has_key? :viewable_id
      if params[:image][:viewable_id] == "All"
        object.viewable = @product
      else
        object.viewable_type = 'Variant'
        object.viewable_id = params[:image][:viewable_id]
      end
    else
      object.viewable = @product
    end
  end

  def destroy_before
    @viewable = object.viewable
  end

end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
spree_core-0.50.4 app/controllers/admin/images_controller.rb
spree_core-0.50.3 app/controllers/admin/images_controller.rb
spree_core-0.50.2 app/controllers/admin/images_controller.rb
spree_core-0.50.1 app/controllers/admin/images_controller.rb
spree_core-0.50.0 app/controllers/admin/images_controller.rb