Fix parent menu item preselection of grand children of a wiki page

pull/501/head
Till Breuer 11 years ago committed by Jens Ulferts
parent 6d4f323132
commit eee1e04bb0
  1. 7
      app/controllers/wiki_menu_items_controller.rb
  2. 16
      app/models/wiki_page.rb
  3. 2
      app/views/wiki_menu_items/edit.html.erb

@ -96,10 +96,11 @@ class WikiMenuItemsController < ApplicationController
possible_parent_menu_items = WikiMenuItem.main_items(@page.wiki.id) - [@wiki_menu_item]
@parent_menu_item_options = possible_parent_menu_items.map {|item| [item.name, item.id]}
@selected_parent_menu_item = if @wiki_menu_item.parent
@selected_parent_menu_item_id = if @wiki_menu_item.parent
@wiki_menu_item.parent.id
elsif @page.parent && menu_item_of_parent_page = possible_parent_menu_items.detect {|item| item.title == @page.parent.title}
menu_item_of_parent_page.id
else
@page.nearest_parent_menu_item(:is_main_item => true).try :id
end
end
end

@ -209,10 +209,20 @@ class WikiPage < ActiveRecord::Base
def nearest_menu_item
if self.menu_item
self.menu_item
elsif self.parent
self.parent.nearest_menu_item
else
nil
nearest_parent_menu_item
end
end
def nearest_parent_menu_item(options={})
return nil unless self.parent
options = options.with_indifferent_access
if (parent_menu_item = self.parent.menu_item) && (!options[:is_main_item] || parent_menu_item.is_main_item?)
parent_menu_item
else
self.parent.nearest_parent_menu_item
end
end

@ -65,7 +65,7 @@ See doc/COPYRIGHT.rdoc for more details.
<% disabled = @parent_menu_item_options.empty? %>
<%= form.radio_button 'setting', :sub_item, :disabled => disabled %>
<%= form.label 'setting_sub_item', l(:label_wiki_show_submenu_item), {:id => 'with-select'} %>
<%= select_tag "parent_wiki_menu_item", options_for_select(@parent_menu_item_options, @selected_parent_menu_item), :disabled => disabled %>
<%= select_tag "parent_wiki_menu_item", options_for_select(@parent_menu_item_options, @selected_parent_menu_item_id), :disabled => disabled %>
</p>
</fieldset>
<p>

Loading…
Cancel
Save