Class: Spotlight::PagesController

Inherits:
ApplicationController show all
Includes:
Blacklight::Catalog::SearchContext, Base, Catalog::AccessControlsEnforcement
Defined in:
app/controllers/spotlight/pages_controller.rb

Instance Method Summary collapse

Methods included from Base

#autocomplete_json_response, #blacklight_config

Methods included from Config

#exhibit_specific_blacklight_config

Methods included from Controller

#blacklight_config, #current_exhibit, #current_masthead, #current_masthead=, #default_masthead?, #exhibit_masthead?, #exhibit_search_action_url, #exhibit_search_facet_url, #search_action_url, #search_facet_url

Instance Method Details

#_prefixesObject



87
88
89
# File 'app/controllers/spotlight/pages_controller.rb', line 87

def _prefixes
  @_prefixes ||= super + ['catalog']
end

#createObject

POST /exhibits/1/pages



49
50
51
52
53
54
55
56
57
58
# File 'app/controllers/spotlight/pages_controller.rb', line 49

def create
  @page.attributes = page_params
  @page.last_edited_by = @page.created_by = current_user

  if @page.save
    redirect_to [@page.exhibit, page_collection_name], notice: t(:'helpers.submit.page.created', model: @page.class.model_name.human.downcase)
  else
    render action: 'new'
  end
end

#destroyObject

DELETE /pages/1



72
73
74
75
76
# File 'app/controllers/spotlight/pages_controller.rb', line 72

def destroy
  @page.destroy

  redirect_to [@page.exhibit, page_collection_name], flash: { html_safe: true }, notice: view_context.safe_join([t(:'helpers.submit.page.destroyed', model: @page.class.model_name.human.downcase), undo_link], " ")
end

#editObject

GET /pages/1/edit



44
45
46
# File 'app/controllers/spotlight/pages_controller.rb', line 44

def edit
  @page.lock! current_user
end

#indexObject

GET /exhibits/1/pages



14
15
16
17
18
19
20
21
22
# File 'app/controllers/spotlight/pages_controller.rb', line 14

def index
  # set up a model the inline "add a new page" form
  @page = CanCan::ControllerResource.new(self).send(:build_resource)

  respond_to do |format|
    format.html
    format.json { render json: @pages.published.to_json(methods: [:thumbnail_image_url]) }
  end
end

#newObject

GET /exhibits/1/pages/new



40
41
# File 'app/controllers/spotlight/pages_controller.rb', line 40

def new
end

#previewObject



29
30
31
32
33
34
35
36
37
# File 'app/controllers/spotlight/pages_controller.rb', line 29

def preview
  @page = current_exhibit.pages.find(params['id'])
  authorize! :read, @page
  @block = SirTrevorRails::Block.from_hash(JSON.parse(params[:block], symbolize_names: true), @page)

  respond_to do |format|
    format.html { render 'preview', layout: false }
  end
end

#showObject

GET /pages/1



25
26
27
# File 'app/controllers/spotlight/pages_controller.rb', line 25

def show
  fresh_when([@page.exhibit, @page])
end


91
92
93
94
# File 'app/controllers/spotlight/pages_controller.rb', line 91

def undo_link
  return unless can? :manage, @page
  view_context.link_to(t(:'spotlight.versions.undo'), revert_version_path(@page.versions.last), :method => :post)
end

#updateObject

PATCH/PUT /pages/1



61
62
63
64
65
66
67
68
69
# File 'app/controllers/spotlight/pages_controller.rb', line 61

def update
  @page.lock.delete if @page.lock

  if @page.update(page_params.merge(last_edited_by: current_user))
    redirect_to [@page.exhibit, @page], flash: { html_safe: true }, notice: view_context.safe_join([t(:'helpers.submit.page.updated', model: @page.class.model_name.human.downcase), undo_link], " ")
  else
    render action: 'edit'
  end
end

#update_allObject



78
79
80
81
82
83
84
85
# File 'app/controllers/spotlight/pages_controller.rb', line 78

def update_all
  notice = if @exhibit.update update_all_page_params
    t(:'helpers.submit.page.batch_updated', model: human_name)
  else
    t(:'helpers.submit.page.batch_error', model: human_name)
  end
  redirect_to :back, notice: notice
end