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