@member ||= @project.members.new\r
@roles = Role.find_all\r
@users = User.find_all - @project.members.find(:all, :include => :user).collect{|m| m.user }\r
- @custom_values = ProjectCustomField.find(:all).collect { |x| @project.custom_values.find_by_custom_field_id(x.id) || CustomValue.new(:custom_field => x) }\r
+ @custom_values ||= ProjectCustomField.find(:all).collect { |x| @project.custom_values.find_by_custom_field_id(x.id) || CustomValue.new(:custom_field => x) }\r
end\r
\r
# Edit @project\r
\r
module ApplicationHelper\r
\r
- # return current logged in user or nil\r
+ # Return current logged in user or nil\r
def loggedin?\r
@logged_in_user\r
end\r
\r
- # return true if user is loggend in and is admin, otherwise false\r
+ # Return true if user is logged in and is admin, otherwise false\r
def admin_loggedin?\r
@logged_in_user and @logged_in_user.admin?\r
end\r
\r
+ # Return true if user is authorized for controller/action, otherwise false\r
def authorize_for(controller, action) \r
# check if action is allowed on public projects\r
if @project.is_public? and Permission.allowed_to_public "%s/%s" % [ controller, action ]\r
if attr == "base"\r
full_messages << l(msg)\r
else\r
- full_messages << "« " + (l_has_string?("field_" + attr) ? l("field_" + attr) : object.class.human_attribute_name(attr)) + " » " + l(msg)\r
+ full_messages << "« " + (l_has_string?("field_" + attr) ? l("field_" + attr) : object.class.human_attribute_name(attr)) + " » " + l(msg) unless attr == "custom_values"\r
end\r
- end \r
+ end\r
+ # retrieve custom values error messages\r
+ if object.errors[:custom_values]\r
+ object.custom_values.each do |v| \r
+ v.errors.each do |attr, msg|\r
+ next if msg.nil?\r
+ full_messages << "« " + v.custom_field.name + " » " + l(msg)\r
+ end\r
+ end\r
+ end \r
content_tag("div",\r
content_tag(\r
- options[:header_tag] || "h2", lwr(:gui_validation_error, object.errors.count) + " :"\r
+ options[:header_tag] || "h2", lwr(:gui_validation_error, full_messages.length) + " :"\r
) +\r
content_tag("ul", full_messages.collect { |msg| content_tag("li", msg) }),\r
"id" => options[:id] || "errorExplanation", "class" => options[:class] || "errorExplanation"\r
\r
module CustomFieldsHelper\r
\r
+ # Return custom field html tag corresponding to its format\r
def custom_field_tag(custom_value) \r
custom_field = custom_value.custom_field\r
field_name = "custom_fields[#{custom_field.id}]"\r
\r
case custom_field.field_format\r
when "string", "int", "date"\r
- text_field_tag field_name, custom_value.value, :id => field_id\r
+ text_field 'custom_value', 'value', :name => field_name, :id => field_id\r
when "text"\r
- text_area_tag field_name, custom_value.value, :id => field_id, :cols => 60, :rows => 3\r
+ text_area 'custom_value', 'value', :name => field_name, :id => field_id, :cols => 60, :rows => 3\r
when "bool"\r
- check_box_tag(field_name, "1", custom_value.value == "1", :id => field_id) + \r
- hidden_field_tag(field_name, "0")\r
+ check_box 'custom_value', 'value', :name => field_name, :id => field_id\r
when "list"\r
- select_tag field_name, \r
- "<option></option>" + options_for_select(custom_field.possible_values.split('|'),\r
- custom_value.value), :id => field_id\r
+ select 'custom_value', 'value', custom_field.possible_values.split('|'), { :include_blank => true }, :name => field_name, :id => field_id\r
end\r
end\r
\r
+ # Return custom field label tag\r
def custom_field_label_tag(custom_value)\r
content_tag "label", custom_value.custom_field.name +\r
(custom_value.custom_field.is_required? ? " <span class=\"required\">*</span>" : ""),\r
:for => "custom_fields_#{custom_value.custom_field.id}"\r
end\r
\r
+ # Return custom field tag with its label tag\r
def custom_field_tag_with_label(custom_value)\r
case custom_value.custom_field.field_format\r
when "bool"\r
+ # label is displayed inline after the checkbox\r
custom_field_tag(custom_value) + " " + custom_field_label_tag(custom_value)\r
else\r
custom_field_label_tag(custom_value) + "<br />" + custom_field_tag(custom_value)\r
end \r
end\r
\r
+ # Return a string used to display a custom value\r
def show_value(custom_value)\r
case custom_value.custom_field.field_format\r
when "bool"\r
end \r
end\r
\r
+ # Return an array of custom field formats which can be used in select_tag\r
def custom_field_formats_for_select\r
CustomField::FIELD_FORMATS.keys.collect { |k| [ l(CustomField::FIELD_FORMATS[k]), k ] }\r
end
\r
protected\r
def validate\r
- # errors are added to customized object unless it's nil\r
- object = customized || self\r
- \r
- object.errors.add(custom_field.name, :activerecord_error_blank) if custom_field.is_required? and value.empty?\r
- object.errors.add(custom_field.name, :activerecord_error_invalid) unless custom_field.regexp.empty? or value =~ Regexp.new(custom_field.regexp)\r
-\r
- 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\r
- object.errors.add(custom_field.name, :activerecord_error_too_long) if custom_field.max_length > 0 and value.length > custom_field.max_length\r
-\r
+ errors.add(:value, :activerecord_error_blank) and return if custom_field.is_required? and value.empty? \r
+ errors.add(:value, :activerecord_error_invalid) unless custom_field.regexp.empty? or value =~ Regexp.new(custom_field.regexp)\r
+ errors.add(:value, :activerecord_error_too_short) if custom_field.min_length > 0 and value.length < custom_field.min_length and value.length > 0\r
+ errors.add(:value, :activerecord_error_too_long) if custom_field.max_length > 0 and value.length > custom_field.max_length\r
case custom_field.field_format\r
when "int"\r
- object.errors.add(custom_field.name, :activerecord_error_not_a_number) unless value =~ /^[0-9]*$/ \r
+ errors.add(:value, :activerecord_error_not_a_number) unless value =~ /^[0-9]*$/ \r
when "date"\r
- object.errors.add(custom_field.name, :activerecord_error_invalid) unless value =~ /^(\d+)\/(\d+)\/(\d+)$/ or value.empty?\r
+ errors.add(:value, :activerecord_error_invalid) unless value =~ /^(\d+)\/(\d+)\/(\d+)$/ or value.empty?\r
when "list"\r
- object.errors.add(custom_field.name, :activerecord_error_inclusion) unless custom_field.possible_values.split('|').include? value or value.empty?\r
+ errors.add(:value, :activerecord_error_inclusion) unless custom_field.possible_values.split('|').include? value or value.empty?\r
end\r
end
end\r
<p><label for="user_language"><%=l(:field_language)%></label><br/>
<%= select("user", "language", lang_options_for_select) %></p>\r
\r
-<% for custom_value in @custom_values %>
- <p><%= custom_field_tag_with_label custom_value %></p>
+<% for @custom_value in @custom_values %>
+ <p><%= custom_field_tag_with_label @custom_value %></p>
<% end %>\r
\r
<p><%= check_box 'user', 'mail_notification' %> <label for="user_mail_notification"><%=l(:field_mail_notification)%></label></p>\r
<p><label for="issue_due_date"><%=l(:field_due_date)%></label><br />
<%= date_select 'issue', 'due_date', :start_year => Date.today.year, :include_blank => true %></p>
\r
-<% for custom_value in @custom_values %>
- <p><%= custom_field_tag_with_label custom_value %></p>
+<% for @custom_value in @custom_values %>
+ <p><%= custom_field_tag_with_label @custom_value %></p>
<% end %>\r
\r
<p><label for="issue_fixed_version"><%=l(:field_fixed_version)%></label><br/>
<p><%= check_box 'project', 'is_public' %>\r
<label for="project_is_public"><%=l(:field_is_public)%></label></p>
\r
-<% for custom_value in @custom_values %>
- <p><%= custom_field_tag_with_label custom_value %></p>
+<% for @custom_value in @custom_values %>
+ <p><%= custom_field_tag_with_label @custom_value %></p>
<% end %>\r
\r
<fieldset><legend><%=l(:label_custom_field_plural)%></legend>\r
<p><label for="issue_due_date"><%=l(:field_due_date)%></label><br />
<%= date_select 'issue', 'due_date', :start_year => Date.today.year, :include_blank => true %></p>
\r
-<% for custom_value in @custom_values %>
- <p><%= custom_field_tag_with_label custom_value %></p>
+<% for @custom_value in @custom_values %>
+ <p><%= custom_field_tag_with_label @custom_value %></p>
<% end %>\r
\r
<p><label for="attachment_file"><%=l(:label_attachment)%></label><br />
<p><label for="user_language"><%=l(:field_language)%></label><br/>
<%= select("user", "language", lang_options_for_select) %></p>\r
\r
-<% for custom_value in @custom_values %>
- <p><%= custom_field_tag_with_label custom_value %></p>
+<% for @custom_value in @custom_values %>
+ <p><%= custom_field_tag_with_label @custom_value %></p>
<% end %>\r
\r
<div style="clear: both;"></div>\r