Class: BookmarksController

Inherits:
ApplicationController show all
Defined in:
vendor/plugins/blacklight/app/controllers/bookmarks_controller.rb

Instance Method Summary (collapse)

Methods inherited from ApplicationController

#current_user, #default_html_head, #error, #extra_head_content, #javascript_includes, #stylesheet_links, #user_class

Methods included from HydraAccessControlsHelper

#editor?, #reader?, #test_permission

Instance Method Details

- (Object) clear



59
60
61
62
63
64
65
66
# File 'vendor/plugins/blacklight/app/controllers/bookmarks_controller.rb', line 59

def clear    
  if current_user.bookmarks.clear
    flash[:notice] = "Cleared your bookmarks."
  else
    flash[:error] = "There was a problem clearing your bookmarks."
  end
  redirect_to :action => "index"
end

- (Object) collection

overrides the ResourceController collection method see vendor/plugins/resource_controller/



13
14
15
16
17
18
19
20
21
22
23
24
# File 'vendor/plugins/blacklight/app/controllers/bookmarks_controller.rb', line 13

def collection
  user_id = current_user ? current_user.id : nil
  assocations = nil
  conditions = ['user_id = ?', user_id]
  if params[:a] == 'find' && ! params[:q].blank?
    q = "%#{params[:q]}%"
    conditions.first << ' AND (tags.name LIKE ? OR title LIKE ? OR notes LIKE ?)'
    conditions += [q, q, q]
    assocations = [:tags]
  end
  Bookmark.paginate_by_tag(params[:tag], :per_page => 8, :page => params[:page], :order => 'bookmarks.id ASC', :conditions => conditions, :include => assocations)
end

- (Object) create



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'vendor/plugins/blacklight/app/controllers/bookmarks_controller.rb', line 28

def create
  success = true
  @bookmarks = params[:bookmarks]
  if @bookmarks.nil?
    sucess = current_user.bookmarks.create(params[:bookmark])
  else
    @bookmarks.each do |key, bookmark|
      success = false unless current_user.bookmarks.create(bookmark)
    end
  end
  if success
    if @bookmarks.nil? || @bookmarks.size == 1
      flash[:notice] = "Successfully added bookmark."
    else
      flash[:notice] = "Successfully added bookmarks."
    end
  else
    flash[:error] = "There was a problem adding that bookmark."      
  end
  redirect_to :back
end

- (Object) destroy



50
51
52
53
54
55
56
57
# File 'vendor/plugins/blacklight/app/controllers/bookmarks_controller.rb', line 50

def destroy
  if current_user.bookmarks.delete(Bookmark.find(params[:id]))
    flash[:notice] = "Successfully removed that bookmark."
  else
    flash[:error] = "Couldn't remove that bookmark."
  end
  redirect_to :back
end