diff --git a/redmine/app/controllers/projects_controller.rb b/redmine/app/controllers/projects_controller.rb
index 2bfb841d6..802573054 100644
--- a/redmine/app/controllers/projects_controller.rb
+++ b/redmine/app/controllers/projects_controller.rb
@@ -80,7 +80,7 @@ class ProjectsController < ApplicationController
@member ||= @project.members.new
@roles = Role.find_all
@users = User.find_all - @project.members.find(:all, :include => :user).collect{|m| m.user }
- @custom_values = ProjectCustomField.find(:all).collect { |x| @project.custom_values.find_by_custom_field_id(x.id) || CustomValue.new(:custom_field => x) }
+ @custom_values ||= ProjectCustomField.find(:all).collect { |x| @project.custom_values.find_by_custom_field_id(x.id) || CustomValue.new(:custom_field => x) }
end
# Edit @project
diff --git a/redmine/app/helpers/application_helper.rb b/redmine/app/helpers/application_helper.rb
index 7f3f97532..d45cf9b97 100644
--- a/redmine/app/helpers/application_helper.rb
+++ b/redmine/app/helpers/application_helper.rb
@@ -17,16 +17,17 @@
module ApplicationHelper
- # return current logged in user or nil
+ # Return current logged in user or nil
def loggedin?
@logged_in_user
end
- # return true if user is loggend in and is admin, otherwise false
+ # Return true if user is logged in and is admin, otherwise false
def admin_loggedin?
@logged_in_user and @logged_in_user.admin?
end
+ # Return true if user is authorized for controller/action, otherwise false
def authorize_for(controller, action)
# check if action is allowed on public projects
if @project.is_public? and Permission.allowed_to_public "%s/%s" % [ controller, action ]
@@ -76,12 +77,21 @@ module ApplicationHelper
if attr == "base"
full_messages << l(msg)
else
- full_messages << "« " + (l_has_string?("field_" + attr) ? l("field_" + attr) : object.class.human_attribute_name(attr)) + " » " + l(msg)
+ full_messages << "« " + (l_has_string?("field_" + attr) ? l("field_" + attr) : object.class.human_attribute_name(attr)) + " » " + l(msg) unless attr == "custom_values"
end
- end
+ end
+ # retrieve custom values error messages
+ if object.errors[:custom_values]
+ object.custom_values.each do |v|
+ v.errors.each do |attr, msg|
+ next if msg.nil?
+ full_messages << "« " + v.custom_field.name + " » " + l(msg)
+ end
+ end
+ end
content_tag("div",
content_tag(
- options[:header_tag] || "h2", lwr(:gui_validation_error, object.errors.count) + " :"
+ options[:header_tag] || "h2", lwr(:gui_validation_error, full_messages.length) + " :"
) +
content_tag("ul", full_messages.collect { |msg| content_tag("li", msg) }),
"id" => options[:id] || "errorExplanation", "class" => options[:class] || "errorExplanation"
diff --git a/redmine/app/helpers/custom_fields_helper.rb b/redmine/app/helpers/custom_fields_helper.rb
index 2af21edbb..bc5a15e9a 100644
--- a/redmine/app/helpers/custom_fields_helper.rb
+++ b/redmine/app/helpers/custom_fields_helper.rb
@@ -17,6 +17,7 @@
module CustomFieldsHelper
+ # Return custom field html tag corresponding to its format
def custom_field_tag(custom_value)
custom_field = custom_value.custom_field
field_name = "custom_fields[#{custom_field.id}]"
@@ -24,34 +25,35 @@ module CustomFieldsHelper
case custom_field.field_format
when "string", "int", "date"
- text_field_tag field_name, custom_value.value, :id => field_id
+ text_field 'custom_value', 'value', :name => field_name, :id => field_id
when "text"
- text_area_tag field_name, custom_value.value, :id => field_id, :cols => 60, :rows => 3
+ text_area 'custom_value', 'value', :name => field_name, :id => field_id, :cols => 60, :rows => 3
when "bool"
- check_box_tag(field_name, "1", custom_value.value == "1", :id => field_id) +
- hidden_field_tag(field_name, "0")
+ check_box 'custom_value', 'value', :name => field_name, :id => field_id
when "list"
- select_tag field_name,
- "" + options_for_select(custom_field.possible_values.split('|'),
- custom_value.value), :id => field_id
+ select 'custom_value', 'value', custom_field.possible_values.split('|'), { :include_blank => true }, :name => field_name, :id => field_id
end
end
+ # Return custom field label tag
def custom_field_label_tag(custom_value)
content_tag "label", custom_value.custom_field.name +
(custom_value.custom_field.is_required? ? " *" : ""),
:for => "custom_fields_#{custom_value.custom_field.id}"
end
+ # Return custom field tag with its label tag
def custom_field_tag_with_label(custom_value)
case custom_value.custom_field.field_format
when "bool"
+ # label is displayed inline after the checkbox
custom_field_tag(custom_value) + " " + custom_field_label_tag(custom_value)
else
custom_field_label_tag(custom_value) + "
" + custom_field_tag(custom_value)
end
end
+ # Return a string used to display a custom value
def show_value(custom_value)
case custom_value.custom_field.field_format
when "bool"
@@ -61,6 +63,7 @@ module CustomFieldsHelper
end
end
+ # Return an array of custom field formats which can be used in select_tag
def custom_field_formats_for_select
CustomField::FIELD_FORMATS.keys.collect { |k| [ l(CustomField::FIELD_FORMATS[k]), k ] }
end
diff --git a/redmine/app/models/custom_value.rb b/redmine/app/models/custom_value.rb
index ac72e5aba..6c1dd3aea 100644
--- a/redmine/app/models/custom_value.rb
+++ b/redmine/app/models/custom_value.rb
@@ -21,22 +21,17 @@ class CustomValue < ActiveRecord::Base
protected
def validate
- # errors are added to customized object unless it's nil
- object = customized || self
-
- object.errors.add(custom_field.name, :activerecord_error_blank) if custom_field.is_required? and value.empty?
- object.errors.add(custom_field.name, :activerecord_error_invalid) unless custom_field.regexp.empty? or value =~ Regexp.new(custom_field.regexp)
-
- 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
- object.errors.add(custom_field.name, :activerecord_error_too_long) if custom_field.max_length > 0 and value.length > custom_field.max_length
-
+ errors.add(:value, :activerecord_error_blank) and return if custom_field.is_required? and value.empty?
+ errors.add(:value, :activerecord_error_invalid) unless custom_field.regexp.empty? or value =~ Regexp.new(custom_field.regexp)
+ errors.add(:value, :activerecord_error_too_short) if custom_field.min_length > 0 and value.length < custom_field.min_length and value.length > 0
+ errors.add(:value, :activerecord_error_too_long) if custom_field.max_length > 0 and value.length > custom_field.max_length
case custom_field.field_format
when "int"
- object.errors.add(custom_field.name, :activerecord_error_not_a_number) unless value =~ /^[0-9]*$/
+ errors.add(:value, :activerecord_error_not_a_number) unless value =~ /^[0-9]*$/
when "date"
- object.errors.add(custom_field.name, :activerecord_error_invalid) unless value =~ /^(\d+)\/(\d+)\/(\d+)$/ or value.empty?
+ errors.add(:value, :activerecord_error_invalid) unless value =~ /^(\d+)\/(\d+)\/(\d+)$/ or value.empty?
when "list"
- object.errors.add(custom_field.name, :activerecord_error_inclusion) unless custom_field.possible_values.split('|').include? value or value.empty?
+ errors.add(:value, :activerecord_error_inclusion) unless custom_field.possible_values.split('|').include? value or value.empty?
end
end
end
diff --git a/redmine/app/views/account/register.rhtml b/redmine/app/views/account/register.rhtml
index 3a953a254..74a5c74c0 100644
--- a/redmine/app/views/account/register.rhtml
+++ b/redmine/app/views/account/register.rhtml
@@ -26,8 +26,8 @@
<%= select("user", "language", lang_options_for_select) %>
<%= custom_field_tag_with_label custom_value %>
+<% for @custom_value in @custom_values %> +<%= custom_field_tag_with_label @custom_value %>
<% end %><%= check_box 'user', 'mail_notification' %>
diff --git a/redmine/app/views/issues/edit.rhtml b/redmine/app/views/issues/edit.rhtml index b8fc6ad4c..0386173ef 100644 --- a/redmine/app/views/issues/edit.rhtml +++ b/redmine/app/views/issues/edit.rhtml @@ -39,8 +39,8 @@
<%= date_select 'issue', 'due_date', :start_year => Date.today.year, :include_blank => true %>
<%= custom_field_tag_with_label custom_value %>
+<% for @custom_value in @custom_values %> +<%= custom_field_tag_with_label @custom_value %>
<% end %>
diff --git a/redmine/app/views/projects/_form.rhtml b/redmine/app/views/projects/_form.rhtml
index 06fdc46fb..18b703cbd 100644
--- a/redmine/app/views/projects/_form.rhtml
+++ b/redmine/app/views/projects/_form.rhtml
@@ -22,8 +22,8 @@
<%= check_box 'project', 'is_public' %>
-<% for custom_value in @custom_values %> -<%= custom_field_tag_with_label custom_value %>
+<% for @custom_value in @custom_values %> +<%= custom_field_tag_with_label @custom_value %>
<% end %>