]> source.dussan.org Git - redmine.git/commitdiff
Fixed: empty list for user/version custom fields on bulk edit form (#2096).
authorJean-Philippe Lang <jp_lang@yahoo.fr>
Thu, 7 Apr 2011 16:34:58 +0000 (16:34 +0000)
committerJean-Philippe Lang <jp_lang@yahoo.fr>
Thu, 7 Apr 2011 16:34:58 +0000 (16:34 +0000)
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@5354 e93f8b46-1217-0410-a6f0-8f06a7374b81

app/helpers/custom_fields_helper.rb
app/models/custom_field.rb
app/views/issues/bulk_edit.rhtml
app/views/timelog/bulk_edit.rhtml
test/functional/issues_controller_test.rb
test/unit/custom_field_user_format_test.rb

index 36f665e185dfe4221de4f07c2c888f8aece2cd8f..0f7a5a13522bac0fd8d6e0cc35ad3514086b46da 100644 (file)
@@ -68,7 +68,7 @@ module CustomFieldsHelper
     custom_field_label_tag(name, custom_value) + custom_field_tag(name, custom_value)
   end
   
-  def custom_field_tag_for_bulk_edit(name, custom_field)
+  def custom_field_tag_for_bulk_edit(name, custom_field, projects)
     field_name = "#{name}[custom_field_values][#{custom_field.id}]"
     field_id = "#{name}_custom_field_values_#{custom_field.id}"
     field_format = Redmine::CustomFieldFormat.find_by_name(custom_field.field_format)
@@ -83,7 +83,7 @@ module CustomFieldsHelper
                                                    [l(:general_text_yes), '1'],
                                                    [l(:general_text_no), '0']]), :id => field_id)
       when "list"
-        select_tag(field_name, options_for_select([[l(:label_no_change_option), '']] + custom_field.possible_values_options), :id => field_id)
+        select_tag(field_name, options_for_select([[l(:label_no_change_option), '']] + custom_field.possible_values_options(projects)), :id => field_id)
       else
         text_field_tag(field_name, '', :id => field_id)
     end
index a09674df01745e1acb47f4e290cba0084c6975ec..0e8151ee0cfd0bfa0a314cb7096e5df3f87475a0 100644 (file)
@@ -58,6 +58,8 @@ class CustomField < ActiveRecord::Base
         when 'version'
           obj.project.versions.sort.collect {|u| [u.to_s, u.id.to_s]}
         end
+      elsif obj.is_a?(Array)
+        obj.collect {|o| possible_values_options(o)}.inject {|memo, v| memo & v}
       else
         []
       end
index 35ee17307ad268e8f037ce8eccdaa30174ceb5a2..71b30ddacb289514f7a8f71cba143e86992daeff 100644 (file)
@@ -48,7 +48,7 @@
 <% end %>
 
 <% @custom_fields.each do |custom_field| %>
-       <p><label><%= h(custom_field.name) %></label> <%= custom_field_tag_for_bulk_edit('issue', custom_field) %></p>
+       <p><label><%= h(custom_field.name) %></label> <%= custom_field_tag_for_bulk_edit('issue', custom_field, @projects) %></p>
 <% end %>
 
 <%= call_hook(:view_issues_bulk_edit_details_bottom, { :issues => @issues }) %>
index 3045e2569a7c0864ba8e2c474241727e0eb887f7..a93e39238de3242d378578dbd941b121efdb21cf 100644 (file)
@@ -36,7 +36,7 @@
     </p>
 
     <% @custom_fields.each do |custom_field| %>
-      <p><label><%= h(custom_field.name) %></label> <%= custom_field_tag_for_bulk_edit('time_entry', custom_field) %></p>
+      <p><label><%= h(custom_field.name) %></label> <%= custom_field_tag_for_bulk_edit('time_entry', custom_field, @projects) %></p>
     <% end %>
 
     <%= call_hook(:view_time_entries_bulk_edit_details_bottom, { :time_entries => @time_entries }) %>
index 4c6e33266e49688ed70b0d692a85e12dee772e8f..31132eba0626c07aba67478860dd83a72e43966c 100644 (file)
@@ -1,5 +1,5 @@
 # Redmine - project management software
-# Copyright (C) 2006-2008  Jean-Philippe Lang
+# Copyright (C) 2006-2011  Jean-Philippe Lang
 #
 # This program is free software; you can redistribute it and/or
 # modify it under the terms of the GNU General Public License
@@ -1123,6 +1123,38 @@ class IssuesControllerTest < ActionController::TestCase
     assert !field.project_ids.include?(Issue.find(6).project_id)
     assert_no_tag :input, :attributes => {:name => 'issue[custom_field_values][9]'}
   end
+  
+  def test_get_bulk_edit_with_user_custom_field
+    field = IssueCustomField.create!(:name => 'Tester', :field_format => 'user', :is_for_all => true)
+    
+    @request.session[:user_id] = 2
+    get :bulk_edit, :ids => [1, 2]
+    assert_response :success
+    assert_template 'bulk_edit'
+    
+    assert_tag :select,
+      :attributes => {:name => "issue[custom_field_values][#{field.id}]"},
+      :children => {
+        :only => {:tag => 'option'},
+        :count => Project.find(1).users.count + 1
+      }
+  end
+  
+  def test_get_bulk_edit_with_version_custom_field
+    field = IssueCustomField.create!(:name => 'Affected version', :field_format => 'version', :is_for_all => true)
+    
+    @request.session[:user_id] = 2
+    get :bulk_edit, :ids => [1, 2]
+    assert_response :success
+    assert_template 'bulk_edit'
+    
+    assert_tag :select,
+      :attributes => {:name => "issue[custom_field_values][#{field.id}]"},
+      :children => {
+        :only => {:tag => 'option'},
+        :count => Project.find(1).versions.count + 1
+      }
+  end
 
   def test_bulk_update
     @request.session[:user_id] = 2
index 5cc4ea5c16e23da6db4e573273dfa1c736e74fa9..8cac3009f39e10b2bb2b8be33920caffe47de698 100644 (file)
@@ -53,6 +53,13 @@ class CustomFieldUserFormatTest < ActiveSupport::TestCase
     assert_equal project.users.sort.map {|u| [u.name, u.id.to_s]}, possible_values_options
   end
   
+  def test_possible_values_options_with_array
+    projects = Project.find([1, 2])
+    possible_values_options = @field.possible_values_options(projects)
+    assert possible_values_options.any?
+    assert_equal (projects.first.users & projects.last.users).sort.map {|u| [u.name, u.id.to_s]}, possible_values_options
+  end
+  
   def test_cast_blank_value
     assert_equal nil, @field.cast_value(nil)
     assert_equal nil, @field.cast_value("")