Module: Blacklight::DefaultComponentConfiguration::ClassMethods

Defined in:
app/controllers/concerns/blacklight/default_component_configuration.rb

Instance Method Summary collapse

Instance Method Details

#add_nav_action(name, opts = {}) ⇒ Object

Add a partial to the header navbar.

Parameters:

  • name (String)

    the name of the document partial

  • opts (Hash) (defaults to: {})

Options Hash (opts):

  • :if (Symbol, Proc)

    render this action if the method identified by the symbol or the proc evaluates to true. The proc will receive the action configuration and the document or documents for the action.

  • :unless (Symbol, Proc)

    render this action unless the method identified by the symbol or the proc evaluates to true. The proc will receive the action configuration and the document or documents for the action.



90
91
92
# File 'app/controllers/concerns/blacklight/default_component_configuration.rb', line 90

def add_nav_action(name, opts = {})
  blacklight_config.add_nav_action(name, opts)
end

#add_results_collection_tool(name, opts = {}) ⇒ Object

Add a tool to be displayed for the list of search results themselves.

Parameters:

  • name (String)

    the name of the document partial

  • opts (Hash) (defaults to: {})

Options Hash (opts):

  • :if (Symbol, Proc)

    render this action if the method identified by the symbol or the proc evaluates to true. The proc will receive the action configuration and the document or documents for the action.

  • :unless (Symbol, Proc)

    render this action unless the method identified by the symbol or the proc evaluates to true. The proc will receive the action configuration and the document or documents for the action.



84
85
86
# File 'app/controllers/concerns/blacklight/default_component_configuration.rb', line 84

def add_results_collection_tool(name, opts = {})
  blacklight_config.add_results_collection_tool(name, opts)
end

#add_results_document_tool(name, opts = {}) ⇒ Object

Add a tool to be displayed for each document in the search results.

Parameters:

  • name (String)

    the name of the document partial

  • opts (Hash) (defaults to: {})

Options Hash (opts):

  • :if (Symbol, Proc)

    render this action if the method identified by the symbol or the proc evaluates to true. The proc will receive the action configuration and the document or documents for the action.

  • :unless (Symbol, Proc)

    render this action unless the method identified by the symbol or the proc evaluates to true. The proc will receive the action configuration and the document or documents for the action.



78
79
80
# File 'app/controllers/concerns/blacklight/default_component_configuration.rb', line 78

def add_results_document_tool(name, opts = {})
  blacklight_config.add_results_document_tool(name, opts)
end

#add_show_tools_partial(name, opts = {}) ⇒ Object

Add a partial to the tools for rendering a document

Parameters:

  • name (String)

    the name of the document partial

  • opts (Hash) (defaults to: {})

Options Hash (opts):

  • :if (Symbol, Proc)

    render this action if the method identified by the symbol or the proc evaluates to true. The proc will receive the action configuration and the document or documents for the action.

  • :unless (Symbol, Proc)

    render this action unless the method identified by the symbol or the proc evaluates to true. The proc will receive the action configuration and the document or documents for the action.

  • :define_method (Boolean)

    define a controller method as named, default: true

  • :validator (Symbol)

    method for toggling between success and failure, should return Boolean (true if valid)

  • :callback (Symbol)

    method for further processing of documents, receives Array of documents



42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'app/controllers/concerns/blacklight/default_component_configuration.rb', line 42

def add_show_tools_partial(name, opts = {})
  blacklight_config.add_show_tools_partial(name, opts)

  return if method_defined?(name) || opts[:define_method] == false

  # Define a simple action handler for the tool
  define_method name do
    @response, @documents = action_documents

    if request.post? && opts[:callback] &&
      (opts[:validator].blank? || self.send(opts[:validator]))

      self.send(opts[:callback], @documents)

      flash[:success] ||= I18n.t("blacklight.#{name}.success", default: nil)

      respond_to do |format|
        format.html do
          return render "#{name}_success", layout: false if request.xhr?
          redirect_to action_success_redirect_path
        end
      end
    else
      respond_to do |format|
        format.html do
          return render layout: false if request.xhr?
          # Otherwise draw the full page
        end
      end
    end
  end
end