Sha256: 20d77f031d8d8f90b1ed74185f2ddfb0fd3b0d2bfb1f0615e6e4083bb8efea19

Contents?: true

Size: 1.47 KB

Versions: 3

Compression:

Stored size: 1.47 KB

Contents

module Spotlight
  class ResourcesController < Spotlight::ApplicationController
    before_filter :authenticate_user!, except: [:show]

    load_and_authorize_resource :exhibit, class: Spotlight::Exhibit
    before_filter :build_resource, only: [:create]

    load_and_authorize_resource through: :exhibit
    helper_method :from_popup?

    def new

      @resource.attributes = resource_params if params[:resource]
      @resource = @resource.becomes_provider

      ## TODO: in Rails 4.1, replace this with a variant
      if from_popup?
        render layout: 'spotlight/popup'
      else
        render
      end
    end

    def create
      @resource.attributes = resource_params
      @resource = @resource.becomes_provider

      if @resource.save_and_commit
        if from_popup?
          render layout: false, text: "<html><script>window.close();</script></html>"
        else
          redirect_to admin_exhibit_catalog_index_path(@resource.exhibit, sort: :timestamp)
        end
      else
        render action: 'new'
      end
    end

    def reindex_all
      @exhibit.reindex_later

      redirect_to admin_exhibit_catalog_index_path(@exhibit), notice: t(:'spotlight.resources.reindexing_in_progress')
    end

    protected
    def resource_params
      params.require(:resource).permit(:url)
    end

    def build_resource
      @resource ||= @exhibit.resources.build(resource_params).becomes_provider
    end

    def from_popup?
      params.fetch(:popup, false)
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
blacklight-spotlight-0.4.1 app/controllers/spotlight/resources_controller.rb
blacklight-spotlight-0.3.1 app/controllers/spotlight/resources_controller.rb
blacklight-spotlight-0.3.0 app/controllers/spotlight/resources_controller.rb