summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJean-Philippe Lang <jp_lang@yahoo.fr>2007-10-25 17:38:05 +0000
committerJean-Philippe Lang <jp_lang@yahoo.fr>2007-10-25 17:38:05 +0000
commit8610b191ae1a40ff58e90a1225d79c893a49b0d6 (patch)
tree33b98bcfe7d2fd1407602831794f3a05eff588c5
parent01ef9f12c816fab283ebc7d96283abd3397c61c8 (diff)
downloadredmine-8610b191ae1a40ff58e90a1225d79c893a49b0d6.tar.gz
redmine-8610b191ae1a40ff58e90a1225d79c893a49b0d6.zip
Added "Float" as a custom field format.
git-svn-id: http://redmine.rubyforge.org/svn/trunk@870 e93f8b46-1217-0410-a6f0-8f06a7374b81
-rw-r--r--app/helpers/custom_fields_helper.rb4
-rw-r--r--app/models/custom_field.rb7
-rw-r--r--app/models/custom_value.rb11
-rw-r--r--app/views/custom_fields/_form.rhtml9
-rw-r--r--lang/bg.yml1
-rw-r--r--lang/cs.yml1
-rw-r--r--lang/de.yml1
-rw-r--r--lang/en.yml1
-rw-r--r--lang/es.yml1
-rw-r--r--lang/fr.yml1
-rw-r--r--lang/he.yml1
-rw-r--r--lang/it.yml1
-rw-r--r--lang/ja.yml1
-rw-r--r--lang/nl.yml1
-rw-r--r--lang/pl.yml1
-rw-r--r--lang/pt-br.yml1
-rw-r--r--lang/pt.yml1
-rw-r--r--lang/ro.yml1
-rw-r--r--lang/sr.yml1
-rw-r--r--lang/sv.yml1
-rw-r--r--lang/zh.yml1
-rw-r--r--test/fixtures/custom_fields.yml12
-rw-r--r--test/unit/custom_field_test.rb32
-rw-r--r--test/unit/custom_value_test.rb34
24 files changed, 108 insertions, 18 deletions
diff --git a/app/helpers/custom_fields_helper.rb b/app/helpers/custom_fields_helper.rb
index d6dc586c4..b1b176107 100644
--- a/app/helpers/custom_fields_helper.rb
+++ b/app/helpers/custom_fields_helper.rb
@@ -24,8 +24,6 @@ module CustomFieldsHelper
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)
@@ -35,6 +33,8 @@ module CustomFieldsHelper
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
diff --git a/app/models/custom_field.rb b/app/models/custom_field.rb
index 751cc8526..81c8aae06 100644
--- a/app/models/custom_field.rb
+++ b/app/models/custom_field.rb
@@ -22,9 +22,10 @@ class CustomField < ActiveRecord::Base
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
diff --git a/app/models/custom_value.rb b/app/models/custom_value.rb
index 6cc4d16bf..afe4c1afb 100644
--- a/app/models/custom_value.rb
+++ b/app/models/custom_value.rb
@@ -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_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
-
diff --git a/app/views/custom_fields/_form.rhtml b/app/views/custom_fields/_form.rhtml
index 32269e3f0..013be9b70 100644
--- a/app/views/custom_fields/_form.rhtml
+++ b/app/views/custom_fields/_form.rhtml
@@ -13,13 +13,6 @@ function toggle_custom_field_format() {
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);
@@ -29,7 +22,7 @@ function toggle_custom_field_format() {
default:
Element.show(p_length.parentNode);
Element.show(p_regexp.parentNode);
- Element.show(p_values);
+ Element.hide(p_values);
break;
}
}
diff --git a/lang/bg.yml b/lang/bg.yml
index 0b333e488..c9e5a69b2 100644
--- a/lang/bg.yml
+++ b/lang/bg.yml
@@ -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_none: "Only for things I watch or I'm involved in"
setting_emails_footer: Emails footer
+label_float: Float
diff --git a/lang/cs.yml b/lang/cs.yml
index e947b1172..f885359fc 100644
--- a/lang/cs.yml
+++ b/lang/cs.yml
@@ -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_none: "Only for things I watch or I'm involved in"
setting_emails_footer: Emails footer
+label_float: Float
diff --git a/lang/de.yml b/lang/de.yml
index 93190fb73..9649902e7 100644
--- a/lang/de.yml
+++ b/lang/de.yml
@@ -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_none: "Only for things I watch or I'm involved in"
setting_emails_footer: Emails footer
+label_float: Float
diff --git a/lang/en.yml b/lang/en.yml
index 88cbcd730..ec0ee3077 100644
--- a/lang/en.yml
+++ b/lang/en.yml
@@ -259,6 +259,7 @@ label_min_max_length: Min - Max length
label_list: List
label_date: Date
label_integer: Integer
+label_float: Float
label_boolean: Boolean
label_string: Text
label_text: Long text
diff --git a/lang/es.yml b/lang/es.yml
index f55d5849e..4df3e6541 100644
--- a/lang/es.yml
+++ b/lang/es.yml
@@ -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_none: "Only for things I watch or I'm involved in"
setting_emails_footer: Emails footer
+label_float: Float
diff --git a/lang/fr.yml b/lang/fr.yml
index 70b603687..0aeed308b 100644
--- a/lang/fr.yml
+++ b/lang/fr.yml
@@ -259,6 +259,7 @@ label_min_max_length: Longueurs mini - maxi
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
diff --git a/lang/he.yml b/lang/he.yml
index 8cefd127f..dcb9c82f4 100644
--- a/lang/he.yml
+++ b/lang/he.yml
@@ -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_none: "Only for things I watch or I'm involved in"
setting_emails_footer: Emails footer
+label_float: Float
diff --git a/lang/it.yml b/lang/it.yml
index 840d298f7..661d1ef20 100644
--- a/lang/it.yml
+++ b/lang/it.yml
@@ -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_none: "Only for things I watch or I'm involved in"
setting_emails_footer: Emails footer
+label_float: Float
diff --git a/lang/ja.yml b/lang/ja.yml
index fc42cee52..da4c3530f 100644
--- a/lang/ja.yml
+++ b/lang/ja.yml
@@ -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_none: "Only for things I watch or I'm involved in"
setting_emails_footer: Emails footer
+label_float: Float
diff --git a/lang/nl.yml b/lang/nl.yml
index fc6d9bbeb..d4b6889ed 100644
--- a/lang/nl.yml
+++ b/lang/nl.yml
@@ -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_none: "Only for things I watch or I'm involved in"
setting_emails_footer: Emails footer
+label_float: Float
diff --git a/lang/pl.yml b/lang/pl.yml
index 4565b2576..95b416197 100644
--- a/lang/pl.yml
+++ b/lang/pl.yml
@@ -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_none: "Only for things I watch or I'm involved in"
setting_emails_footer: Emails footer
+label_float: Float
diff --git a/lang/pt-br.yml b/lang/pt-br.yml
index 942de55ae..650c6ebb9 100644
--- a/lang/pt-br.yml
+++ b/lang/pt-br.yml
@@ -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_none: "Only for things I watch or I'm involved in"
setting_emails_footer: Emails footer
+label_float: Float
diff --git a/lang/pt.yml b/lang/pt.yml
index 49176d607..2bdb57198 100644
--- a/lang/pt.yml
+++ b/lang/pt.yml
@@ -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_none: "Only for things I watch or I'm involved in"
setting_emails_footer: Emails footer
+label_float: Float
diff --git a/lang/ro.yml b/lang/ro.yml
index 8e7b8a2bf..0ef3a9027 100644
--- a/lang/ro.yml
+++ b/lang/ro.yml
@@ -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_none: "Only for things I watch or I'm involved in"
setting_emails_footer: Emails footer
+label_float: Float
diff --git a/lang/sr.yml b/lang/sr.yml
index d65225319..983798fbe 100644
--- a/lang/sr.yml
+++ b/lang/sr.yml
@@ -533,3 +533,4 @@ default_activity_development: Razvoj
enumeration_issue_priorities: Prioriteti kartica
enumeration_doc_categories: Kategorija dokumenata
enumeration_activities: Aktivnosti (praćenje vremena))
+label_float: Float
diff --git a/lang/sv.yml b/lang/sv.yml
index 878eb1441..72355c3bb 100644
--- a/lang/sv.yml
+++ b/lang/sv.yml
@@ -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_none: "Only for things I watch or I'm involved in"
setting_emails_footer: Emails footer
+label_float: Float
diff --git a/lang/zh.yml b/lang/zh.yml
index 34e56ea37..7d276ab4c 100644
--- a/lang/zh.yml
+++ b/lang/zh.yml
@@ -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_none: "Only for things I watch or I'm involved in"
setting_emails_footer: Emails footer
+label_float: Float
diff --git a/test/fixtures/custom_fields.yml b/test/fixtures/custom_fields.yml
index fcf52c17a..ce7509fe9 100644
--- a/test/fixtures/custom_fields.yml
+++ b/test/fixtures/custom_fields.yml
@@ -43,3 +43,15 @@ custom_fields_004:
id: 4
is_required: false
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
+ \ No newline at end of file
diff --git a/test/unit/custom_field_test.rb b/test/unit/custom_field_test.rb
new file mode 100644
index 000000000..1b9c9aea9
--- /dev/null
+++ b/test/unit/custom_field_test.rb
@@ -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
diff --git a/test/unit/custom_value_test.rb b/test/unit/custom_value_test.rb
new file mode 100644
index 000000000..24d09fe49
--- /dev/null
+++ b/test/unit/custom_value_test.rb
@@ -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