Skip to content

Commit

Permalink
fix default template selected
Browse files Browse the repository at this point in the history
  • Loading branch information
ghoppe authored and ugisozols committed May 30, 2012
1 parent 1aa4065 commit 807c44b
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 10 deletions.
14 changes: 14 additions & 0 deletions pages/app/helpers/refinery/admin/pages_helper.rb
Expand Up @@ -10,6 +10,20 @@ def parent_id_nested_set_options(current_page)
ActiveRecord::Associations::Preloader.new(pages, :translations).run
pages.map {|page| ["#{'-' * page.level} #{page.title}", page.id]}
end
def selected_template(template_type, current_page)
if current_page.send(template_type).nil? then
if current_page.parent_id? then
# Use Parent Template by default.
current_page.parent.send(template_type)
else
# Use Default Template (First in whitelist)
Refinery::Pages.send("#{template_type}_whitelist").first
end
else
# Use Selected Template in Page
current_page.send(template_type)
end
end
end
end
end
Expand Up @@ -26,11 +26,7 @@
<%= f.label :layout_template, t('.layout_template') %>
<%= refinery_help_tag t('.layout_template_help') %>
</span>
<% if @page.parent_id? %>
<%= f.select(:layout_template, @valid_layout_templates, {:selected => @page.parent.layout_template}) %>
<% else %>
<%= f.select(:layout_template, @valid_layout_templates) %>
<% end %>
<%= f.select(:layout_template, @valid_layout_templates, {:selected => selected_template(:layout_template, current_page)}) %>
</div>
<% end %>
<% if Refinery::Pages.use_view_templates %>
Expand All @@ -39,11 +35,7 @@
<%= f.label :view_template, t('.view_template') %>
<%= refinery_help_tag t('.view_template_help') %>
</span>
<% if @page.parent_id? %>
<%= f.select(:view_template, @valid_view_templates.map{|t| [t.titleize, t]}, {:selected => @page.parent.view_template }) %>
<% else %>
<%= f.select(:view_template, @valid_view_templates.map{|t| [t.titleize, t]}) %>
<% end %>
<%= f.select(:view_template, @valid_view_templates.map{|t| [t.titleize, t]}, {:selected => selected_template(:view_template, current_page) }) %>
</div>
<% end %>

Expand Down

0 comments on commit 807c44b

Please sign in to comment.