Skip to content

Commit

Permalink
Refactored the Refinery::Admin::PagesController.
Browse files Browse the repository at this point in the history
  • Loading branch information
parndt committed Nov 16, 2014
1 parent aec2943 commit 3601775
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 16 deletions.
34 changes: 20 additions & 14 deletions pages/app/controllers/refinery/admin/pages_controller.rb
Expand Up @@ -8,7 +8,7 @@ class PagesController < Refinery::AdminController
:include => [:translations, :children],
:paging => false

before_action :load_valid_templates, :only => [:edit, :new, :create, :update]
helper_method :valid_layout_templates, :valid_view_templates

def new
@page = Page.new(new_page_params)
Expand All @@ -24,10 +24,7 @@ def children

def update
if @page.update_attributes(page_params)
flash.notice = t(
'refinery.crudify.updated',
:what => "'#{@page.title}'"
)
flash.notice = t('refinery.crudify.updated', what: "'#{@page.title}'")

if from_dialog?
self.index
Expand All @@ -36,11 +33,8 @@ def update
else
if params[:continue_editing] =~ /true|on|1/
if request.xhr?
render :partial => 'save_and_continue_callback', :locals => {
:new_refinery_edit_page_path => refinery.admin_edit_page_path(@page.nested_url),
:new_refinery_page_path => refinery.admin_page_path(@page.nested_url),
:new_page_path => refinery.pages_admin_preview_page_path(@page.nested_url)
}
render partial: 'save_and_continue_callback',
locals: save_and_continue_locals(@page)
else
redirect_to :back
end
Expand Down Expand Up @@ -85,11 +79,14 @@ def globalize!
end
end

def load_valid_templates
@valid_layout_templates = Pages.layout_template_whitelist &
Pages.valid_templates('app', 'views', '{layouts,refinery/layouts}', '*html*')
def valid_layout_templates
Pages.layout_template_whitelist & Pages.valid_templates(
'app', 'views', '{layouts,refinery/layouts}', '*html*'
)
end

@valid_view_templates = Pages.valid_templates('app', 'views', '{pages,refinery/pages}', '*html*')
def valid_view_templates
Pages.valid_templates('app', 'views', '{pages,refinery/pages}', '*html*')
end

def page_params
Expand All @@ -103,6 +100,15 @@ def page_params
def new_page_params
params.permit(:parent_id, :view_template, :layout_template)
end

private def save_and_continue_locals(page)
nested_url = page.nested_url
{
new_refinery_edit_page_path: refinery.admin_edit_page_path(nested_url),
new_refinery_page_path: refinery.admin_page_path(nested_url),
new_page_path: refinery.pages_admin_preview_page_path(nested_url)
}
end
end
end
end
Expand Up @@ -16,7 +16,7 @@
<%= f.label :layout_template, t('.layout_template') %>
<%= refinery_help_tag t('.layout_template_help') %>
</span>
<%= f.select :layout_template, @valid_layout_templates,
<%= f.select :layout_template, valid_layout_templates,
template_options(:layout_template, @page) %>
</div>
<% end %>
Expand All @@ -25,7 +25,7 @@
<%= f.label :view_template, t('.view_template') %>
<%= refinery_help_tag t('.view_template_help') %>
</span>
<%= f.select :view_template, @valid_view_templates.map { |t| [t.titleize, t] },
<%= f.select :view_template, valid_view_templates.map { |t| [t.titleize, t] },
template_options(:view_template, @page) %>
</div>

Expand Down

0 comments on commit 3601775

Please sign in to comment.