Class: SelectedItemsController

Inherits:
ApplicationController
  • Object
show all
Defined in:
lib/generators/atrium/install/templates/controllers/selected_items_controller.rb

Overview

TODO: This concept should be proposed to Blacklight core as something to add into. Be it as an callback for the search or some process therein.

Instance Method Summary collapse

Instance Method Details

#indexObject



6
7
8
# File 'lib/generators/atrium/install/templates/controllers/selected_items_controller.rb', line 6

def index
  @searches = current_user.searches
end

#saveObject



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/generators/atrium/install/templates/controllers/selected_items_controller.rb', line 10

def save
  success = true
  existing_selected_items = current_user.selected_document_ids
  @selected_items = params[:items] || []
  @selected_items.delete_if {|key, value| existing_selected_items.include?(value[:document_id]) }
  @selected_items.each do |key, item|
    success = false unless current_user.selected_items.create(item)
  end
  if @selected_items.length > 0 && success
    flash[:notice] = 'Selected items '+ @selected_items.length.to_s + ' was saved successfully.'
  elsif @selected_items.length > 0
    flash[:error] = 'Error saving selected items'
  end

  redirect_to :back
end