##// END OF EJS Templates
Change the order of checkboxes for boolean custom fields....
Eric Davis -
r2828:739e11702a81
parent child
Show More
@@ -1,89 +1,89
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 def custom_fields_tabs
20 def custom_fields_tabs
21 tabs = [{:name => 'IssueCustomField', :partial => 'custom_fields/index', :label => :label_issue_plural},
21 tabs = [{:name => 'IssueCustomField', :partial => 'custom_fields/index', :label => :label_issue_plural},
22 {:name => 'TimeEntryCustomField', :partial => 'custom_fields/index', :label => :label_spent_time},
22 {:name => 'TimeEntryCustomField', :partial => 'custom_fields/index', :label => :label_spent_time},
23 {:name => 'ProjectCustomField', :partial => 'custom_fields/index', :label => :label_project_plural},
23 {:name => 'ProjectCustomField', :partial => 'custom_fields/index', :label => :label_project_plural},
24 {:name => 'UserCustomField', :partial => 'custom_fields/index', :label => :label_user_plural},
24 {:name => 'UserCustomField', :partial => 'custom_fields/index', :label => :label_user_plural},
25 {:name => 'GroupCustomField', :partial => 'custom_fields/index', :label => :label_group_plural}
25 {:name => 'GroupCustomField', :partial => 'custom_fields/index', :label => :label_group_plural}
26 ]
26 ]
27 end
27 end
28
28
29 # Return custom field html tag corresponding to its format
29 # Return custom field html tag corresponding to its format
30 def custom_field_tag(name, custom_value)
30 def custom_field_tag(name, custom_value)
31 custom_field = custom_value.custom_field
31 custom_field = custom_value.custom_field
32 field_name = "#{name}[custom_field_values][#{custom_field.id}]"
32 field_name = "#{name}[custom_field_values][#{custom_field.id}]"
33 field_id = "#{name}_custom_field_values_#{custom_field.id}"
33 field_id = "#{name}_custom_field_values_#{custom_field.id}"
34
34
35 case custom_field.field_format
35 case custom_field.field_format
36 when "date"
36 when "date"
37 text_field_tag(field_name, custom_value.value, :id => field_id, :size => 10) +
37 text_field_tag(field_name, custom_value.value, :id => field_id, :size => 10) +
38 calendar_for(field_id)
38 calendar_for(field_id)
39 when "text"
39 when "text"
40 text_area_tag(field_name, custom_value.value, :id => field_id, :rows => 3, :style => 'width:90%')
40 text_area_tag(field_name, custom_value.value, :id => field_id, :rows => 3, :style => 'width:90%')
41 when "bool"
41 when "bool"
42 check_box_tag(field_name, '1', custom_value.true?, :id => field_id) + hidden_field_tag(field_name, '0')
42 hidden_field_tag(field_name, '0') + check_box_tag(field_name, '1', custom_value.true?, :id => field_id)
43 when "list"
43 when "list"
44 blank_option = custom_field.is_required? ?
44 blank_option = custom_field.is_required? ?
45 (custom_field.default_value.blank? ? "<option value=\"\">--- #{l(:actionview_instancetag_blank_option)} ---</option>" : '') :
45 (custom_field.default_value.blank? ? "<option value=\"\">--- #{l(:actionview_instancetag_blank_option)} ---</option>" : '') :
46 '<option></option>'
46 '<option></option>'
47 select_tag(field_name, blank_option + options_for_select(custom_field.possible_values, custom_value.value), :id => field_id)
47 select_tag(field_name, blank_option + options_for_select(custom_field.possible_values, custom_value.value), :id => field_id)
48 else
48 else
49 text_field_tag(field_name, custom_value.value, :id => field_id)
49 text_field_tag(field_name, custom_value.value, :id => field_id)
50 end
50 end
51 end
51 end
52
52
53 # Return custom field label tag
53 # Return custom field label tag
54 def custom_field_label_tag(name, custom_value)
54 def custom_field_label_tag(name, custom_value)
55 content_tag "label", custom_value.custom_field.name +
55 content_tag "label", custom_value.custom_field.name +
56 (custom_value.custom_field.is_required? ? " <span class=\"required\">*</span>" : ""),
56 (custom_value.custom_field.is_required? ? " <span class=\"required\">*</span>" : ""),
57 :for => "#{name}_custom_field_values_#{custom_value.custom_field.id}",
57 :for => "#{name}_custom_field_values_#{custom_value.custom_field.id}",
58 :class => (custom_value.errors.empty? ? nil : "error" )
58 :class => (custom_value.errors.empty? ? nil : "error" )
59 end
59 end
60
60
61 # Return custom field tag with its label tag
61 # Return custom field tag with its label tag
62 def custom_field_tag_with_label(name, custom_value)
62 def custom_field_tag_with_label(name, custom_value)
63 custom_field_label_tag(name, custom_value) + custom_field_tag(name, custom_value)
63 custom_field_label_tag(name, custom_value) + custom_field_tag(name, custom_value)
64 end
64 end
65
65
66 # Return a string used to display a custom value
66 # Return a string used to display a custom value
67 def show_value(custom_value)
67 def show_value(custom_value)
68 return "" unless custom_value
68 return "" unless custom_value
69 format_value(custom_value.value, custom_value.custom_field.field_format)
69 format_value(custom_value.value, custom_value.custom_field.field_format)
70 end
70 end
71
71
72 # Return a string used to display a custom value
72 # Return a string used to display a custom value
73 def format_value(value, field_format)
73 def format_value(value, field_format)
74 return "" unless value && !value.empty?
74 return "" unless value && !value.empty?
75 case field_format
75 case field_format
76 when "date"
76 when "date"
77 begin; format_date(value.to_date); rescue; value end
77 begin; format_date(value.to_date); rescue; value end
78 when "bool"
78 when "bool"
79 l(value == "1" ? :general_text_Yes : :general_text_No)
79 l(value == "1" ? :general_text_Yes : :general_text_No)
80 else
80 else
81 value
81 value
82 end
82 end
83 end
83 end
84
84
85 # Return an array of custom field formats which can be used in select_tag
85 # Return an array of custom field formats which can be used in select_tag
86 def custom_field_formats_for_select
86 def custom_field_formats_for_select
87 CustomField::FIELD_FORMATS.sort {|a,b| a[1][:order]<=>b[1][:order]}.collect { |k| [ l(k[1][:name]), k[0] ] }
87 CustomField::FIELD_FORMATS.sort {|a,b| a[1][:order]<=>b[1][:order]}.collect { |k| [ l(k[1][:name]), k[0] ] }
88 end
88 end
89 end
89 end
General Comments 0
You need to be logged in to leave comments. Login now