Skip to content

Commit

Permalink
Merge pull request #3168 from refinery/feature/2707
Browse files Browse the repository at this point in the history
Add preview skip_to_first_child page message
  • Loading branch information
parndt committed May 17, 2016
2 parents 138994b + ae30517 commit 2cf6f98
Show file tree
Hide file tree
Showing 11 changed files with 59 additions and 18 deletions.
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
$(document).ready(function(){
// focus first field in an admin form.
$('form input[type=text]:first').focus();

init_flash_messages();
});

init_flash_messages = function() {
$('#flash_container .flash').append(
"<button id='flash_close'><%= I18n.t('refinery.message.close') %></button>"
);

$('#flash_container').on('click', '#flash_close', function(e) {
$('#flash').hide();
Expand Down
13 changes: 9 additions & 4 deletions core/app/assets/stylesheets/refinery/sections/_layout.scss
Original file line number Diff line number Diff line change
Expand Up @@ -197,10 +197,14 @@ noscript .flash.flash_alert a:hover {
display: inline;
font-weight: bold;
}
.flash a#flash_close {
position: absolute;
right: 9px;
top: 7px;
.flash #flash_close {
background: none;
border: none;
color: #41403C;
cursor: pointer;
float: right;
font-size: 1em;
margin-top: 3px;
}
#content .visual_editor_box a,
#content .ui-tabs a {
Expand Down Expand Up @@ -1512,6 +1516,7 @@ a.information:hover {
text-transform: uppercase;
white-space: nowrap;
background-color: #bfbfbf;
margin-right: 0.25em;
&.important{
background-color: #c43c35;
}
Expand Down
1 change: 1 addition & 0 deletions core/app/views/refinery/_content_page.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@
:can_use_fallback => !local_assigns[:show_empty_sections] && !local_assigns[:remove_automatic_sections]
}) %>
<%= render '/refinery/draft_page_message' if @page && @page.draft? -%>
<%= render '/refinery/skip_to_first_child_page_message' if @page && @page.skip_to_first_child? -%>
2 changes: 0 additions & 2 deletions core/app/views/refinery/_message.html.erb
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
<% flash.each do |key, value| %>
<div id='flash' class="flash flash_<%= key %>">
<%= value %>
<%= link_to t(".close#{'_this_message' if key.to_s == "message"}"), "",
:id => "flash_close" %>
</div>
<% end %>
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<aside class='page_skip_to_first_child'>
<%= t('.skip_to_first_child') %>
</aside>
2 changes: 2 additions & 0 deletions core/config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ en:
close_this_message: Close this message
draft_page_message:
not_live: This page is NOT live for public viewing.
skip_to_first_child_page_message:
skip_to_first_child: "This page uses the option \"Skip to first child\" and will never be displayed to visitors."
footer:
copyright: "Copyright © %{year} %{site_name}"
no_script:
Expand Down
16 changes: 8 additions & 8 deletions pages/app/controllers/refinery/pages/admin/preview_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ class PreviewController < Refinery::PagesController

skip_before_action :error_404, :set_canonical

layout :layout

def show
render_with_templates?
end
Expand All @@ -33,16 +31,18 @@ def find_page
end
alias_method :page, :find_page

def layout
'application'
def page_params
params.require(:page).permit(permitted_page_params)
end

def page_params
params.require(:page).permit(
private

def permitted_page_params
[
:browser_title, :draft, :link_url, :menu_title, :meta_description,
:parent_id, :skip_to_first_child, :show_in_menu, :title, :view_template,
:layout_template, parts_attributes: [:id, :title, :body, :position]
)
:layout_template, :custom_slug, parts_attributes: [:id, :title, :slug, :body, :position]
]
end
end
end
Expand Down
8 changes: 8 additions & 0 deletions pages/app/helpers/refinery/admin/pages_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,14 @@ def page_meta_information(page)
::I18n.t('hidden', :scope => 'refinery.admin.pages.page')
end unless page.show_in_menu?

meta_information << content_tag(:span, :class => 'label') do
::I18n.t('skip_to_first_child', :scope => 'refinery.admin.pages.page')
end if page.skip_to_first_child?

meta_information << content_tag(:span, :class => 'label') do
::I18n.t('redirected', :scope => 'refinery.admin.pages.page')
end if page.link_url?

meta_information << content_tag(:span, :class => 'label notice') do
::I18n.t('draft', :scope => 'refinery.admin.pages.page')
end if page.draft?
Expand Down
6 changes: 4 additions & 2 deletions pages/config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,11 @@ en:
new: Add a new child page
expand_collapse: Expand or collapse sub pages
page:
view_live_html: View this page live <br/><em>(opens in a new window)</em>
hidden: hidden
draft: draft
hidden: hidden
redirected: Redirected
skip_to_first_child: Skip to first child
view_live_html: View this page live <br/><em>(opens in a new window)</em>
form:
preview: Preview
preview_changes: Preview your changes before making them live
Expand Down
1 change: 1 addition & 0 deletions pages/spec/features/refinery/pages_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,7 @@ def standard_page_menu_items_exist?

within ".active * > .selected a" do
expect(page).to have_content(child_page.title)
expect(page).to_not have_content(::I18n.t('skip_to_first_child', scope: 'refinery.skip_to_first_child_page_message'))
end
end
end
Expand Down
20 changes: 20 additions & 0 deletions pages/spec/helpers/refinery/pages/admin/pages_helper_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,26 @@ module Admin
end
end

context "when skip_to_first_child is true" do
it "adds 'skip to first child' label" do
page.skip_to_first_child = true

expect(helper.page_meta_information(page)).to eq(
%Q{<span class="label">#{::I18n.t('refinery.admin.pages.page.skip_to_first_child')}</span>}
)
end
end

context "when link_url is present" do
it "adds 'redirected' label" do
page.link_url = '/redirect'

expect(helper.page_meta_information(page)).to eq(
%Q{<span class="label">#{::I18n.t('refinery.admin.pages.page.redirected')}</span>}
)
end
end

context "when draft is true" do
it "adds 'draft' label" do
page.draft = true
Expand Down

0 comments on commit 2cf6f98

Please sign in to comment.