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