Sha256: 2e5a9e9bb146a9c4c1717f457a644cdd37d66d884f6a27c2c9f4835da9d8f635

Contents?: true

Size: 1.02 KB

Versions: 5

Compression:

Stored size: 1.02 KB

Contents

module ScrivitoResourcebrowser
  class ResourcebrowserController < ApplicationController
    # Return JSON responses without layout information.
    layout false

    # Renders the resource browser modal and returns it in a JSON response.
    def modal
      render json: { content: render_to_string }
    end

    # Render a JSON response that holds the resource browser inspector markup. The inspector either
    # renders the details view for the selected object, or a fallback view that is located under
    # 'app/views/obj/details'.
    def inspector
      @obj = Obj.find(params[:id])

      options = {
        layout: 'scrivito_resourcebrowser/inspector',
      }

      content = begin
        render_to_string(details_view_template(@obj), options)
      rescue ActionView::MissingTemplate
        render_to_string('scrivito_resourcebrowser/obj/details', options)
      end

      render json: { content: content }
    end

    private

    def details_view_template(obj)
      "#{obj.obj_class_name.underscore}/details"
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
scrivito_resourcebrowser-0.0.5 app/controllers/scrivito_resourcebrowser/resourcebrowser_controller.rb
scrivito_resourcebrowser-0.0.4 app/controllers/scrivito_resourcebrowser/resourcebrowser_controller.rb
scrivito_resourcebrowser-0.0.3 app/controllers/scrivito_resourcebrowser/resourcebrowser_controller.rb
scrivito_resourcebrowser-0.0.2 app/controllers/scrivito_resourcebrowser/resourcebrowser_controller.rb
scrivito_resourcebrowser-0.0.1 app/controllers/scrivito_resourcebrowser/resourcebrowser_controller.rb