comparison app/helpers/custom_fields_helper.rb @ 441:cbce1fd3b1b7 redmine-1.2

Update to Redmine 1.2-stable branch (Redmine SVN rev 6000)
author Chris Cannam
date Mon, 06 Jun 2011 14:24:13 +0100
parents 8661b858af72
children cbb26bc654de
comparison
equal deleted inserted replaced
245:051f544170fe 441:cbce1fd3b1b7
1 # redMine - project management software 1 # Redmine - project management software
2 # Copyright (C) 2006 Jean-Philippe Lang 2 # Copyright (C) 2006-2011 Jean-Philippe Lang
3 # 3 #
4 # This program is free software; you can redistribute it and/or 4 # This program is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU General Public License 5 # modify it under the terms of the GNU General Public License
6 # as published by the Free Software Foundation; either version 2 6 # as published by the Free Software Foundation; either version 2
7 # of the License, or (at your option) any later version. 7 # of the License, or (at your option) any later version.
35 custom_field = custom_value.custom_field 35 custom_field = custom_value.custom_field
36 field_name = "#{name}[custom_field_values][#{custom_field.id}]" 36 field_name = "#{name}[custom_field_values][#{custom_field.id}]"
37 field_id = "#{name}_custom_field_values_#{custom_field.id}" 37 field_id = "#{name}_custom_field_values_#{custom_field.id}"
38 38
39 field_format = Redmine::CustomFieldFormat.find_by_name(custom_field.field_format) 39 field_format = Redmine::CustomFieldFormat.find_by_name(custom_field.field_format)
40 case field_format.edit_as 40 case field_format.try(:edit_as)
41 when "date" 41 when "date"
42 text_field_tag(field_name, custom_value.value, :id => field_id, :size => 10) + 42 text_field_tag(field_name, custom_value.value, :id => field_id, :size => 10) +
43 calendar_for(field_id) 43 calendar_for(field_id)
44 when "text" 44 when "text"
45 text_area_tag(field_name, custom_value.value, :id => field_id, :rows => 3, :style => 'width:90%') 45 text_area_tag(field_name, custom_value.value, :id => field_id, :rows => 3, :style => 'width:90%')
47 hidden_field_tag(field_name, '0') + check_box_tag(field_name, '1', custom_value.true?, :id => field_id) 47 hidden_field_tag(field_name, '0') + check_box_tag(field_name, '1', custom_value.true?, :id => field_id)
48 when "list" 48 when "list"
49 blank_option = custom_field.is_required? ? 49 blank_option = custom_field.is_required? ?
50 (custom_field.default_value.blank? ? "<option value=\"\">--- #{l(:actionview_instancetag_blank_option)} ---</option>" : '') : 50 (custom_field.default_value.blank? ? "<option value=\"\">--- #{l(:actionview_instancetag_blank_option)} ---</option>" : '') :
51 '<option></option>' 51 '<option></option>'
52 select_tag(field_name, blank_option + options_for_select(custom_field.possible_values, custom_value.value), :id => field_id) 52 select_tag(field_name, blank_option + options_for_select(custom_field.possible_values_options(custom_value.customized), custom_value.value), :id => field_id)
53 else 53 else
54 text_field_tag(field_name, custom_value.value, :id => field_id) 54 text_field_tag(field_name, custom_value.value, :id => field_id)
55 end 55 end
56 end 56 end
57 57
66 # Return custom field tag with its label tag 66 # Return custom field tag with its label tag
67 def custom_field_tag_with_label(name, custom_value) 67 def custom_field_tag_with_label(name, custom_value)
68 custom_field_label_tag(name, custom_value) + custom_field_tag(name, custom_value) 68 custom_field_label_tag(name, custom_value) + custom_field_tag(name, custom_value)
69 end 69 end
70 70
71 def custom_field_tag_for_bulk_edit(name, custom_field) 71 def custom_field_tag_for_bulk_edit(name, custom_field, projects=nil)
72 field_name = "#{name}[custom_field_values][#{custom_field.id}]" 72 field_name = "#{name}[custom_field_values][#{custom_field.id}]"
73 field_id = "#{name}_custom_field_values_#{custom_field.id}" 73 field_id = "#{name}_custom_field_values_#{custom_field.id}"
74 field_format = Redmine::CustomFieldFormat.find_by_name(custom_field.field_format) 74 field_format = Redmine::CustomFieldFormat.find_by_name(custom_field.field_format)
75 case field_format.edit_as 75 case field_format.try(:edit_as)
76 when "date" 76 when "date"
77 text_field_tag(field_name, '', :id => field_id, :size => 10) + 77 text_field_tag(field_name, '', :id => field_id, :size => 10) +
78 calendar_for(field_id) 78 calendar_for(field_id)
79 when "text" 79 when "text"
80 text_area_tag(field_name, '', :id => field_id, :rows => 3, :style => 'width:90%') 80 text_area_tag(field_name, '', :id => field_id, :rows => 3, :style => 'width:90%')
81 when "bool" 81 when "bool"
82 select_tag(field_name, options_for_select([[l(:label_no_change_option), ''], 82 select_tag(field_name, options_for_select([[l(:label_no_change_option), ''],
83 [l(:general_text_yes), '1'], 83 [l(:general_text_yes), '1'],
84 [l(:general_text_no), '0']]), :id => field_id) 84 [l(:general_text_no), '0']]), :id => field_id)
85 when "list" 85 when "list"
86 select_tag(field_name, options_for_select([[l(:label_no_change_option), '']] + custom_field.possible_values), :id => field_id) 86 select_tag(field_name, options_for_select([[l(:label_no_change_option), '']] + custom_field.possible_values_options(projects)), :id => field_id)
87 else 87 else
88 text_field_tag(field_name, '', :id => field_id) 88 text_field_tag(field_name, '', :id => field_id)
89 end 89 end
90 end 90 end
91 91
99 def format_value(value, field_format) 99 def format_value(value, field_format)
100 Redmine::CustomFieldFormat.format_value(value, field_format) # Proxy 100 Redmine::CustomFieldFormat.format_value(value, field_format) # Proxy
101 end 101 end
102 102
103 # Return an array of custom field formats which can be used in select_tag 103 # Return an array of custom field formats which can be used in select_tag
104 def custom_field_formats_for_select 104 def custom_field_formats_for_select(custom_field)
105 Redmine::CustomFieldFormat.as_select 105 Redmine::CustomFieldFormat.as_select(custom_field.class.customized_class.name)
106 end 106 end
107 107
108 # Renders the custom_values in api views 108 # Renders the custom_values in api views
109 def render_api_custom_values(custom_values, api) 109 def render_api_custom_values(custom_values, api)
110 api.array :custom_fields do 110 api.array :custom_fields do