@@ -241,6 +241,9 class IssuesController < ApplicationController | |||
|
241 | 241 | end |
|
242 | 242 | |
|
243 | 243 | @safe_attributes = @issues.map(&:safe_attribute_names).reduce(:&) |
|
244 | ||
|
245 | @issue_params = params[:issue] || {} | |
|
246 | @issue_params[:custom_field_values] ||= {} | |
|
244 | 247 | end |
|
245 | 248 | |
|
246 | 249 | def bulk_update |
@@ -330,7 +330,7 module ApplicationHelper | |||
|
330 | 330 | end |
|
331 | 331 | groups = '' |
|
332 | 332 | collection.sort.each do |element| |
|
333 | selected_attribute = ' selected="selected"' if option_value_selected?(element, selected) | |
|
333 | selected_attribute = ' selected="selected"' if option_value_selected?(element, selected) || element.id.to_s == selected | |
|
334 | 334 | (element.is_a?(Group) ? groups : s) << %(<option value="#{element.id}"#{selected_attribute}>#{h element.name}</option>) |
|
335 | 335 | end |
|
336 | 336 | unless groups.empty? |
@@ -348,6 +348,10 module ApplicationHelper | |||
|
348 | 348 | options |
|
349 | 349 | end |
|
350 | 350 | |
|
351 | def option_tag(name, text, value, selected=nil, options={}) | |
|
352 | content_tag 'option', value, options.merge(:value => value, :selected => (value == selected)) | |
|
353 | end | |
|
354 | ||
|
351 | 355 | # Truncates and returns the string as a single line |
|
352 | 356 | def truncate_single_line(string, *args) |
|
353 | 357 | truncate(string.to_s, *args).gsub(%r{[\r\n]+}m, ' ') |
@@ -77,7 +77,7 module CustomFieldsHelper | |||
|
77 | 77 | custom_field_label_tag(name, custom_value, options) + custom_field_tag(name, custom_value) |
|
78 | 78 | end |
|
79 | 79 | |
|
80 | def custom_field_tag_for_bulk_edit(name, custom_field, projects=nil) | |
|
80 | def custom_field_tag_for_bulk_edit(name, custom_field, projects=nil, value=nil) | |
|
81 | 81 | field_name = "#{name}[custom_field_values][#{custom_field.id}]" |
|
82 | 82 | field_name << "[]" if custom_field.multiple? |
|
83 | 83 | field_id = "#{name}_custom_field_values_#{custom_field.id}" |
@@ -87,22 +87,22 module CustomFieldsHelper | |||
|
87 | 87 | field_format = Redmine::CustomFieldFormat.find_by_name(custom_field.field_format) |
|
88 | 88 | case field_format.try(:edit_as) |
|
89 | 89 | when "date" |
|
90 |
text_field_tag(field_name, |
|
|
90 | text_field_tag(field_name, value, tag_options.merge(:size => 10)) + | |
|
91 | 91 | calendar_for(field_id) |
|
92 | 92 | when "text" |
|
93 |
text_area_tag(field_name, |
|
|
93 | text_area_tag(field_name, value, tag_options.merge(:rows => 3)) | |
|
94 | 94 | when "bool" |
|
95 | 95 | select_tag(field_name, options_for_select([[l(:label_no_change_option), ''], |
|
96 | 96 | [l(:general_text_yes), '1'], |
|
97 | [l(:general_text_no), '0']]), tag_options) | |
|
97 | [l(:general_text_no), '0']], value), tag_options) | |
|
98 | 98 | when "list" |
|
99 | 99 | options = [] |
|
100 | 100 | options << [l(:label_no_change_option), ''] unless custom_field.multiple? |
|
101 | 101 | options << [l(:label_none), '__none__'] unless custom_field.is_required? |
|
102 | 102 | options += custom_field.possible_values_options(projects) |
|
103 | select_tag(field_name, options_for_select(options), tag_options.merge(:multiple => custom_field.multiple?)) | |
|
103 | select_tag(field_name, options_for_select(options, value), tag_options.merge(:multiple => custom_field.multiple?)) | |
|
104 | 104 | else |
|
105 |
text_field_tag(field_name, |
|
|
105 | text_field_tag(field_name, value, tag_options) | |
|
106 | 106 | end |
|
107 | 107 | end |
|
108 | 108 |
@@ -69,10 +69,11 module ProjectsHelper | |||
|
69 | 69 | grouped[version.project.name] << [version.name, version.id] |
|
70 | 70 | end |
|
71 | 71 | |
|
72 | selected = selected.is_a?(Version) ? selected.id : selected | |
|
72 | 73 | if grouped.keys.size > 1 |
|
73 |
grouped_options_for_select(grouped, selected |
|
|
74 | grouped_options_for_select(grouped, selected) | |
|
74 | 75 | else |
|
75 |
options_for_select((grouped.values.first || []), selected |
|
|
76 | options_for_select((grouped.values.first || []), selected) | |
|
76 | 77 | end |
|
77 | 78 | end |
|
78 | 79 |
@@ -32,34 +32,43 | |||
|
32 | 32 | <% if @allowed_projects.present? %> |
|
33 | 33 | <p> |
|
34 | 34 | <label for="issue_project_id"><%= l(:field_project) %></label> |
|
35 | <%= select_tag('issue[project_id]', content_tag('option', l(:label_no_change_option), :value => '') + project_tree_options_for_select(@allowed_projects, :selected => @target_project), | |
|
35 | <%= select_tag('issue[project_id]', | |
|
36 | content_tag('option', l(:label_no_change_option), :value => '') + | |
|
37 | project_tree_options_for_select(@allowed_projects, :selected => @target_project), | |
|
36 | 38 | :onchange => "updateBulkEditFrom('#{escape_javascript url_for(:action => 'bulk_edit', :format => 'js')}')") %> |
|
37 | 39 | </p> |
|
38 | 40 | <% end %> |
|
39 | 41 | <p> |
|
40 | 42 | <label for="issue_tracker_id"><%= l(:field_tracker) %></label> |
|
41 | <%= select_tag('issue[tracker_id]', content_tag('option', l(:label_no_change_option), :value => '') + options_from_collection_for_select(@trackers, :id, :name)) %> | |
|
43 | <%= select_tag('issue[tracker_id]', | |
|
44 | content_tag('option', l(:label_no_change_option), :value => '') + | |
|
45 | options_from_collection_for_select(@trackers, :id, :name, @issue_params[:tracker_id])) %> | |
|
42 | 46 | </p> |
|
43 | 47 | <% if @available_statuses.any? %> |
|
44 | 48 | <p> |
|
45 | 49 | <label for='issue_status_id'><%= l(:field_status) %></label> |
|
46 | <%= select_tag('issue[status_id]',content_tag('option', l(:label_no_change_option), :value => '') + options_from_collection_for_select(@available_statuses, :id, :name)) %> | |
|
50 | <%= select_tag('issue[status_id]', | |
|
51 | content_tag('option', l(:label_no_change_option), :value => '') + | |
|
52 | options_from_collection_for_select(@available_statuses, :id, :name, @issue_params[:status_id])) %> | |
|
47 | 53 | </p> |
|
48 | 54 | <% end %> |
|
49 | 55 | |
|
50 | 56 | <% if @safe_attributes.include?('priority_id') -%> |
|
51 | 57 | <p> |
|
52 | 58 | <label for='issue_priority_id'><%= l(:field_priority) %></label> |
|
53 | <%= select_tag('issue[priority_id]', content_tag('option', l(:label_no_change_option), :value => '') + options_from_collection_for_select(IssuePriority.active, :id, :name)) %> | |
|
59 | <%= select_tag('issue[priority_id]', | |
|
60 | content_tag('option', l(:label_no_change_option), :value => '') + | |
|
61 | options_from_collection_for_select(IssuePriority.active, :id, :name, @issue_params[:priority_id])) %> | |
|
54 | 62 | </p> |
|
55 | 63 | <% end %> |
|
56 | 64 | |
|
57 | 65 | <% if @safe_attributes.include?('assigned_to_id') -%> |
|
58 | 66 | <p> |
|
59 | 67 | <label for='issue_assigned_to_id'><%= l(:field_assigned_to) %></label> |
|
60 | <%= select_tag('issue[assigned_to_id]', content_tag('option', l(:label_no_change_option), :value => '') + | |
|
61 |
|
|
|
62 | principals_options_for_select(@assignables)) %> | |
|
68 | <%= select_tag('issue[assigned_to_id]', | |
|
69 | content_tag('option', l(:label_no_change_option), :value => '') + | |
|
70 | content_tag('option', l(:label_nobody), :value => 'none', :selected => (@issue_params[:assigned_to_id] == 'none')) + | |
|
71 | principals_options_for_select(@assignables, @issue_params[:assigned_to_id])) %> | |
|
63 | 72 | </p> |
|
64 | 73 | <% end %> |
|
65 | 74 | |
@@ -67,8 +76,8 | |||
|
67 | 76 | <p> |
|
68 | 77 | <label for='issue_category_id'><%= l(:field_category) %></label> |
|
69 | 78 | <%= select_tag('issue[category_id]', content_tag('option', l(:label_no_change_option), :value => '') + |
|
70 | content_tag('option', l(:label_none), :value => 'none') + | |
|
71 | options_from_collection_for_select(@categories, :id, :name)) %> | |
|
79 | content_tag('option', l(:label_none), :value => 'none', :selected => (@issue_params[:category_id] == 'none')) + | |
|
80 | options_from_collection_for_select(@categories, :id, :name, @issue_params[:category_id])) %> | |
|
72 | 81 | </p> |
|
73 | 82 | <% end %> |
|
74 | 83 | |
@@ -76,26 +85,31 | |||
|
76 | 85 | <p> |
|
77 | 86 | <label for='issue_fixed_version_id'><%= l(:field_fixed_version) %></label> |
|
78 | 87 | <%= select_tag('issue[fixed_version_id]', content_tag('option', l(:label_no_change_option), :value => '') + |
|
79 | content_tag('option', l(:label_none), :value => 'none') + | |
|
80 | version_options_for_select(@versions.sort)) %> | |
|
88 | content_tag('option', l(:label_none), :value => 'none', :selected => (@issue_params[:fixed_version_id] == 'none')) + | |
|
89 | version_options_for_select(@versions.sort, @issue_params[:fixed_version_id])) %> | |
|
81 | 90 | </p> |
|
82 | 91 | <% end %> |
|
83 | 92 | |
|
84 | 93 | <% @custom_fields.each do |custom_field| %> |
|
85 | <p><label><%= h(custom_field.name) %></label> <%= custom_field_tag_for_bulk_edit('issue', custom_field, @projects) %></p> | |
|
94 | <p> | |
|
95 | <label><%= h(custom_field.name) %></label> | |
|
96 | <%= custom_field_tag_for_bulk_edit('issue', custom_field, @projects, @issue_params[:custom_field_values][custom_field.id.to_s]) %> | |
|
97 | </p> | |
|
86 | 98 | <% end %> |
|
87 | 99 | |
|
88 | 100 | <% if @copy && @attachments_present %> |
|
101 | <%= hidden_field_tag 'copy_attachments', '0' %> | |
|
89 | 102 | <p> |
|
90 | 103 | <label for='copy_attachments'><%= l(:label_copy_attachments) %></label> |
|
91 |
<%= check_box_tag 'copy_attachments', '1', |
|
|
104 | <%= check_box_tag 'copy_attachments', '1', params[:copy_attachments] != '0' %> | |
|
92 | 105 | </p> |
|
93 | 106 | <% end %> |
|
94 | 107 | |
|
95 | 108 | <% if @copy && @subtasks_present %> |
|
109 | <%= hidden_field_tag 'copy_subtasks', '0' %> | |
|
96 | 110 | <p> |
|
97 | 111 | <label for='copy_subtasks'><%= l(:label_copy_subtasks) %></label> |
|
98 |
<%= check_box_tag 'copy_subtasks', '1', |
|
|
112 | <%= check_box_tag 'copy_subtasks', '1', params[:copy_subtasks] != '0' %> | |
|
99 | 113 | </p> |
|
100 | 114 | <% end %> |
|
101 | 115 | |
@@ -107,15 +121,15 | |||
|
107 | 121 | <p> |
|
108 | 122 | <label for='issue_is_private'><%= l(:field_is_private) %></label> |
|
109 | 123 | <%= select_tag('issue[is_private]', content_tag('option', l(:label_no_change_option), :value => '') + |
|
110 | content_tag('option', l(:general_text_Yes), :value => '1') + | |
|
111 | content_tag('option', l(:general_text_No), :value => '0')) %> | |
|
124 | content_tag('option', l(:general_text_Yes), :value => '1', :selected => (@issue_params[:is_private] == '1')) + | |
|
125 | content_tag('option', l(:general_text_No), :value => '0', :selected => (@issue_params[:is_private] == '0'))) %> | |
|
112 | 126 | </p> |
|
113 | 127 | <% end %> |
|
114 | 128 | |
|
115 | 129 | <% if @safe_attributes.include?('parent_issue_id') && @project %> |
|
116 | 130 | <p> |
|
117 | 131 | <label for='issue_parent_issue_id'><%= l(:field_parent_issue) %></label> |
|
118 | <%= text_field_tag 'issue[parent_issue_id]', '', :size => 10 %> | |
|
132 | <%= text_field_tag 'issue[parent_issue_id]', '', :size => 10, :value => @issue_params[:parent_issue_id] %> | |
|
119 | 133 | </p> |
|
120 | 134 | <%= javascript_tag "observeAutocompleteField('issue_parent_issue_id', '#{escape_javascript auto_complete_issues_path(:project_id => @project)}')" %> |
|
121 | 135 | <% end %> |
@@ -123,21 +137,21 | |||
|
123 | 137 | <% if @safe_attributes.include?('start_date') %> |
|
124 | 138 | <p> |
|
125 | 139 | <label for='issue_start_date'><%= l(:field_start_date) %></label> |
|
126 | <%= text_field_tag 'issue[start_date]', '', :size => 10 %><%= calendar_for('issue_start_date') %> | |
|
140 | <%= text_field_tag 'issue[start_date]', '', :value => @issue_params[:start_date], :size => 10 %><%= calendar_for('issue_start_date') %> | |
|
127 | 141 | </p> |
|
128 | 142 | <% end %> |
|
129 | 143 | |
|
130 | 144 | <% if @safe_attributes.include?('due_date') %> |
|
131 | 145 | <p> |
|
132 | 146 | <label for='issue_due_date'><%= l(:field_due_date) %></label> |
|
133 | <%= text_field_tag 'issue[due_date]', '', :size => 10 %><%= calendar_for('issue_due_date') %> | |
|
147 | <%= text_field_tag 'issue[due_date]', '', :value => @issue_params[:due_date], :size => 10 %><%= calendar_for('issue_due_date') %> | |
|
134 | 148 | </p> |
|
135 | 149 | <% end %> |
|
136 | 150 | |
|
137 | 151 | <% if @safe_attributes.include?('done_ratio') && Issue.use_field_for_done_ratio? %> |
|
138 | 152 | <p> |
|
139 | 153 | <label for='issue_done_ratio'><%= l(:field_done_ratio) %></label> |
|
140 | <%= select_tag 'issue[done_ratio]', options_for_select([[l(:label_no_change_option), '']] + (0..10).to_a.collect {|r| ["#{r*10} %", r*10] }) %> | |
|
154 | <%= select_tag 'issue[done_ratio]', options_for_select([[l(:label_no_change_option), '']] + (0..10).to_a.collect {|r| ["#{r*10} %", r*10] }, @issue_params[:done_ratio]) %> | |
|
141 | 155 | </p> |
|
142 | 156 | <% end %> |
|
143 | 157 | </div> |
@@ -3616,6 +3616,18 class IssuesControllerTest < ActionController::TestCase | |||
|
3616 | 3616 | assert_equal [issue1.id, issue2.id], assigns[:issues].map(&:id) |
|
3617 | 3617 | end |
|
3618 | 3618 | |
|
3619 | def test_bulk_update_with_failure_should_preserved_form_values | |
|
3620 | @request.session[:user_id] = 2 | |
|
3621 | post :bulk_update, :ids => [1, 2], :issue => {:tracker_id => '2', :start_date => 'foo'} | |
|
3622 | ||
|
3623 | assert_response :success | |
|
3624 | assert_template 'bulk_edit' | |
|
3625 | assert_select 'select[name=?]', 'issue[tracker_id]' do | |
|
3626 | assert_select 'option[value=2][selected=selected]' | |
|
3627 | end | |
|
3628 | assert_select 'input[name=?][value=?]', 'issue[start_date]', 'foo' | |
|
3629 | end | |
|
3630 | ||
|
3619 | 3631 | def test_get_bulk_copy |
|
3620 | 3632 | @request.session[:user_id] = 2 |
|
3621 | 3633 | get :bulk_edit, :ids => [1, 2, 3], :copy => '1' |
General Comments 0
You need to be logged in to leave comments.
Login now