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