comparison app/helpers/custom_fields_helper.rb @ 909:cbb26bc654de redmine-1.3

Update to Redmine 1.3-stable branch (Redmine SVN rev 8964)
author Chris Cannam
date Fri, 24 Feb 2012 19:09:32 +0000
parents cbce1fd3b1b7
children 433d4f72a19b
comparison
equal deleted inserted replaced
908:c6c2cbd0afee 909:cbb26bc654de
1 # encoding: utf-8
2 #
1 # Redmine - project management software 3 # Redmine - project management software
2 # Copyright (C) 2006-2011 Jean-Philippe Lang 4 # Copyright (C) 2006-2011 Jean-Philippe Lang
3 # 5 #
4 # This program is free software; you can redistribute it and/or 6 # This program is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU General Public License 7 # modify it under the terms of the GNU General Public License
6 # as published by the Free Software Foundation; either version 2 8 # as published by the Free Software Foundation; either version 2
7 # of the License, or (at your option) any later version. 9 # of the License, or (at your option) any later version.
8 # 10 #
9 # This program is distributed in the hope that it will be useful, 11 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details. 14 # GNU General Public License for more details.
13 # 15 #
14 # You should have received a copy of the GNU General Public License 16 # You should have received a copy of the GNU General Public License
15 # along with this program; if not, write to the Free Software 17 # along with this program; if not, write to the Free Software
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 18 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 19
18 module CustomFieldsHelper 20 module CustomFieldsHelper
27 {:name => 'TimeEntryActivityCustomField', :partial => 'custom_fields/index', :label => TimeEntryActivity::OptionName}, 29 {:name => 'TimeEntryActivityCustomField', :partial => 'custom_fields/index', :label => TimeEntryActivity::OptionName},
28 {:name => 'IssuePriorityCustomField', :partial => 'custom_fields/index', :label => IssuePriority::OptionName}, 30 {:name => 'IssuePriorityCustomField', :partial => 'custom_fields/index', :label => IssuePriority::OptionName},
29 {:name => 'DocumentCategoryCustomField', :partial => 'custom_fields/index', :label => DocumentCategory::OptionName} 31 {:name => 'DocumentCategoryCustomField', :partial => 'custom_fields/index', :label => DocumentCategory::OptionName}
30 ] 32 ]
31 end 33 end
32 34
33 # Return custom field html tag corresponding to its format 35 # Return custom field html tag corresponding to its format
34 def custom_field_tag(name, custom_value) 36 def custom_field_tag(name, custom_value)
35 custom_field = custom_value.custom_field 37 custom_field = custom_value.custom_field
36 field_name = "#{name}[custom_field_values][#{custom_field.id}]" 38 field_name = "#{name}[custom_field_values][#{custom_field.id}]"
37 field_id = "#{name}_custom_field_values_#{custom_field.id}" 39 field_id = "#{name}_custom_field_values_#{custom_field.id}"
38 40
39 field_format = Redmine::CustomFieldFormat.find_by_name(custom_field.field_format) 41 field_format = Redmine::CustomFieldFormat.find_by_name(custom_field.field_format)
40 case field_format.try(:edit_as) 42 case field_format.try(:edit_as)
41 when "date" 43 when "date"
42 text_field_tag(field_name, custom_value.value, :id => field_id, :size => 10) + 44 text_field_tag(field_name, custom_value.value, :id => field_id, :size => 10) +
43 calendar_for(field_id) 45 calendar_for(field_id)
44 when "text" 46 when "text"
45 text_area_tag(field_name, custom_value.value, :id => field_id, :rows => 3, :style => 'width:90%') 47 text_area_tag(field_name, custom_value.value, :id => field_id, :rows => 3, :style => 'width:90%')
46 when "bool" 48 when "bool"
47 hidden_field_tag(field_name, '0') + check_box_tag(field_name, '1', custom_value.true?, :id => field_id) 49 hidden_field_tag(field_name, '0') + check_box_tag(field_name, '1', custom_value.true?, :id => field_id)
48 when "list" 50 when "list"
49 blank_option = custom_field.is_required? ? 51 blank_option = custom_field.is_required? ?
50 (custom_field.default_value.blank? ? "<option value=\"\">--- #{l(:actionview_instancetag_blank_option)} ---</option>" : '') : 52 (custom_field.default_value.blank? ? "<option value=\"\">--- #{l(:actionview_instancetag_blank_option)} ---</option>" : '') :
51 '<option></option>' 53 '<option></option>'
52 select_tag(field_name, blank_option + options_for_select(custom_field.possible_values_options(custom_value.customized), custom_value.value), :id => field_id) 54 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 55 else
54 text_field_tag(field_name, custom_value.value, :id => field_id) 56 text_field_tag(field_name, custom_value.value, :id => field_id)
55 end 57 end
56 end 58 end
57 59
58 # Return custom field label tag 60 # Return custom field label tag
59 def custom_field_label_tag(name, custom_value) 61 def custom_field_label_tag(name, custom_value)
60 content_tag "label", custom_value.custom_field.name + 62 content_tag "label", h(custom_value.custom_field.name) +
61 (custom_value.custom_field.is_required? ? " <span class=\"required\">*</span>" : ""), 63 (custom_value.custom_field.is_required? ? " <span class=\"required\">*</span>".html_safe : ""),
62 :for => "#{name}_custom_field_values_#{custom_value.custom_field.id}", 64 :for => "#{name}_custom_field_values_#{custom_value.custom_field.id}",
63 :class => (custom_value.errors.empty? ? nil : "error" ) 65 :class => (custom_value.errors.empty? ? nil : "error" )
64 end 66 end
65 67
66 # Return custom field tag with its label tag 68 # Return custom field tag with its label tag
67 def custom_field_tag_with_label(name, custom_value) 69 def custom_field_tag_with_label(name, custom_value)
68 custom_field_label_tag(name, custom_value) + custom_field_tag(name, custom_value) 70 custom_field_label_tag(name, custom_value) + custom_field_tag(name, custom_value)
69 end 71 end
70 72
71 def custom_field_tag_for_bulk_edit(name, custom_field, projects=nil) 73 def custom_field_tag_for_bulk_edit(name, custom_field, projects=nil)
72 field_name = "#{name}[custom_field_values][#{custom_field.id}]" 74 field_name = "#{name}[custom_field_values][#{custom_field.id}]"
73 field_id = "#{name}_custom_field_values_#{custom_field.id}" 75 field_id = "#{name}_custom_field_values_#{custom_field.id}"
74 field_format = Redmine::CustomFieldFormat.find_by_name(custom_field.field_format) 76 field_format = Redmine::CustomFieldFormat.find_by_name(custom_field.field_format)
75 case field_format.try(:edit_as) 77 case field_format.try(:edit_as)
76 when "date" 78 when "date"
77 text_field_tag(field_name, '', :id => field_id, :size => 10) + 79 text_field_tag(field_name, '', :id => field_id, :size => 10) +
78 calendar_for(field_id) 80 calendar_for(field_id)
79 when "text" 81 when "text"
80 text_area_tag(field_name, '', :id => field_id, :rows => 3, :style => 'width:90%') 82 text_area_tag(field_name, '', :id => field_id, :rows => 3, :style => 'width:90%')
81 when "bool" 83 when "bool"
82 select_tag(field_name, options_for_select([[l(:label_no_change_option), ''], 84 select_tag(field_name, options_for_select([[l(:label_no_change_option), ''],
92 # Return a string used to display a custom value 94 # Return a string used to display a custom value
93 def show_value(custom_value) 95 def show_value(custom_value)
94 return "" unless custom_value 96 return "" unless custom_value
95 format_value(custom_value.value, custom_value.custom_field.field_format) 97 format_value(custom_value.value, custom_value.custom_field.field_format)
96 end 98 end
97 99
98 # Return a string used to display a custom value 100 # Return a string used to display a custom value
99 def format_value(value, field_format) 101 def format_value(value, field_format)
100 Redmine::CustomFieldFormat.format_value(value, field_format) # Proxy 102 Redmine::CustomFieldFormat.format_value(value, field_format) # Proxy
101 end 103 end
102 104
103 # Return an array of custom field formats which can be used in select_tag 105 # Return an array of custom field formats which can be used in select_tag
104 def custom_field_formats_for_select(custom_field) 106 def custom_field_formats_for_select(custom_field)
105 Redmine::CustomFieldFormat.as_select(custom_field.class.customized_class.name) 107 Redmine::CustomFieldFormat.as_select(custom_field.class.customized_class.name)
106 end 108 end
107 109
108 # Renders the custom_values in api views 110 # Renders the custom_values in api views
109 def render_api_custom_values(custom_values, api) 111 def render_api_custom_values(custom_values, api)
110 api.array :custom_fields do 112 api.array :custom_fields do
111 custom_values.each do |custom_value| 113 custom_values.each do |custom_value|
112 api.custom_field :id => custom_value.custom_field_id, :name => custom_value.custom_field.name do 114 api.custom_field :id => custom_value.custom_field_id, :name => custom_value.custom_field.name do