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