##// END OF EJS Templates
custom field tags...
Jean-Philippe Lang -
r18:54aeec7b5fcf
parent child
Show More
@@ -80,7 +80,7 class ProjectsController < ApplicationController
80 @member ||= @project.members.new
80 @member ||= @project.members.new
81 @roles = Role.find_all
81 @roles = Role.find_all
82 @users = User.find_all - @project.members.find(:all, :include => :user).collect{|m| m.user }
82 @users = User.find_all - @project.members.find(:all, :include => :user).collect{|m| m.user }
83 @custom_values = ProjectCustomField.find(:all).collect { |x| @project.custom_values.find_by_custom_field_id(x.id) || CustomValue.new(:custom_field => x) }
83 @custom_values ||= ProjectCustomField.find(:all).collect { |x| @project.custom_values.find_by_custom_field_id(x.id) || CustomValue.new(:custom_field => x) }
84 end
84 end
85
85
86 # Edit @project
86 # Edit @project
@@ -17,16 +17,17
17
17
18 module ApplicationHelper
18 module ApplicationHelper
19
19
20 # return current logged in user or nil
20 # Return current logged in user or nil
21 def loggedin?
21 def loggedin?
22 @logged_in_user
22 @logged_in_user
23 end
23 end
24
24
25 # return true if user is loggend in and is admin, otherwise false
25 # Return true if user is logged in and is admin, otherwise false
26 def admin_loggedin?
26 def admin_loggedin?
27 @logged_in_user and @logged_in_user.admin?
27 @logged_in_user and @logged_in_user.admin?
28 end
28 end
29
29
30 # Return true if user is authorized for controller/action, otherwise false
30 def authorize_for(controller, action)
31 def authorize_for(controller, action)
31 # check if action is allowed on public projects
32 # check if action is allowed on public projects
32 if @project.is_public? and Permission.allowed_to_public "%s/%s" % [ controller, action ]
33 if @project.is_public? and Permission.allowed_to_public "%s/%s" % [ controller, action ]
@@ -76,12 +77,21 module ApplicationHelper
76 if attr == "base"
77 if attr == "base"
77 full_messages << l(msg)
78 full_messages << l(msg)
78 else
79 else
79 full_messages << "&#171; " + (l_has_string?("field_" + attr) ? l("field_" + attr) : object.class.human_attribute_name(attr)) + " &#187; " + l(msg)
80 full_messages << "&#171; " + (l_has_string?("field_" + attr) ? l("field_" + attr) : object.class.human_attribute_name(attr)) + " &#187; " + l(msg) unless attr == "custom_values"
80 end
81 end
81 end
82 end
83 # retrieve custom values error messages
84 if object.errors[:custom_values]
85 object.custom_values.each do |v|
86 v.errors.each do |attr, msg|
87 next if msg.nil?
88 full_messages << "&#171; " + v.custom_field.name + " &#187; " + l(msg)
89 end
90 end
91 end
82 content_tag("div",
92 content_tag("div",
83 content_tag(
93 content_tag(
84 options[:header_tag] || "h2", lwr(:gui_validation_error, object.errors.count) + " :"
94 options[:header_tag] || "h2", lwr(:gui_validation_error, full_messages.length) + " :"
85 ) +
95 ) +
86 content_tag("ul", full_messages.collect { |msg| content_tag("li", msg) }),
96 content_tag("ul", full_messages.collect { |msg| content_tag("li", msg) }),
87 "id" => options[:id] || "errorExplanation", "class" => options[:class] || "errorExplanation"
97 "id" => options[:id] || "errorExplanation", "class" => options[:class] || "errorExplanation"
@@ -17,6 +17,7
17
17
18 module CustomFieldsHelper
18 module CustomFieldsHelper
19
19
20 # Return custom field html tag corresponding to its format
20 def custom_field_tag(custom_value)
21 def custom_field_tag(custom_value)
21 custom_field = custom_value.custom_field
22 custom_field = custom_value.custom_field
22 field_name = "custom_fields[#{custom_field.id}]"
23 field_name = "custom_fields[#{custom_field.id}]"
@@ -24,34 +25,35 module CustomFieldsHelper
24
25
25 case custom_field.field_format
26 case custom_field.field_format
26 when "string", "int", "date"
27 when "string", "int", "date"
27 text_field_tag field_name, custom_value.value, :id => field_id
28 text_field 'custom_value', 'value', :name => field_name, :id => field_id
28 when "text"
29 when "text"
29 text_area_tag field_name, custom_value.value, :id => field_id, :cols => 60, :rows => 3
30 text_area 'custom_value', 'value', :name => field_name, :id => field_id, :cols => 60, :rows => 3
30 when "bool"
31 when "bool"
31 check_box_tag(field_name, "1", custom_value.value == "1", :id => field_id) +
32 check_box 'custom_value', 'value', :name => field_name, :id => field_id
32 hidden_field_tag(field_name, "0")
33 when "list"
33 when "list"
34 select_tag field_name,
34 select 'custom_value', 'value', custom_field.possible_values.split('|'), { :include_blank => true }, :name => field_name, :id => field_id
35 "<option></option>" + options_for_select(custom_field.possible_values.split('|'),
36 custom_value.value), :id => field_id
37 end
35 end
38 end
36 end
39
37
38 # Return custom field label tag
40 def custom_field_label_tag(custom_value)
39 def custom_field_label_tag(custom_value)
41 content_tag "label", custom_value.custom_field.name +
40 content_tag "label", custom_value.custom_field.name +
42 (custom_value.custom_field.is_required? ? " <span class=\"required\">*</span>" : ""),
41 (custom_value.custom_field.is_required? ? " <span class=\"required\">*</span>" : ""),
43 :for => "custom_fields_#{custom_value.custom_field.id}"
42 :for => "custom_fields_#{custom_value.custom_field.id}"
44 end
43 end
45
44
45 # Return custom field tag with its label tag
46 def custom_field_tag_with_label(custom_value)
46 def custom_field_tag_with_label(custom_value)
47 case custom_value.custom_field.field_format
47 case custom_value.custom_field.field_format
48 when "bool"
48 when "bool"
49 # label is displayed inline after the checkbox
49 custom_field_tag(custom_value) + " " + custom_field_label_tag(custom_value)
50 custom_field_tag(custom_value) + " " + custom_field_label_tag(custom_value)
50 else
51 else
51 custom_field_label_tag(custom_value) + "<br />" + custom_field_tag(custom_value)
52 custom_field_label_tag(custom_value) + "<br />" + custom_field_tag(custom_value)
52 end
53 end
53 end
54 end
54
55
56 # Return a string used to display a custom value
55 def show_value(custom_value)
57 def show_value(custom_value)
56 case custom_value.custom_field.field_format
58 case custom_value.custom_field.field_format
57 when "bool"
59 when "bool"
@@ -61,6 +63,7 module CustomFieldsHelper
61 end
63 end
62 end
64 end
63
65
66 # Return an array of custom field formats which can be used in select_tag
64 def custom_field_formats_for_select
67 def custom_field_formats_for_select
65 CustomField::FIELD_FORMATS.keys.collect { |k| [ l(CustomField::FIELD_FORMATS[k]), k ] }
68 CustomField::FIELD_FORMATS.keys.collect { |k| [ l(CustomField::FIELD_FORMATS[k]), k ] }
66 end
69 end
@@ -21,22 +21,17 class CustomValue < ActiveRecord::Base
21
21
22 protected
22 protected
23 def validate
23 def validate
24 # errors are added to customized object unless it's nil
24 errors.add(:value, :activerecord_error_blank) and return if custom_field.is_required? and value.empty?
25 object = customized || self
25 errors.add(:value, :activerecord_error_invalid) unless custom_field.regexp.empty? or value =~ Regexp.new(custom_field.regexp)
26
26 errors.add(:value, :activerecord_error_too_short) if custom_field.min_length > 0 and value.length < custom_field.min_length and value.length > 0
27 object.errors.add(custom_field.name, :activerecord_error_blank) if custom_field.is_required? and value.empty?
27 errors.add(:value, :activerecord_error_too_long) if custom_field.max_length > 0 and value.length > custom_field.max_length
28 object.errors.add(custom_field.name, :activerecord_error_invalid) unless custom_field.regexp.empty? or value =~ Regexp.new(custom_field.regexp)
29
30 object.errors.add(custom_field.name, :activerecord_error_too_short) if custom_field.min_length > 0 and value.length < custom_field.min_length and value.length > 0
31 object.errors.add(custom_field.name, :activerecord_error_too_long) if custom_field.max_length > 0 and value.length > custom_field.max_length
32
33 case custom_field.field_format
28 case custom_field.field_format
34 when "int"
29 when "int"
35 object.errors.add(custom_field.name, :activerecord_error_not_a_number) unless value =~ /^[0-9]*$/
30 errors.add(:value, :activerecord_error_not_a_number) unless value =~ /^[0-9]*$/
36 when "date"
31 when "date"
37 object.errors.add(custom_field.name, :activerecord_error_invalid) unless value =~ /^(\d+)\/(\d+)\/(\d+)$/ or value.empty?
32 errors.add(:value, :activerecord_error_invalid) unless value =~ /^(\d+)\/(\d+)\/(\d+)$/ or value.empty?
38 when "list"
33 when "list"
39 object.errors.add(custom_field.name, :activerecord_error_inclusion) unless custom_field.possible_values.split('|').include? value or value.empty?
34 errors.add(:value, :activerecord_error_inclusion) unless custom_field.possible_values.split('|').include? value or value.empty?
40 end
35 end
41 end
36 end
42 end
37 end
@@ -26,8 +26,8
26 <p><label for="user_language"><%=l(:field_language)%></label><br/>
26 <p><label for="user_language"><%=l(:field_language)%></label><br/>
27 <%= select("user", "language", lang_options_for_select) %></p>
27 <%= select("user", "language", lang_options_for_select) %></p>
28
28
29 <% for custom_value in @custom_values %>
29 <% for @custom_value in @custom_values %>
30 <p><%= custom_field_tag_with_label custom_value %></p>
30 <p><%= custom_field_tag_with_label @custom_value %></p>
31 <% end %>
31 <% end %>
32
32
33 <p><%= check_box 'user', 'mail_notification' %> <label for="user_mail_notification"><%=l(:field_mail_notification)%></label></p>
33 <p><%= check_box 'user', 'mail_notification' %> <label for="user_mail_notification"><%=l(:field_mail_notification)%></label></p>
@@ -39,8 +39,8
39 <p><label for="issue_due_date"><%=l(:field_due_date)%></label><br />
39 <p><label for="issue_due_date"><%=l(:field_due_date)%></label><br />
40 <%= date_select 'issue', 'due_date', :start_year => Date.today.year, :include_blank => true %></p>
40 <%= date_select 'issue', 'due_date', :start_year => Date.today.year, :include_blank => true %></p>
41
41
42 <% for custom_value in @custom_values %>
42 <% for @custom_value in @custom_values %>
43 <p><%= custom_field_tag_with_label custom_value %></p>
43 <p><%= custom_field_tag_with_label @custom_value %></p>
44 <% end %>
44 <% end %>
45
45
46 <p><label for="issue_fixed_version"><%=l(:field_fixed_version)%></label><br/>
46 <p><label for="issue_fixed_version"><%=l(:field_fixed_version)%></label><br/>
@@ -22,8 +22,8
22 <p><%= check_box 'project', 'is_public' %>
22 <p><%= check_box 'project', 'is_public' %>
23 <label for="project_is_public"><%=l(:field_is_public)%></label></p>
23 <label for="project_is_public"><%=l(:field_is_public)%></label></p>
24
24
25 <% for custom_value in @custom_values %>
25 <% for @custom_value in @custom_values %>
26 <p><%= custom_field_tag_with_label custom_value %></p>
26 <p><%= custom_field_tag_with_label @custom_value %></p>
27 <% end %>
27 <% end %>
28
28
29 <fieldset><legend><%=l(:label_custom_field_plural)%></legend>
29 <fieldset><legend><%=l(:label_custom_field_plural)%></legend>
@@ -39,8 +39,8
39 <p><label for="issue_due_date"><%=l(:field_due_date)%></label><br />
39 <p><label for="issue_due_date"><%=l(:field_due_date)%></label><br />
40 <%= date_select 'issue', 'due_date', :start_year => Date.today.year, :include_blank => true %></p>
40 <%= date_select 'issue', 'due_date', :start_year => Date.today.year, :include_blank => true %></p>
41
41
42 <% for custom_value in @custom_values %>
42 <% for @custom_value in @custom_values %>
43 <p><%= custom_field_tag_with_label custom_value %></p>
43 <p><%= custom_field_tag_with_label @custom_value %></p>
44 <% end %>
44 <% end %>
45
45
46 <p><label for="attachment_file"><%=l(:label_attachment)%></label><br />
46 <p><label for="attachment_file"><%=l(:label_attachment)%></label><br />
@@ -23,8 +23,8
23 <p><label for="user_language"><%=l(:field_language)%></label><br/>
23 <p><label for="user_language"><%=l(:field_language)%></label><br/>
24 <%= select("user", "language", lang_options_for_select) %></p>
24 <%= select("user", "language", lang_options_for_select) %></p>
25
25
26 <% for custom_value in @custom_values %>
26 <% for @custom_value in @custom_values %>
27 <p><%= custom_field_tag_with_label custom_value %></p>
27 <p><%= custom_field_tag_with_label @custom_value %></p>
28 <% end %>
28 <% end %>
29
29
30 <div style="clear: both;"></div>
30 <div style="clear: both;"></div>
General Comments 0
You need to be logged in to leave comments. Login now