Sha256: 565192a52cc3b32aca0fc4aa3194fde0aa2a8af412e4a808c6394bcd8811ccc7

Contents?: true

Size: 1.27 KB

Versions: 14

Compression:

Stored size: 1.27 KB

Contents

module Admin
  class ImagesController < BaseController

    include ActionView::Helpers::SanitizeHelper
    include ActionView::Helpers::TextHelper

    defaults :collection_name => 'assets', :instance_name => 'asset'

    respond_to :json, :only => [:index, :create, :destroy]

    def index
      index! do |response|
        response.json do
          render :json => { :images => @assets.collect { |image| image_to_json(image) } }
        end
      end
    end

    def create
      params[:asset] = { :name => params[:name], :source => params[:file] } if params[:file]

      create! do |success, failure|
        success.json do
          render :json => image_to_json(@asset)
        end
        failure.json { render :json => { :status => 'error' } }
      end
    end

    protected

    def collection
      @assets ||= begin_of_association_chain.assets
    end

    def begin_of_association_chain
      @asset_collection ||= AssetCollection.find_or_create_internal(current_site)
    end

    def image_to_json(image)
      {
        :status       => 'success',
        :name         => truncate(image.name, :length => 15),
        :url          => image.source.url,
        :vignette_url => image.vignette_url,
        :destroy_url  => admin_image_url(image, :json)
      }
    end

  end
end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
locomotive_cms-1.0.0.beta.2 app/controllers/admin/images_controller.rb
locomotive_cms-1.0.0.beta app/controllers/admin/images_controller.rb
locomotive_cms-0.0.4.beta12 app/controllers/admin/images_controller.rb
locomotive_cms-0.0.4.beta11 app/controllers/admin/images_controller.rb
locomotive_cms-0.0.4.beta10 app/controllers/admin/images_controller.rb
locomotive_cms-0.0.4.beta9 app/controllers/admin/images_controller.rb
locomotive_cms-0.0.4.beta8 app/controllers/admin/images_controller.rb
locomotive_cms-0.0.4.beta7 app/controllers/admin/images_controller.rb
locomotive_cms-0.0.4.beta5 app/controllers/admin/images_controller.rb
locomotive_cms-0.0.4.beta4 app/controllers/admin/images_controller.rb
locomotive_cms-0.0.4.beta3 app/controllers/admin/images_controller.rb
locomotive_cms-0.0.4.beta2 app/controllers/admin/images_controller.rb
locomotive_cms-0.0.4.beta1 app/controllers/admin/images_controller.rb
locomotive_cms-0.0.4 app/controllers/admin/images_controller.rb