##// END OF EJS Templates
r18633@gaspard (orig r1875): jplang | 2008-09-17 21:18:31 +0200...
r18633@gaspard (orig r1875): jplang | 2008-09-17 21:18:31 +0200 reposman: change #log arguments. r18634@gaspard (orig r1876): jplang | 2008-09-17 21:38:20 +0200 Slight change on git repository creation command. r18635@gaspard (orig r1877): jplang | 2008-09-17 21:47:36 +0200 Make --command option usable on Windows. r18636@gaspard (orig r1878): jplang | 2008-09-19 17:32:52 +0200 Adds watch/unwatch functionality at forum topic level (#1912). Users who create/reply a topic are automatically added as watchers but are now able to unwatch the topic. r18637@gaspard (orig r1879): winterheart | 2008-09-19 18:15:49 +0200 update of ru.yml r18638@gaspard (orig r1880): winterheart | 2008-09-19 18:17:35 +0200 #1918, translation for zh-tw r18639@gaspard (orig r1881): winterheart | 2008-09-19 18:20:45 +0200 fixed #1920, patch for Hungarian language r18640@gaspard (orig r1882): winterheart | 2008-09-19 18:23:04 +0200 patch #1922, update for nl.yml r18641@gaspard (orig r1883): winterheart | 2008-09-19 18:26:19 +0200 #1923, updated zh.yml r18642@gaspard (orig r1884): winterheart | 2008-09-19 18:30:39 +0200 #1924, update for da.yml r18643@gaspard (orig r1885): winterheart | 2008-09-19 18:33:08 +0200 #1925, patch for lt.yml git-svn-id: http://redmine.rubyforge.org/svn/branches/nbc@1886 e93f8b46-1217-0410-a6f0-8f06a7374b81

File last commit:

r1653:025581bb284a
r1884:d8549c55411a
Show More
custom_value.rb
55 lines | 2.3 KiB | text/x-ruby | RubyLexer
# redMine - project management software
# Copyright (C) 2006 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.
class CustomValue < ActiveRecord::Base
belongs_to :custom_field
belongs_to :customized, :polymorphic => true
def after_initialize
if custom_field && new_record? && (customized_type.blank? || (customized && customized.new_record?))
self.value ||= custom_field.default_value
end
end
# Returns true if the boolean custom value is true
def true?
self.value == '1'
end
protected
def validate
if value.blank?
errors.add(:value, :activerecord_error_blank) if custom_field.is_required? and value.blank?
else
errors.add(:value, :activerecord_error_invalid) unless custom_field.regexp.blank? 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
errors.add(:value, :activerecord_error_too_long) if custom_field.max_length > 0 and value.length > custom_field.max_length
# Format specific validations
case custom_field.field_format
when 'int'
errors.add(:value, :activerecord_error_not_a_number) unless value =~ /^[+-]?\d+$/
when 'float'
begin; 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}$/
when 'list'
errors.add(:value, :activerecord_error_inclusion) unless custom_field.possible_values.include?(value)
end
end
end
end