git-svn-id: http://redmine.rubyforge.org/svn/trunk@20 e93f8b46-1217-0410-a6f0-8f06a7374b81tags/0.3.0
@@ -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 |
@@ -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" |
@@ -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, | |||
"<option></option>" + 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? ? " <span class=\"required\">*</span>" : ""), | |||
: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) + "<br />" + 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 |
@@ -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 |
@@ -26,8 +26,8 @@ | |||
<p><label for="user_language"><%=l(:field_language)%></label><br/> | |||
<%= select("user", "language", lang_options_for_select) %></p> | |||
<% 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 %> | |||
<p><%= check_box 'user', 'mail_notification' %> <label for="user_mail_notification"><%=l(:field_mail_notification)%></label></p> |
@@ -39,8 +39,8 @@ | |||
<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> | |||
<% 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 %> | |||
<p><label for="issue_fixed_version"><%=l(:field_fixed_version)%></label><br/> |
@@ -22,8 +22,8 @@ | |||
<p><%= check_box 'project', 'is_public' %> | |||
<label for="project_is_public"><%=l(:field_is_public)%></label></p> | |||
<% 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 %> | |||
<fieldset><legend><%=l(:label_custom_field_plural)%></legend> |
@@ -39,8 +39,8 @@ | |||
<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> | |||
<% 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 %> | |||
<p><label for="attachment_file"><%=l(:label_attachment)%></label><br /> |
@@ -23,8 +23,8 @@ | |||
<p><label for="user_language"><%=l(:field_language)%></label><br/> | |||
<%= select("user", "language", lang_options_for_select) %></p> | |||
<% 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 %> | |||
<div style="clear: both;"></div> |