Mercurial > hg > soundsoftware-site
comparison .svn/pristine/3d/3d32001255668e3c83c7a368c346637efc3f891b.svn-base @ 1494:e248c7af89ec redmine-2.4
Update to Redmine SVN revision 12979 on 2.4-stable branch
author | Chris Cannam |
---|---|
date | Mon, 17 Mar 2014 08:54:02 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
1464:261b3d9a4903 | 1494:e248c7af89ec |
---|---|
1 # encoding: utf-8 | |
2 # | |
3 # Redmine - project management software | |
4 # Copyright (C) 2006-2014 Jean-Philippe Lang | |
5 # | |
6 # This program is free software; you can redistribute it and/or | |
7 # modify it under the terms of the GNU General Public License | |
8 # as published by the Free Software Foundation; either version 2 | |
9 # of the License, or (at your option) any later version. | |
10 # | |
11 # This program is distributed in the hope that it will be useful, | |
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 # GNU General Public License for more details. | |
15 # | |
16 # You should have received a copy of the GNU General Public License | |
17 # along with this program; if not, write to the Free Software | |
18 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | |
19 | |
20 module CustomFieldsHelper | |
21 | |
22 CUSTOM_FIELDS_TABS = [ | |
23 {:name => 'IssueCustomField', :partial => 'custom_fields/index', | |
24 :label => :label_issue_plural}, | |
25 {:name => 'TimeEntryCustomField', :partial => 'custom_fields/index', | |
26 :label => :label_spent_time}, | |
27 {:name => 'ProjectCustomField', :partial => 'custom_fields/index', | |
28 :label => :label_project_plural}, | |
29 {:name => 'VersionCustomField', :partial => 'custom_fields/index', | |
30 :label => :label_version_plural}, | |
31 {:name => 'UserCustomField', :partial => 'custom_fields/index', | |
32 :label => :label_user_plural}, | |
33 {:name => 'GroupCustomField', :partial => 'custom_fields/index', | |
34 :label => :label_group_plural}, | |
35 {:name => 'TimeEntryActivityCustomField', :partial => 'custom_fields/index', | |
36 :label => TimeEntryActivity::OptionName}, | |
37 {:name => 'IssuePriorityCustomField', :partial => 'custom_fields/index', | |
38 :label => IssuePriority::OptionName}, | |
39 {:name => 'DocumentCategoryCustomField', :partial => 'custom_fields/index', | |
40 :label => DocumentCategory::OptionName} | |
41 ] | |
42 | |
43 def custom_fields_tabs | |
44 CUSTOM_FIELDS_TABS | |
45 end | |
46 | |
47 # Return custom field html tag corresponding to its format | |
48 def custom_field_tag(name, custom_value) | |
49 custom_field = custom_value.custom_field | |
50 field_name = "#{name}[custom_field_values][#{custom_field.id}]" | |
51 field_name << "[]" if custom_field.multiple? | |
52 field_id = "#{name}_custom_field_values_#{custom_field.id}" | |
53 | |
54 tag_options = {:id => field_id, :class => "#{custom_field.field_format}_cf"} | |
55 | |
56 field_format = Redmine::CustomFieldFormat.find_by_name(custom_field.field_format) | |
57 case field_format.try(:edit_as) | |
58 when "date" | |
59 text_field_tag(field_name, custom_value.value, tag_options.merge(:size => 10)) + | |
60 calendar_for(field_id) | |
61 when "text" | |
62 text_area_tag(field_name, custom_value.value, tag_options.merge(:rows => 3)) | |
63 when "bool" | |
64 hidden_field_tag(field_name, '0') + check_box_tag(field_name, '1', custom_value.true?, tag_options) | |
65 when "list" | |
66 blank_option = ''.html_safe | |
67 unless custom_field.multiple? | |
68 if custom_field.is_required? | |
69 unless custom_field.default_value.present? | |
70 blank_option = content_tag('option', "--- #{l(:actionview_instancetag_blank_option)} ---", :value => '') | |
71 end | |
72 else | |
73 blank_option = content_tag('option') | |
74 end | |
75 end | |
76 s = select_tag(field_name, blank_option + options_for_select(custom_field.possible_values_options(custom_value.customized), custom_value.value), | |
77 tag_options.merge(:multiple => custom_field.multiple?)) | |
78 if custom_field.multiple? | |
79 s << hidden_field_tag(field_name, '') | |
80 end | |
81 s | |
82 else | |
83 text_field_tag(field_name, custom_value.value, tag_options) | |
84 end | |
85 end | |
86 | |
87 # Return custom field label tag | |
88 def custom_field_label_tag(name, custom_value, options={}) | |
89 required = options[:required] || custom_value.custom_field.is_required? | |
90 | |
91 content_tag "label", h(custom_value.custom_field.name) + | |
92 (required ? " <span class=\"required\">*</span>".html_safe : ""), | |
93 :for => "#{name}_custom_field_values_#{custom_value.custom_field.id}" | |
94 end | |
95 | |
96 # Return custom field tag with its label tag | |
97 def custom_field_tag_with_label(name, custom_value, options={}) | |
98 custom_field_label_tag(name, custom_value, options) + custom_field_tag(name, custom_value) | |
99 end | |
100 | |
101 def custom_field_tag_for_bulk_edit(name, custom_field, projects=nil, value='') | |
102 field_name = "#{name}[custom_field_values][#{custom_field.id}]" | |
103 field_name << "[]" if custom_field.multiple? | |
104 field_id = "#{name}_custom_field_values_#{custom_field.id}" | |
105 | |
106 tag_options = {:id => field_id, :class => "#{custom_field.field_format}_cf"} | |
107 | |
108 unset_tag = '' | |
109 unless custom_field.is_required? | |
110 unset_tag = content_tag('label', | |
111 check_box_tag(field_name, '__none__', (value == '__none__'), :id => nil, :data => {:disables => "##{field_id}"}) + l(:button_clear), | |
112 :class => 'inline' | |
113 ) | |
114 end | |
115 | |
116 field_format = Redmine::CustomFieldFormat.find_by_name(custom_field.field_format) | |
117 case field_format.try(:edit_as) | |
118 when "date" | |
119 text_field_tag(field_name, value, tag_options.merge(:size => 10)) + | |
120 calendar_for(field_id) + | |
121 unset_tag | |
122 when "text" | |
123 text_area_tag(field_name, value, tag_options.merge(:rows => 3)) + | |
124 '<br />'.html_safe + | |
125 unset_tag | |
126 when "bool" | |
127 select_tag(field_name, options_for_select([[l(:label_no_change_option), ''], | |
128 [l(:general_text_yes), '1'], | |
129 [l(:general_text_no), '0']], value), tag_options) | |
130 when "list" | |
131 options = [] | |
132 options << [l(:label_no_change_option), ''] unless custom_field.multiple? | |
133 options << [l(:label_none), '__none__'] unless custom_field.is_required? | |
134 options += custom_field.possible_values_options(projects) | |
135 select_tag(field_name, options_for_select(options, value), tag_options.merge(:multiple => custom_field.multiple?)) | |
136 else | |
137 text_field_tag(field_name, value, tag_options) + | |
138 unset_tag | |
139 end | |
140 end | |
141 | |
142 # Return a string used to display a custom value | |
143 def show_value(custom_value) | |
144 return "" unless custom_value | |
145 format_value(custom_value.value, custom_value.custom_field.field_format) | |
146 end | |
147 | |
148 # Return a string used to display a custom value | |
149 def format_value(value, field_format) | |
150 if value.is_a?(Array) | |
151 value.collect {|v| format_value(v, field_format)}.compact.sort.join(', ') | |
152 else | |
153 Redmine::CustomFieldFormat.format_value(value, field_format) | |
154 end | |
155 end | |
156 | |
157 # Return an array of custom field formats which can be used in select_tag | |
158 def custom_field_formats_for_select(custom_field) | |
159 Redmine::CustomFieldFormat.as_select(custom_field.class.customized_class.name) | |
160 end | |
161 | |
162 # Renders the custom_values in api views | |
163 def render_api_custom_values(custom_values, api) | |
164 api.array :custom_fields do | |
165 custom_values.each do |custom_value| | |
166 attrs = {:id => custom_value.custom_field_id, :name => custom_value.custom_field.name} | |
167 attrs.merge!(:multiple => true) if custom_value.custom_field.multiple? | |
168 api.custom_field attrs do | |
169 if custom_value.value.is_a?(Array) | |
170 api.array :value do | |
171 custom_value.value.each do |value| | |
172 api.value value unless value.blank? | |
173 end | |
174 end | |
175 else | |
176 api.value custom_value.value | |
177 end | |
178 end | |
179 end | |
180 end unless custom_values.empty? | |
181 end | |
182 end |