summaryrefslogtreecommitdiffstats
path: root/app/helpers
diff options
context:
space:
mode:
authorJean-Philippe Lang <jp_lang@yahoo.fr>2013-05-04 15:03:07 +0000
committerJean-Philippe Lang <jp_lang@yahoo.fr>2013-05-04 15:03:07 +0000
commit70bdb86c534f2acb074f48ddac3070eaf9a9e3d1 (patch)
tree420ec435fc92bd849036028d03249ef6d172bc31 /app/helpers
parent1269e6c7d3f5e067f4a77d78b66a8149255dd00a (diff)
downloadredmine-70bdb86c534f2acb074f48ddac3070eaf9a9e3d1.tar.gz
redmine-70bdb86c534f2acb074f48ddac3070eaf9a9e3d1.zip
Preserve field values on bulk edit failure (#13943).
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@11787 e93f8b46-1217-0410-a6f0-8f06a7374b81
Diffstat (limited to 'app/helpers')
-rw-r--r--app/helpers/application_helper.rb6
-rw-r--r--app/helpers/custom_fields_helper.rb12
-rw-r--r--app/helpers/projects_helper.rb5
3 files changed, 14 insertions, 9 deletions
diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb
index 148780df9..215579180 100644
--- a/app/helpers/application_helper.rb
+++ b/app/helpers/application_helper.rb
@@ -330,7 +330,7 @@ module ApplicationHelper
end
groups = ''
collection.sort.each do |element|
- selected_attribute = ' selected="selected"' if option_value_selected?(element, selected)
+ selected_attribute = ' selected="selected"' if option_value_selected?(element, selected) || element.id.to_s == selected
(element.is_a?(Group) ? groups : s) << %(<option value="#{element.id}"#{selected_attribute}>#{h element.name}</option>)
end
unless groups.empty?
@@ -348,6 +348,10 @@ module ApplicationHelper
options
end
+ def option_tag(name, text, value, selected=nil, options={})
+ content_tag 'option', value, options.merge(:value => value, :selected => (value == selected))
+ end
+
# Truncates and returns the string as a single line
def truncate_single_line(string, *args)
truncate(string.to_s, *args).gsub(%r{[\r\n]+}m, ' ')
diff --git a/app/helpers/custom_fields_helper.rb b/app/helpers/custom_fields_helper.rb
index 803dbb6d3..80a3eecd7 100644
--- a/app/helpers/custom_fields_helper.rb
+++ b/app/helpers/custom_fields_helper.rb
@@ -77,7 +77,7 @@ module CustomFieldsHelper
custom_field_label_tag(name, custom_value, options) + custom_field_tag(name, custom_value)
end
- def custom_field_tag_for_bulk_edit(name, custom_field, projects=nil)
+ def custom_field_tag_for_bulk_edit(name, custom_field, projects=nil, value=nil)
field_name = "#{name}[custom_field_values][#{custom_field.id}]"
field_name << "[]" if custom_field.multiple?
field_id = "#{name}_custom_field_values_#{custom_field.id}"
@@ -87,22 +87,22 @@ module CustomFieldsHelper
field_format = Redmine::CustomFieldFormat.find_by_name(custom_field.field_format)
case field_format.try(:edit_as)
when "date"
- text_field_tag(field_name, '', tag_options.merge(:size => 10)) +
+ text_field_tag(field_name, value, tag_options.merge(:size => 10)) +
calendar_for(field_id)
when "text"
- text_area_tag(field_name, '', tag_options.merge(:rows => 3))
+ text_area_tag(field_name, value, tag_options.merge(:rows => 3))
when "bool"
select_tag(field_name, options_for_select([[l(:label_no_change_option), ''],
[l(:general_text_yes), '1'],
- [l(:general_text_no), '0']]), tag_options)
+ [l(:general_text_no), '0']], value), tag_options)
when "list"
options = []
options << [l(:label_no_change_option), ''] unless custom_field.multiple?
options << [l(:label_none), '__none__'] unless custom_field.is_required?
options += custom_field.possible_values_options(projects)
- select_tag(field_name, options_for_select(options), tag_options.merge(:multiple => custom_field.multiple?))
+ select_tag(field_name, options_for_select(options, value), tag_options.merge(:multiple => custom_field.multiple?))
else
- text_field_tag(field_name, '', tag_options)
+ text_field_tag(field_name, value, tag_options)
end
end
diff --git a/app/helpers/projects_helper.rb b/app/helpers/projects_helper.rb
index 33e51b8a4..4ec54d8dd 100644
--- a/app/helpers/projects_helper.rb
+++ b/app/helpers/projects_helper.rb
@@ -69,10 +69,11 @@ module ProjectsHelper
grouped[version.project.name] << [version.name, version.id]
end
+ selected = selected.is_a?(Version) ? selected.id : selected
if grouped.keys.size > 1
- grouped_options_for_select(grouped, selected && selected.id)
+ grouped_options_for_select(grouped, selected)
else
- options_for_select((grouped.values.first || []), selected && selected.id)
+ options_for_select((grouped.values.first || []), selected)
end
end