diff --git a/app/views/helpers/redmine_category_tree/issue_category_helper.rb b/app/views/helpers/redmine_category_tree/issue_category_helper.rb index c0cc69a..a5c5736 100644 --- a/app/views/helpers/redmine_category_tree/issue_category_helper.rb +++ b/app/views/helpers/redmine_category_tree/issue_category_helper.rb @@ -2,7 +2,7 @@ module RedmineCategoryTree module IssueCategoryHelper def issue_category_tree_options_for_select(issue_categories, options={}) s = '' - issue_category_tree(issue_categories) do |category, level| + issue_category_tree(issue_categories, true) do |category, level| if category.nil? || category.id.nil? next end @@ -22,15 +22,61 @@ def issue_category_tree_options_for_select(issue_categories, options={}) if !options[:current].nil? && options[:current].id == category.id tag_options[:disabled] = 'disabled' end - - tag_options.merge!(yield(category)) if block_given? + + tag_options.merge!(yield(category)) if block_given? s << content_tag('option', name_prefix + h(category), tag_options) + end s.html_safe end - def issue_category_tree(issue_categories, &block) - IssueCategory.issue_category_tree(issue_categories, &block) + def issue_category_tree(issue_categories, ignore_disabled = false, &block) + + if ignore_disabled + + cats = [] + levels = [] + + cur_disabled_levels = [] + IssueCategory.issue_category_tree(issue_categories) do |category, level| + + # Child levels no longer matter if we moved up + while !cur_disabled_levels.empty? && cur_disabled_levels.last >= level + cur_disabled_levels.pop + end + + has_disabled_parent_cat = !cur_disabled_levels.empty? && cur_disabled_levels.min < level + disabled_at_current_level = !cur_disabled_levels.empty? && cur_disabled_levels.last == level + current_cat_disabled = category.archived || has_disabled_parent_cat + + # If archived here, current disabled level + if category.archived + cur_disabled_levels.push level + # Pop current level if reached again, but honor setting from parent for this one + elsif disabled_at_current_level + while !cur_disabled_levels.empty? && cur_disabled_levels.last == level + cur_disabled_levels.pop + end + end + + if !current_cat_disabled + cats.push category + levels.push level + end + + end + + if !cats.nil? + # How to make a normal for loop?? => for(int i = 0; i < cats.size(); ++i) { ... } ??? + len = cats.size - 1 + (0..len).each do |i| + yield cats[i], levels[i] + end + end + return cats + else + IssueCategory.issue_category_tree(issue_categories, &block) + end end def render_issue_category_tree_list(categories, includeOuterUL=false, &block) @@ -67,14 +113,14 @@ def render_issue_category_tree_list(categories, includeOuterUL=false, &block) end def render_issue_category_tree_context_menu_list(categories, includeOuterUL=false, &block) - categories = issue_category_tree(categories) { |cat, level| nil } + categories = issue_category_tree(categories, true) { |cat, level| nil } return '' if categories.size == 0 output = '' output << '
+ <% if @copy %> + <%= hidden_field_tag 'copy', '1' %> + <%= submit_tag l(:button_copy) %> + <%= submit_tag l(:button_copy_and_follow), :name => 'follow' %> + <% elsif @target_project %> + <%= submit_tag l(:button_move) %> + <%= submit_tag l(:button_move_and_follow), :name => 'follow' %> + <% else %> + <%= submit_tag l(:button_submit) %> + <% end %> +
+ +<% end %> + +<%= javascript_tag do %> +$(window).load(function(){ + $(document).on('change', 'input[data-disables]', function(){ + if ($(this).attr('checked')){ + $($(this).data('disables')).attr('disabled', true).val(''); + } else { + $($(this).data('disables')).attr('disabled', false); + } + }); +}); +$(document).ready(function(){ + $('input[data-disables]').trigger('change'); +}); +<% end %> diff --git a/app/views/projects/settings/_issue_categories.html.erb b/app/views/projects/settings/_issue_categories.html.erb index 81f0da0..cd49f74 100644 --- a/app/views/projects/settings/_issue_categories.html.erb +++ b/app/views/projects/settings/_issue_categories.html.erb @@ -38,6 +38,8 @@