Added "Float" as a custom field format.

git-svn-id: http://redmine.rubyforge.org/svn/trunk@870 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
Jean-Philippe Lang 2007-10-25 17:38:05 +00:00
parent 01ef9f12c8
commit 8610b191ae
24 changed files with 108 additions and 18 deletions

View File

@ -24,8 +24,6 @@ module CustomFieldsHelper
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)
@ -35,6 +33,8 @@ module CustomFieldsHelper
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

View File

@ -22,9 +22,10 @@ class CustomField < ActiveRecord::Base
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 }, "float" => { :name => :label_float, :order => 4 },
"date" => { :name => :label_date, :order => 5 }, "list" => { :name => :label_list, :order => 5 },
"bool" => { :name => :label_boolean, :order => 6 } "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

View File

@ -26,13 +26,14 @@ protected
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" when 'int'
errors.add(:value, :activerecord_error_not_a_number) unless value =~ /^[0-9]*$/ errors.add(:value, :activerecord_error_not_a_number) unless value.blank? || value =~ /^[+-]?\d+$/
when "date" 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

View File

@ -13,13 +13,6 @@ function toggle_custom_field_format() {
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);
@ -29,7 +22,7 @@ function toggle_custom_field_format() {
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;
} }
} }

View File

@ -532,3 +532,4 @@ label_user_mail_option_selected: "For any event on the selected projects only...
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

View File

@ -532,3 +532,4 @@ label_user_mail_option_selected: "For any event on the selected projects only...
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

View File

@ -532,3 +532,4 @@ label_user_mail_option_selected: "For any event on the selected projects only...
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

View File

@ -259,6 +259,7 @@ label_min_max_length: Min - Max length
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

View File

@ -535,3 +535,4 @@ label_user_mail_option_selected: "For any event on the selected projects only...
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

View File

@ -259,6 +259,7 @@ label_min_max_length: Longueurs mini - maxi
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

View File

@ -532,3 +532,4 @@ label_user_mail_option_selected: "For any event on the selected projects only...
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

View File

@ -532,3 +532,4 @@ label_user_mail_option_selected: "For any event on the selected projects only...
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

View File

@ -533,3 +533,4 @@ label_user_mail_option_selected: "For any event on the selected projects only...
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

View File

@ -533,3 +533,4 @@ label_user_mail_option_selected: "For any event on the selected projects only...
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

View File

@ -532,3 +532,4 @@ label_user_mail_option_selected: "For any event on the selected projects only...
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

View File

@ -532,3 +532,4 @@ label_user_mail_option_selected: "For any event on the selected projects only...
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

View File

@ -532,3 +532,4 @@ label_user_mail_option_selected: "For any event on the selected projects only...
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

View File

@ -532,3 +532,4 @@ label_user_mail_option_selected: "For any event on the selected projects only...
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

View File

@ -533,3 +533,4 @@ default_activity_development: Razvoj
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

View File

@ -533,3 +533,4 @@ label_user_mail_option_selected: "For any event on the selected projects only...
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

View File

@ -535,3 +535,4 @@ label_user_mail_option_selected: "For any event on the selected projects only...
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

View File

@ -43,3 +43,15 @@ custom_fields_004:
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

View File

@ -0,0 +1,32 @@
# 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

View File

@ -0,0 +1,34 @@
# 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