dropdowns for pages/layouts are properly scoped under sites
Oleg
committed Oct 19, 2010
commit 4354f8ff741dfaf8cd2c13dbfa0f46b628d155e1
Showing 6
changed files with
16 additions
and 16 deletions
app/models/cms_layout.rb
+3
-3
| @@ | @@ -13,13 +13,13 @@ class CmsLayout < ActiveRecord::Base |
| # -- Class Methods -------------------------------------------------------- | |
| # Tree-like structure for layouts | |
| - | def self.options_for_select(cms_layout = nil, current_layout = nil, depth = 0, spacer = '. . ') |
| + | def self.options_for_select(cms_site, cms_layout = nil, current_layout = nil, depth = 0, spacer = '. . ') |
| out = [] | |
| - | [current_layout || CmsLayout.roots].flatten.each do |layout| |
| + | [current_layout || cms_site.cms_layouts.roots].flatten.each do |layout| |
| next if cms_layout == layout | |
| out << [ "#{spacer*depth}#{layout.label}", layout.id ] | |
| layout.children.each do |child| | |
| - | out += options_for_select(cms_layout, child, depth + 1, spacer) |
| + | out += options_for_select(cms_site, cms_layout, child, depth + 1, spacer) |
| end | |
| end | |
| return out.compact | |
app/models/cms_page.rb
+3
-3
| @@ | @@ -33,11 +33,11 @@ class CmsPage < ActiveRecord::Base |
| # -- Class Methods -------------------------------------------------------- | |
| # Tree-like structure for pages | |
| - | def self.options_for_select(cms_page = nil, current_page = nil, depth = 0, spacer = '. . ') |
| - | return [] if (current_page ||= CmsPage.root) == cms_page || !current_page |
| + | def self.options_for_select(cms_site, cms_page = nil, current_page = nil, depth = 0, spacer = '. . ') |
| + | return [] if (current_page ||= cms_site.cms_pages.root) == cms_page || !current_page |
| out = [[ "#{spacer*depth}#{current_page.label}", current_page.id ]] | |
| current_page.children.each do |child| | |
| - | out += options_for_select(cms_page, child, depth + 1, spacer) |
| + | out += options_for_select(cms_site, cms_page, child, depth + 1, spacer) |
| end | |
| return out.compact | |
| end | |
app/views/cms_admin/layouts/_form.html.erb
+1
-1
| @@ | @@ -1,5 +1,5 @@ |
| <%= form.text_field :label, :label => 'Layout Name' %> | |
| - | <%= form.select :parent_id, CmsLayout.options_for_select(@cms_layout), :include_blank => true %> |
| + | <%= form.select :parent_id, CmsLayout.options_for_select(@cms_site, @cms_layout), :include_blank => true %> |
| <%= form.select :app_layout, CmsLayout.app_layouts_for_select, :include_blank => true %> | |
| <%= form.text_area :content %> | |
| <%= form.text_area :css %> | |
app/views/cms_admin/pages/_form.html.erb
+2
-2
| @@ | @@ -2,8 +2,8 @@ |
| <div class='page_form_extras'> | |
| <%= form.text_field :slug, :id => 'slug' %> | |
| - | <%= form.select :cms_layout_id, CmsLayout.options_for_select, {}, 'data-page-id' => @cms_page.id.to_i, :label => 'Layout' %> |
| - | <%= form.select :parent_id, CmsPage.options_for_select(@cms_page) %> |
| + | <%= form.select :cms_layout_id, CmsLayout.options_for_select(@cms_site), {}, 'data-page-id' => @cms_page.id.to_i, :label => 'Layout' %> |
| + | <%= form.select :parent_id, CmsPage.options_for_select(@cms_site, @cms_page) %> |
| </div> | |
| <%= render :partial => 'form_blocks' %> | |
test/unit/cms_layout_test.rb
+3
-3
| @@ | @@ -15,9 +15,9 @@ class CmsLayoutTest < ActiveSupport::TestCase |
| end | |
| def test_options_for_select | |
| - | assert_equal ['Default Layout', 'Nested Layout', '. . Child Layout'], CmsLayout.options_for_select.collect{|t| t.first} |
| - | assert_equal ['Default Layout', 'Nested Layout'], CmsLayout.options_for_select(cms_layouts(:child)).collect{|t| t.first} |
| - | assert_equal ['Default Layout'], CmsLayout.options_for_select(cms_layouts(:nested)).collect{|t| t.first} |
| + | assert_equal ['Default Layout', 'Nested Layout', '. . Child Layout'], CmsLayout.options_for_select(cms_sites(:default)).collect{|t| t.first} |
| + | assert_equal ['Default Layout', 'Nested Layout'], CmsLayout.options_for_select(cms_sites(:default), cms_layouts(:child)).collect{|t| t.first} |
| + | assert_equal ['Default Layout'], CmsLayout.options_for_select(cms_sites(:default), cms_layouts(:nested)).collect{|t| t.first} |
| end | |
| def test_app_layouts_for_select | |
test/unit/cms_page_test.rb
+4
-4
| @@ | @@ -102,12 +102,12 @@ class CmsPageTest < ActiveSupport::TestCase |
| end | |
| def test_options_for_select | |
| - | assert_equal ['Default Page', '. . Child Page'], CmsPage.options_for_select.collect{|t| t.first } |
| - | assert_equal ['Default Page'], CmsPage.options_for_select(cms_pages(:child)).collect{|t| t.first } |
| - | assert_equal [], CmsPage.options_for_select(cms_pages(:default)) |
| + | assert_equal ['Default Page', '. . Child Page'], CmsPage.options_for_select(cms_sites(:default)).collect{|t| t.first } |
| + | assert_equal ['Default Page'], CmsPage.options_for_select(cms_sites(:default), cms_pages(:child)).collect{|t| t.first } |
| + | assert_equal [], CmsPage.options_for_select(cms_sites(:default), cms_pages(:default)) |
| page = CmsPage.new(new_params(:parent => cms_pages(:default))) | |
| - | assert_equal ['Default Page', '. . Child Page'], CmsPage.options_for_select(page).collect{|t| t.first } |
| + | assert_equal ['Default Page', '. . Child Page'], CmsPage.options_for_select(cms_sites(:default), page).collect{|t| t.first } |
| end | |
| protected | |