custom field tags
git-svn-id: http://redmine.rubyforge.org/svn/trunk@20 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
parent
d2b89f5f9b
commit
54aeec7b5f
@ -80,7 +80,7 @@ class ProjectsController < ApplicationController
|
|||||||
@member ||= @project.members.new
|
@member ||= @project.members.new
|
||||||
@roles = Role.find_all
|
@roles = Role.find_all
|
||||||
@users = User.find_all - @project.members.find(:all, :include => :user).collect{|m| m.user }
|
@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
|
end
|
||||||
|
|
||||||
# Edit @project
|
# Edit @project
|
||||||
|
@ -17,16 +17,17 @@
|
|||||||
|
|
||||||
module ApplicationHelper
|
module ApplicationHelper
|
||||||
|
|
||||||
# return current logged in user or nil
|
# Return current logged in user or nil
|
||||||
def loggedin?
|
def loggedin?
|
||||||
@logged_in_user
|
@logged_in_user
|
||||||
end
|
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?
|
def admin_loggedin?
|
||||||
@logged_in_user and @logged_in_user.admin?
|
@logged_in_user and @logged_in_user.admin?
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Return true if user is authorized for controller/action, otherwise false
|
||||||
def authorize_for(controller, action)
|
def authorize_for(controller, action)
|
||||||
# check if action is allowed on public projects
|
# check if action is allowed on public projects
|
||||||
if @project.is_public? and Permission.allowed_to_public "%s/%s" % [ controller, action ]
|
if @project.is_public? and Permission.allowed_to_public "%s/%s" % [ controller, action ]
|
||||||
@ -76,12 +77,21 @@ module ApplicationHelper
|
|||||||
if attr == "base"
|
if attr == "base"
|
||||||
full_messages << l(msg)
|
full_messages << l(msg)
|
||||||
else
|
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
|
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("div",
|
||||||
content_tag(
|
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) }),
|
content_tag("ul", full_messages.collect { |msg| content_tag("li", msg) }),
|
||||||
"id" => options[:id] || "errorExplanation", "class" => options[:class] || "errorExplanation"
|
"id" => options[:id] || "errorExplanation", "class" => options[:class] || "errorExplanation"
|
||||||
|
@ -17,6 +17,7 @@
|
|||||||
|
|
||||||
module CustomFieldsHelper
|
module CustomFieldsHelper
|
||||||
|
|
||||||
|
# Return custom field html tag corresponding to its format
|
||||||
def custom_field_tag(custom_value)
|
def custom_field_tag(custom_value)
|
||||||
custom_field = custom_value.custom_field
|
custom_field = custom_value.custom_field
|
||||||
field_name = "custom_fields[#{custom_field.id}]"
|
field_name = "custom_fields[#{custom_field.id}]"
|
||||||
@ -24,34 +25,35 @@ module CustomFieldsHelper
|
|||||||
|
|
||||||
case custom_field.field_format
|
case custom_field.field_format
|
||||||
when "string", "int", "date"
|
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"
|
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"
|
when "bool"
|
||||||
check_box_tag(field_name, "1", custom_value.value == "1", :id => field_id) +
|
check_box 'custom_value', 'value', :name => field_name, :id => field_id
|
||||||
hidden_field_tag(field_name, "0")
|
|
||||||
when "list"
|
when "list"
|
||||||
select_tag field_name,
|
select 'custom_value', 'value', custom_field.possible_values.split('|'), { :include_blank => true }, :name => field_name, :id => field_id
|
||||||
"<option></option>" + options_for_select(custom_field.possible_values.split('|'),
|
|
||||||
custom_value.value), :id => field_id
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Return custom field label tag
|
||||||
def custom_field_label_tag(custom_value)
|
def custom_field_label_tag(custom_value)
|
||||||
content_tag "label", custom_value.custom_field.name +
|
content_tag "label", custom_value.custom_field.name +
|
||||||
(custom_value.custom_field.is_required? ? " <span class=\"required\">*</span>" : ""),
|
(custom_value.custom_field.is_required? ? " <span class=\"required\">*</span>" : ""),
|
||||||
:for => "custom_fields_#{custom_value.custom_field.id}"
|
:for => "custom_fields_#{custom_value.custom_field.id}"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Return custom field tag with its label tag
|
||||||
def custom_field_tag_with_label(custom_value)
|
def custom_field_tag_with_label(custom_value)
|
||||||
case custom_value.custom_field.field_format
|
case custom_value.custom_field.field_format
|
||||||
when "bool"
|
when "bool"
|
||||||
|
# label is displayed inline after the checkbox
|
||||||
custom_field_tag(custom_value) + " " + custom_field_label_tag(custom_value)
|
custom_field_tag(custom_value) + " " + custom_field_label_tag(custom_value)
|
||||||
else
|
else
|
||||||
custom_field_label_tag(custom_value) + "<br />" + custom_field_tag(custom_value)
|
custom_field_label_tag(custom_value) + "<br />" + custom_field_tag(custom_value)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Return a string used to display a custom value
|
||||||
def show_value(custom_value)
|
def show_value(custom_value)
|
||||||
case custom_value.custom_field.field_format
|
case custom_value.custom_field.field_format
|
||||||
when "bool"
|
when "bool"
|
||||||
@ -61,6 +63,7 @@ module CustomFieldsHelper
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Return an array of custom field formats which can be used in select_tag
|
||||||
def custom_field_formats_for_select
|
def custom_field_formats_for_select
|
||||||
CustomField::FIELD_FORMATS.keys.collect { |k| [ l(CustomField::FIELD_FORMATS[k]), k ] }
|
CustomField::FIELD_FORMATS.keys.collect { |k| [ l(CustomField::FIELD_FORMATS[k]), k ] }
|
||||||
end
|
end
|
||||||
|
@ -21,22 +21,17 @@ class CustomValue < ActiveRecord::Base
|
|||||||
|
|
||||||
protected
|
protected
|
||||||
def validate
|
def validate
|
||||||
# errors are added to customized object unless it's nil
|
errors.add(:value, :activerecord_error_blank) and return if custom_field.is_required? and value.empty?
|
||||||
object = customized || self
|
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
|
||||||
object.errors.add(custom_field.name, :activerecord_error_blank) if custom_field.is_required? and value.empty?
|
errors.add(:value, :activerecord_error_too_long) if custom_field.max_length > 0 and value.length > custom_field.max_length
|
||||||
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
|
|
||||||
|
|
||||||
case custom_field.field_format
|
case custom_field.field_format
|
||||||
when "int"
|
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"
|
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"
|
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
|
end
|
||||||
end
|
end
|
||||||
|
@ -26,8 +26,8 @@
|
|||||||
<p><label for="user_language"><%=l(:field_language)%></label><br/>
|
<p><label for="user_language"><%=l(:field_language)%></label><br/>
|
||||||
<%= select("user", "language", lang_options_for_select) %></p>
|
<%= select("user", "language", lang_options_for_select) %></p>
|
||||||
|
|
||||||
<% for custom_value in @custom_values %>
|
<% for @custom_value in @custom_values %>
|
||||||
<p><%= custom_field_tag_with_label custom_value %></p>
|
<p><%= custom_field_tag_with_label @custom_value %></p>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|
||||||
<p><%= check_box 'user', 'mail_notification' %> <label for="user_mail_notification"><%=l(:field_mail_notification)%></label></p>
|
<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 />
|
<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>
|
<%= date_select 'issue', 'due_date', :start_year => Date.today.year, :include_blank => true %></p>
|
||||||
|
|
||||||
<% for custom_value in @custom_values %>
|
<% for @custom_value in @custom_values %>
|
||||||
<p><%= custom_field_tag_with_label custom_value %></p>
|
<p><%= custom_field_tag_with_label @custom_value %></p>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|
||||||
<p><label for="issue_fixed_version"><%=l(:field_fixed_version)%></label><br/>
|
<p><label for="issue_fixed_version"><%=l(:field_fixed_version)%></label><br/>
|
||||||
|
@ -22,8 +22,8 @@
|
|||||||
<p><%= check_box 'project', 'is_public' %>
|
<p><%= check_box 'project', 'is_public' %>
|
||||||
<label for="project_is_public"><%=l(:field_is_public)%></label></p>
|
<label for="project_is_public"><%=l(:field_is_public)%></label></p>
|
||||||
|
|
||||||
<% for custom_value in @custom_values %>
|
<% for @custom_value in @custom_values %>
|
||||||
<p><%= custom_field_tag_with_label custom_value %></p>
|
<p><%= custom_field_tag_with_label @custom_value %></p>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|
||||||
<fieldset><legend><%=l(:label_custom_field_plural)%></legend>
|
<fieldset><legend><%=l(:label_custom_field_plural)%></legend>
|
||||||
|
@ -39,8 +39,8 @@
|
|||||||
<p><label for="issue_due_date"><%=l(:field_due_date)%></label><br />
|
<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>
|
<%= date_select 'issue', 'due_date', :start_year => Date.today.year, :include_blank => true %></p>
|
||||||
|
|
||||||
<% for custom_value in @custom_values %>
|
<% for @custom_value in @custom_values %>
|
||||||
<p><%= custom_field_tag_with_label custom_value %></p>
|
<p><%= custom_field_tag_with_label @custom_value %></p>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|
||||||
<p><label for="attachment_file"><%=l(:label_attachment)%></label><br />
|
<p><label for="attachment_file"><%=l(:label_attachment)%></label><br />
|
||||||
|
@ -23,8 +23,8 @@
|
|||||||
<p><label for="user_language"><%=l(:field_language)%></label><br/>
|
<p><label for="user_language"><%=l(:field_language)%></label><br/>
|
||||||
<%= select("user", "language", lang_options_for_select) %></p>
|
<%= select("user", "language", lang_options_for_select) %></p>
|
||||||
|
|
||||||
<% for custom_value in @custom_values %>
|
<% for @custom_value in @custom_values %>
|
||||||
<p><%= custom_field_tag_with_label custom_value %></p>
|
<p><%= custom_field_tag_with_label @custom_value %></p>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|
||||||
<div style="clear: both;"></div>
|
<div style="clear: both;"></div>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user