Skip to content

Commit 262bad4

Browse files
committed
Merge pull request #405 from sul-dlss/edit-in-place-home
Add edit in place to home page
2 parents d31d7ad + c59e66a commit 262bad4

File tree

21 files changed

+176
-56
lines changed

21 files changed

+176
-56
lines changed

app/controllers/spotlight/home_pages_controller.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ class HomePagesController < Spotlight::PagesController
66

77
def edit
88
add_breadcrumb t(:'spotlight.curation.sidebar.feature_pages'), exhibit_feature_pages_path(@exhibit)
9-
add_breadcrumb @page.title_or_default, [:edit, @exhibit, @page]
9+
add_breadcrumb @page.title, [:edit, @exhibit, @page]
1010
super
1111
end
1212

app/controllers/spotlight/pages_controller.rb

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,10 @@ def start_new_search_session?
7777
end
7878

7979
def update_all_page_params
80-
params.require(:exhibit).permit("#{page_collection_name}_attributes" => [:id, :published, :title, :weight, :display_sidebar, :parent_page_id ])
80+
params.require(:exhibit).permit(
81+
"#{page_collection_name}_attributes" => [:id, :published, :title, :weight, :display_sidebar, :parent_page_id ],
82+
"home_pages_attributes" => [:id, :title, :display_title]
83+
)
8184
end
8285

8386
def human_name

app/helpers/spotlight/pages_helper.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,5 +29,8 @@ def multi_up_item_grid_caption(block, document)
2929
end
3030
end
3131
end
32+
def disable_save_pages_button?
33+
page_collection_name == "about_pages" && @pages.empty?
34+
end
3235
end
3336
end

app/models/spotlight/exhibit.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ class Spotlight::Exhibit < ActiveRecord::Base
2323
accepts_nested_attributes_for :searches
2424
accepts_nested_attributes_for :about_pages
2525
accepts_nested_attributes_for :feature_pages
26+
accepts_nested_attributes_for :home_pages
2627
accepts_nested_attributes_for :contacts
2728
accepts_nested_attributes_for :contact_emails
2829
accepts_nested_attributes_for :roles, allow_destroy: true, reject_if: proc {|attr| attr['user_key'].blank?}

app/models/spotlight/home_page.rb

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,21 +6,26 @@ class HomePage < Spotlight::Page
66
before_save :publish
77
before_create :default_content
88

9-
def title_or_default
10-
title.present? ? title : I18n.t('spotlight.pages.index.home_pages.title')
9+
def should_display_title?
10+
display_title
1111
end
1212

1313
private
1414
def self.default_content_text
1515
"This is placeholder content for the exhibit homepage. Curators of this exhibit can edit this page to customize it for the exhibit."
1616
end
1717

18+
def self.default_title_text
19+
"Exhibit Home"
20+
end
21+
1822
def publish
1923
self.display_sidebar = true
2024
self.published = true
2125
end
2226

2327
def default_content
28+
self.title = Spotlight::HomePage.default_title_text
2429
self.content = {
2530
"data" => [
2631
{"type" => "text",

app/models/spotlight/page.rb

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,13 @@ def top_level_page_or_self
3838
parent_page || self
3939
end
4040

41-
# Subclasses may override this if they have a default
42-
def title_or_default
43-
title
44-
end
45-
4641
def should_generate_new_friendly_id?
4742
title_changed?
4843
end
49-
44+
45+
def should_display_title?
46+
title.present?
47+
end
48+
5049
end
5150
end

app/views/spotlight/dashboards/_page.html.erb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<tr>
22
<td>
3-
<h4 class="panel-title"><%= page.title_or_default %></h4>
3+
<h4 class="panel-title"><%= page.title %></h4>
44
<div class="page-links">
55
<%= exhibit_view_link page, :class => 'btn btn-link' %> &middot;
66
<%= exhibit_edit_link page, :class => 'btn btn-link' %>
Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,24 @@
1-
<div class="home_page">
2-
<h3><%= t('spotlight.pages.index.feature_pages.home_pages_header') %></h3>
3-
<div class="panel panel-default">
4-
<div class="panel-heading page">
5-
<div class="main">
6-
<h3 class="panel-title"><%= current_exhibit.home_page.title_or_default %></h3>
7-
<div class="page-links">
8-
<%= exhibit_view_link @exhibit.home_page, class: 'btn btn-link' %> &middot;
9-
<%= exhibit_edit_link @exhibit.home_page, class: 'btn btn-link' %>
1+
<%= f.fields_for "home_pages" do |p| %>
2+
<% page = p.object %>
3+
<div class="home_page">
4+
<h3><%= t('spotlight.pages.index.feature_pages.home_pages_header') %></h3>
5+
<div class="panel panel-default">
6+
<div class="panel-heading page">
7+
<div class="main">
8+
<%= p.hidden_field :id, value: page.id , class: 'form-control input-sm' %>
9+
<h3 class="panel-title">
10+
<a href="#edit-in-place" class="field-label"><%= page.title %></a>
11+
<%= p.hidden_field :title, value: page.title , class: 'form-control input-sm' %>
12+
</h3>
13+
<div class="col-sm-9 page-links">
14+
<%= exhibit_view_link page, class: 'btn btn-link' %> &middot;
15+
<%= exhibit_edit_link page, class: 'btn btn-link' %>
16+
</div>
17+
<div class="col-sm-3 display-sidebar-control">
18+
<%= p.check_box :display_title, label: t('spotlight.administration.display_title') %>
19+
</div>
1020
</div>
1121
</div>
1222
</div>
1323
</div>
14-
</div>
24+
<% end %>

app/views/spotlight/pages/_order_pages.html.erb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<%= curation_page_title t(:"spotlight.pages.index.#{page_collection_name}.header") %>
22
<%= bootstrap_form_for @exhibit, url: polymorphic_path([:update_all, @exhibit, page_collection_name]), style: :horizontal, right: "col-sm-10", html: {:'data-form-observer' => true} do |f| %>
33

4-
<%= render partial: 'header' %>
4+
<%= render partial: 'header', locals: {f: f} %>
55
<h3><%= t :'.pages_header' %></h3>
66
<p><%= t :'.instructions' %></p>
77
<div class="panel-group dd <%= page_collection_name %>_admin" id="nested-pages">
@@ -15,7 +15,7 @@
1515
</div>
1616
<div class="form-actions pull-right">
1717
<div class="primary-actions">
18-
<%= button_tag action_label(page_collection_name, :update_all), class: "btn btn-primary", disabled: @pages.empty? %>
18+
<%= button_tag action_label(page_collection_name, :update_all), class: "btn btn-primary", disabled: disable_save_pages_button? %>
1919
</div>
2020
</div>
2121
<%- end -%>

app/views/spotlight/pages/_page.html.erb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@
1313
<%= f.hidden_field :id %>
1414
<%= f.hidden_field :weight, data: {property: "weight"} %>
1515
<h3 class="panel-title">
16-
<a href="#edit-in-place" class="field-label"><%= page.title_or_default %></a>
17-
<%= f.hidden_field :title, value: page.title_or_default , class: 'form-control input-sm' %>
16+
<a href="#edit-in-place" class="field-label"><%= page.title %></a>
17+
<%= f.hidden_field :title, value: page.title , class: 'form-control input-sm' %>
1818
</h3>
1919
<div class="row">
2020
<div class="page-links col-sm-9">

0 commit comments

Comments
 (0)