diff options
author | Eric Davis <edavis@littlestreamsoftware.com> | 2010-02-18 05:01:39 +0000 |
---|---|---|
committer | Eric Davis <edavis@littlestreamsoftware.com> | 2010-02-18 05:01:39 +0000 |
commit | 28e9bc5d823e4b5ed7585feaa8afdd11446ac754 (patch) | |
tree | ceee0db8e154ee141f18820cf22110daf580c770 /lib | |
parent | 0fcc436f226fd58e9463ccc92ad488b4630d14f4 (diff) | |
download | redmine-28e9bc5d823e4b5ed7585feaa8afdd11446ac754.tar.gz redmine-28e9bc5d823e4b5ed7585feaa8afdd11446ac754.zip |
Fix an IndexError if all the :last menu items are deleted from a menu. #4718
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@3447 e93f8b46-1217-0410-a6f0-8f06a7374b81
Diffstat (limited to 'lib')
-rw-r--r-- | lib/redmine/menu_manager.rb | 13 |
1 files changed, 11 insertions, 2 deletions
diff --git a/lib/redmine/menu_manager.rb b/lib/redmine/menu_manager.rb index af7d67b77..34cea79fa 100644 --- a/lib/redmine/menu_manager.rb +++ b/lib/redmine/menu_manager.rb @@ -84,6 +84,14 @@ module TreeNodePatch end + # Wrapp remove! making sure to decrement the last_items counter if + # the removed child was a last item + def remove!(child) + @last_items_count -= +1 if child && child.last + super + end + + # Will return the position (zero-based) of the current child in # it's parent def position @@ -352,7 +360,7 @@ module Redmine target_root.add(MenuItem.new(name, url, options)) end - elsif options.delete(:last) + elsif options[:last] # don't delete, needs to be stored target_root.add_last(MenuItem.new(name, url, options)) else target_root.add(MenuItem.new(name, url, options)) @@ -386,7 +394,7 @@ module Redmine class MenuItem < Tree::TreeNode include Redmine::I18n - attr_reader :name, :url, :param, :condition, :parent, :child_menus + attr_reader :name, :url, :param, :condition, :parent, :child_menus, :last def initialize(name, url, options) raise ArgumentError, "Invalid option :if for menu item '#{name}'" if options[:if] && !options[:if].respond_to?(:call) @@ -403,6 +411,7 @@ module Redmine @html_options[:class] = [@html_options[:class], @name.to_s.dasherize].compact.join(' ') @parent = options[:parent] @child_menus = options[:children] + @last = options[:last] || false super @name.to_sym end |