git-svn-id: http://redmine.rubyforge.org/svn/trunk@870 e93f8b46-1217-0410-a6f0-8f06a7374b81tags/0.6.0
field_id = "custom_fields_#{custom_field.id}" | field_id = "custom_fields_#{custom_field.id}" | ||||
case custom_field.field_format | case custom_field.field_format | ||||
when "string", "int" | |||||
text_field 'custom_value', 'value', :name => field_name, :id => field_id | |||||
when "date" | when "date" | ||||
text_field('custom_value', 'value', :name => field_name, :id => field_id, :size => 10) + | text_field('custom_value', 'value', :name => field_name, :id => field_id, :size => 10) + | ||||
calendar_for(field_id) | calendar_for(field_id) | ||||
check_box 'custom_value', 'value', :name => field_name, :id => field_id | check_box 'custom_value', 'value', :name => field_name, :id => field_id | ||||
when "list" | when "list" | ||||
select 'custom_value', 'value', custom_field.possible_values, { :include_blank => true }, :name => field_name, :id => field_id | select 'custom_value', 'value', custom_field.possible_values, { :include_blank => true }, :name => field_name, :id => field_id | ||||
else | |||||
text_field 'custom_value', 'value', :name => field_name, :id => field_id | |||||
end | end | ||||
end | end | ||||
FIELD_FORMATS = { "string" => { :name => :label_string, :order => 1 }, | FIELD_FORMATS = { "string" => { :name => :label_string, :order => 1 }, | ||||
"text" => { :name => :label_text, :order => 2 }, | "text" => { :name => :label_text, :order => 2 }, | ||||
"int" => { :name => :label_integer, :order => 3 }, | "int" => { :name => :label_integer, :order => 3 }, | ||||
"list" => { :name => :label_list, :order => 4 }, | |||||
"date" => { :name => :label_date, :order => 5 }, | |||||
"bool" => { :name => :label_boolean, :order => 6 } | |||||
"float" => { :name => :label_float, :order => 4 }, | |||||
"list" => { :name => :label_list, :order => 5 }, | |||||
"date" => { :name => :label_date, :order => 6 }, | |||||
"bool" => { :name => :label_boolean, :order => 7 } | |||||
}.freeze | }.freeze | ||||
validates_presence_of :name, :field_format | validates_presence_of :name, :field_format |
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_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 | 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 | case custom_field.field_format | ||||
when "int" | |||||
errors.add(:value, :activerecord_error_not_a_number) unless value =~ /^[0-9]*$/ | |||||
when "date" | |||||
when 'int' | |||||
errors.add(:value, :activerecord_error_not_a_number) unless value.blank? || value =~ /^[+-]?\d+$/ | |||||
when 'float' | |||||
begin; !value.blank? && Kernel.Float(value); rescue; errors.add(:value, :activerecord_error_invalid) end | |||||
when 'date' | |||||
errors.add(:value, :activerecord_error_not_a_date) unless value =~ /^\d{4}-\d{2}-\d{2}$/ or value.empty? | errors.add(:value, :activerecord_error_not_a_date) unless value =~ /^\d{4}-\d{2}-\d{2}$/ or value.empty? | ||||
when "list" | |||||
when 'list' | |||||
errors.add(:value, :activerecord_error_inclusion) unless custom_field.possible_values.include? value or value.empty? | errors.add(:value, :activerecord_error_inclusion) unless custom_field.possible_values.include? value or value.empty? | ||||
end | end | ||||
end | end | ||||
end | end | ||||
Element.hide(p_regexp.parentNode); | Element.hide(p_regexp.parentNode); | ||||
Element.show(p_values); | Element.show(p_values); | ||||
break; | break; | ||||
case "int": | |||||
case "string": | |||||
case "text": | |||||
Element.show(p_length.parentNode); | |||||
Element.show(p_regexp.parentNode); | |||||
Element.hide(p_values); | |||||
break; | |||||
case "date": | case "date": | ||||
case "bool": | case "bool": | ||||
Element.hide(p_length.parentNode); | Element.hide(p_length.parentNode); | ||||
default: | default: | ||||
Element.show(p_length.parentNode); | Element.show(p_length.parentNode); | ||||
Element.show(p_regexp.parentNode); | Element.show(p_regexp.parentNode); | ||||
Element.show(p_values); | |||||
Element.hide(p_values); | |||||
break; | break; | ||||
} | } | ||||
} | } |
label_user_mail_option_all: "For any event on all my projects" | label_user_mail_option_all: "For any event on all my projects" | ||||
label_user_mail_option_none: "Only for things I watch or I'm involved in" | label_user_mail_option_none: "Only for things I watch or I'm involved in" | ||||
setting_emails_footer: Emails footer | setting_emails_footer: Emails footer | ||||
label_float: Float |
label_user_mail_option_all: "For any event on all my projects" | label_user_mail_option_all: "For any event on all my projects" | ||||
label_user_mail_option_none: "Only for things I watch or I'm involved in" | label_user_mail_option_none: "Only for things I watch or I'm involved in" | ||||
setting_emails_footer: Emails footer | setting_emails_footer: Emails footer | ||||
label_float: Float |
label_user_mail_option_all: "For any event on all my projects" | label_user_mail_option_all: "For any event on all my projects" | ||||
label_user_mail_option_none: "Only for things I watch or I'm involved in" | label_user_mail_option_none: "Only for things I watch or I'm involved in" | ||||
setting_emails_footer: Emails footer | setting_emails_footer: Emails footer | ||||
label_float: Float |
label_list: List | label_list: List | ||||
label_date: Date | label_date: Date | ||||
label_integer: Integer | label_integer: Integer | ||||
label_float: Float | |||||
label_boolean: Boolean | label_boolean: Boolean | ||||
label_string: Text | label_string: Text | ||||
label_text: Long text | label_text: Long text |
label_user_mail_option_all: "For any event on all my projects" | label_user_mail_option_all: "For any event on all my projects" | ||||
label_user_mail_option_none: "Only for things I watch or I'm involved in" | label_user_mail_option_none: "Only for things I watch or I'm involved in" | ||||
setting_emails_footer: Emails footer | setting_emails_footer: Emails footer | ||||
label_float: Float |
label_list: Liste | label_list: Liste | ||||
label_date: Date | label_date: Date | ||||
label_integer: Entier | label_integer: Entier | ||||
label_float: Nombre décimal | |||||
label_boolean: Booléen | label_boolean: Booléen | ||||
label_string: Texte | label_string: Texte | ||||
label_text: Texte long | label_text: Texte long |
label_user_mail_option_all: "For any event on all my projects" | label_user_mail_option_all: "For any event on all my projects" | ||||
label_user_mail_option_none: "Only for things I watch or I'm involved in" | label_user_mail_option_none: "Only for things I watch or I'm involved in" | ||||
setting_emails_footer: Emails footer | setting_emails_footer: Emails footer | ||||
label_float: Float |
label_user_mail_option_all: "For any event on all my projects" | label_user_mail_option_all: "For any event on all my projects" | ||||
label_user_mail_option_none: "Only for things I watch or I'm involved in" | label_user_mail_option_none: "Only for things I watch or I'm involved in" | ||||
setting_emails_footer: Emails footer | setting_emails_footer: Emails footer | ||||
label_float: Float |
label_user_mail_option_all: "For any event on all my projects" | label_user_mail_option_all: "For any event on all my projects" | ||||
label_user_mail_option_none: "Only for things I watch or I'm involved in" | label_user_mail_option_none: "Only for things I watch or I'm involved in" | ||||
setting_emails_footer: Emails footer | setting_emails_footer: Emails footer | ||||
label_float: Float |
label_user_mail_option_all: "For any event on all my projects" | label_user_mail_option_all: "For any event on all my projects" | ||||
label_user_mail_option_none: "Only for things I watch or I'm involved in" | label_user_mail_option_none: "Only for things I watch or I'm involved in" | ||||
setting_emails_footer: Emails footer | setting_emails_footer: Emails footer | ||||
label_float: Float |
label_user_mail_option_all: "For any event on all my projects" | label_user_mail_option_all: "For any event on all my projects" | ||||
label_user_mail_option_none: "Only for things I watch or I'm involved in" | label_user_mail_option_none: "Only for things I watch or I'm involved in" | ||||
setting_emails_footer: Emails footer | setting_emails_footer: Emails footer | ||||
label_float: Float |
label_user_mail_option_all: "For any event on all my projects" | label_user_mail_option_all: "For any event on all my projects" | ||||
label_user_mail_option_none: "Only for things I watch or I'm involved in" | label_user_mail_option_none: "Only for things I watch or I'm involved in" | ||||
setting_emails_footer: Emails footer | setting_emails_footer: Emails footer | ||||
label_float: Float |
label_user_mail_option_all: "For any event on all my projects" | label_user_mail_option_all: "For any event on all my projects" | ||||
label_user_mail_option_none: "Only for things I watch or I'm involved in" | label_user_mail_option_none: "Only for things I watch or I'm involved in" | ||||
setting_emails_footer: Emails footer | setting_emails_footer: Emails footer | ||||
label_float: Float |
label_user_mail_option_all: "For any event on all my projects" | label_user_mail_option_all: "For any event on all my projects" | ||||
label_user_mail_option_none: "Only for things I watch or I'm involved in" | label_user_mail_option_none: "Only for things I watch or I'm involved in" | ||||
setting_emails_footer: Emails footer | setting_emails_footer: Emails footer | ||||
label_float: Float |
enumeration_issue_priorities: Prioriteti kartica | enumeration_issue_priorities: Prioriteti kartica | ||||
enumeration_doc_categories: Kategorija dokumenata | enumeration_doc_categories: Kategorija dokumenata | ||||
enumeration_activities: Aktivnosti (praćenje vremena)) | enumeration_activities: Aktivnosti (praćenje vremena)) | ||||
label_float: Float |
label_user_mail_option_all: "For any event on all my projects" | label_user_mail_option_all: "For any event on all my projects" | ||||
label_user_mail_option_none: "Only for things I watch or I'm involved in" | label_user_mail_option_none: "Only for things I watch or I'm involved in" | ||||
setting_emails_footer: Emails footer | setting_emails_footer: Emails footer | ||||
label_float: Float |
label_user_mail_option_all: "For any event on all my projects" | label_user_mail_option_all: "For any event on all my projects" | ||||
label_user_mail_option_none: "Only for things I watch or I'm involved in" | label_user_mail_option_none: "Only for things I watch or I'm involved in" | ||||
setting_emails_footer: Emails footer | setting_emails_footer: Emails footer | ||||
label_float: Float |
id: 4 | id: 4 | ||||
is_required: false | is_required: false | ||||
field_format: string | field_format: string | ||||
custom_fields_005: | |||||
name: Money | |||||
min_length: 0 | |||||
regexp: "" | |||||
is_for_all: false | |||||
type: UserCustomField | |||||
max_length: 0 | |||||
possible_values: "" | |||||
id: 5 | |||||
is_required: false | |||||
field_format: float | |||||
# redMine - project management software | |||||
# Copyright (C) 2006-2007 Jean-Philippe Lang | |||||
# | |||||
# This program is free software; you can redistribute it and/or | |||||
# modify it under the terms of the GNU General Public License | |||||
# as published by the Free Software Foundation; either version 2 | |||||
# of the License, or (at your option) any later version. | |||||
# | |||||
# This program is distributed in the hope that it will be useful, | |||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of | |||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |||||
# GNU General Public License for more details. | |||||
# | |||||
# You should have received a copy of the GNU General Public License | |||||
# along with this program; if not, write to the Free Software | |||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | |||||
require File.dirname(__FILE__) + '/../test_helper' | |||||
class CustomFieldTest < Test::Unit::TestCase | |||||
fixtures :custom_fields | |||||
def test_create | |||||
field = UserCustomField.new(:name => 'Money money money', :field_format => 'float') | |||||
assert field.save | |||||
end | |||||
def test_destroy | |||||
field = CustomField.find(1) | |||||
assert field.destroy | |||||
end | |||||
end |
# redMine - project management software | |||||
# Copyright (C) 2006-2007 Jean-Philippe Lang | |||||
# | |||||
# This program is free software; you can redistribute it and/or | |||||
# modify it under the terms of the GNU General Public License | |||||
# as published by the Free Software Foundation; either version 2 | |||||
# of the License, or (at your option) any later version. | |||||
# | |||||
# This program is distributed in the hope that it will be useful, | |||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of | |||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |||||
# GNU General Public License for more details. | |||||
# | |||||
# You should have received a copy of the GNU General Public License | |||||
# along with this program; if not, write to the Free Software | |||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | |||||
require File.dirname(__FILE__) + '/../test_helper' | |||||
class CustomValueTest < Test::Unit::TestCase | |||||
fixtures :custom_fields | |||||
def test_float_field | |||||
v = CustomValue.new(:customized => User.find(:first), :custom_field => UserCustomField.find_by_name('Money')) | |||||
v.value = '11.2' | |||||
assert v.save | |||||
v.value = '' | |||||
assert v.save | |||||
v.value = '-6.250' | |||||
assert v.save | |||||
v.value = '6a' | |||||
assert !v.save | |||||
end | |||||
end |