@@ -1,77 +1,77 | |||
|
1 | 1 | # redMine - project management software |
|
2 | 2 | # Copyright (C) 2006 Jean-Philippe Lang |
|
3 | 3 | # |
|
4 | 4 | # This program is free software; you can redistribute it and/or |
|
5 | 5 | # modify it under the terms of the GNU General Public License |
|
6 | 6 | # as published by the Free Software Foundation; either version 2 |
|
7 | 7 | # of the License, or (at your option) any later version. |
|
8 | 8 | # |
|
9 | 9 | # This program is distributed in the hope that it will be useful, |
|
10 | 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 | 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
12 | 12 | # GNU General Public License for more details. |
|
13 | 13 | # |
|
14 | 14 | # You should have received a copy of the GNU General Public License |
|
15 | 15 | # along with this program; if not, write to the Free Software |
|
16 | 16 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
|
17 | 17 | |
|
18 | 18 | module CustomFieldsHelper |
|
19 | 19 | |
|
20 | 20 | # Return custom field html tag corresponding to its format |
|
21 | 21 | def custom_field_tag(custom_value) |
|
22 | 22 | custom_field = custom_value.custom_field |
|
23 | 23 | field_name = "custom_fields[#{custom_field.id}]" |
|
24 | 24 | field_id = "custom_fields_#{custom_field.id}" |
|
25 | 25 | |
|
26 | 26 | case custom_field.field_format |
|
27 | 27 | when "date" |
|
28 | 28 | text_field('custom_value', 'value', :name => field_name, :id => field_id, :size => 10) + |
|
29 | 29 | calendar_for(field_id) |
|
30 | 30 | when "text" |
|
31 | 31 | text_area 'custom_value', 'value', :name => field_name, :id => field_id, :cols => 60, :rows => 3 |
|
32 | 32 | when "bool" |
|
33 | 33 | check_box 'custom_value', 'value', :name => field_name, :id => field_id |
|
34 | 34 | when "list" |
|
35 | 35 | select 'custom_value', 'value', custom_field.possible_values, { :include_blank => true }, :name => field_name, :id => field_id |
|
36 | 36 | else |
|
37 | 37 | text_field 'custom_value', 'value', :name => field_name, :id => field_id |
|
38 | 38 | end |
|
39 | 39 | end |
|
40 | 40 | |
|
41 | 41 | # Return custom field label tag |
|
42 | 42 | def custom_field_label_tag(custom_value) |
|
43 | 43 | content_tag "label", custom_value.custom_field.name + |
|
44 | 44 | (custom_value.custom_field.is_required? ? " <span class=\"required\">*</span>" : ""), |
|
45 | 45 | :for => "custom_fields_#{custom_value.custom_field.id}", |
|
46 | 46 | :class => (custom_value.errors.empty? ? nil : "error" ) |
|
47 | 47 | end |
|
48 | 48 | |
|
49 | 49 | # Return custom field tag with its label tag |
|
50 | 50 | def custom_field_tag_with_label(custom_value) |
|
51 | 51 | custom_field_label_tag(custom_value) + custom_field_tag(custom_value) |
|
52 | 52 | end |
|
53 | 53 | |
|
54 | 54 | # Return a string used to display a custom value |
|
55 | 55 | def show_value(custom_value) |
|
56 | 56 | return "" unless custom_value |
|
57 | 57 | format_value(custom_value.value, custom_value.custom_field.field_format) |
|
58 | 58 | end |
|
59 | 59 | |
|
60 | 60 | # Return a string used to display a custom value |
|
61 | 61 | def format_value(value, field_format) |
|
62 | 62 | return "" unless value && !value.empty? |
|
63 | 63 | case field_format |
|
64 | 64 | when "date" |
|
65 |
begin; |
|
|
65 | begin; format_date(value.to_date); rescue; value end | |
|
66 | 66 | when "bool" |
|
67 | 67 | l_YesNo(value == "1") |
|
68 | 68 | else |
|
69 | 69 | value |
|
70 | 70 | end |
|
71 | 71 | end |
|
72 | 72 | |
|
73 | 73 | # Return an array of custom field formats which can be used in select_tag |
|
74 | 74 | def custom_field_formats_for_select |
|
75 | 75 | CustomField::FIELD_FORMATS.sort {|a,b| a[1][:order]<=>b[1][:order]}.collect { |k| [ l(k[1][:name]), k[0] ] } |
|
76 | 76 | end |
|
77 | 77 | end |
General Comments 0
You need to be logged in to leave comments.
Login now