field_id = "custom_fields_#{custom_field.id}"
case custom_field.field_format
- when "string", "int"
- text_field 'custom_value', 'value', :name => field_name, :id => field_id
when "date"
text_field('custom_value', 'value', :name => field_name, :id => field_id, :size => 10) +
calendar_for(field_id)
check_box 'custom_value', 'value', :name => field_name, :id => field_id
when "list"
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
FIELD_FORMATS = { "string" => { :name => :label_string, :order => 1 },
"text" => { :name => :label_text, :order => 2 },
"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
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_long) if custom_field.max_length > 0 and value.length > custom_field.max_length
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?
- when "list"
+ when 'list'
errors.add(:value, :activerecord_error_inclusion) unless custom_field.possible_values.include? value or value.empty?
end
end
end
-
Element.hide(p_regexp.parentNode);
Element.show(p_values);
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 "bool":
Element.hide(p_length.parentNode);
default:
Element.show(p_length.parentNode);
Element.show(p_regexp.parentNode);
- Element.show(p_values);
+ Element.hide(p_values);
break;
}
}
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"
setting_emails_footer: Emails footer
+label_float: Float
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"
setting_emails_footer: Emails footer
+label_float: Float
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"
setting_emails_footer: Emails footer
+label_float: Float
label_list: List
label_date: Date
label_integer: Integer
+label_float: Float
label_boolean: Boolean
label_string: Text
label_text: Long text
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"
setting_emails_footer: Emails footer
+label_float: Float
label_list: Liste
label_date: Date
label_integer: Entier
+label_float: Nombre décimal
label_boolean: Booléen
label_string: Texte
label_text: Texte long
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"
setting_emails_footer: Emails footer
+label_float: Float
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"
setting_emails_footer: Emails footer
+label_float: Float
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"
setting_emails_footer: Emails footer
+label_float: Float
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"
setting_emails_footer: Emails footer
+label_float: Float
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"
setting_emails_footer: Emails footer
+label_float: Float
label_user_mail_option_all: "For any event on all my projects"\r
label_user_mail_option_none: "Only for things I watch or I'm involved in"\r
setting_emails_footer: Emails footer\r
+label_float: Float\r
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"
setting_emails_footer: Emails footer
+label_float: Float
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"
setting_emails_footer: Emails footer
+label_float: Float
enumeration_issue_priorities: Prioriteti kartica
enumeration_doc_categories: Kategorija dokumenata
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_none: "Only for things I watch or I'm involved in"
setting_emails_footer: Emails footer
+label_float: Float
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"
setting_emails_footer: Emails footer
+label_float: Float
id: 4\r
is_required: false\r
field_format: string\r
+custom_fields_005: \r
+ name: Money\r
+ min_length: 0\r
+ regexp: ""\r
+ is_for_all: false\r
+ type: UserCustomField\r
+ max_length: 0\r
+ possible_values: ""\r
+ id: 5\r
+ is_required: false\r
+ field_format: float\r
+
\ No newline at end of file
--- /dev/null
+# 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
--- /dev/null
+# 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