custom_value.rb
49 lines
| 1.4 KiB
| text/x-ruby
|
RubyLexer
|
r6394 | # Redmine - project management software | ||
|
r8597 | # Copyright (C) 2006-2012 Jean-Philippe Lang | ||
|
r330 | # | ||
# 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. | ||||
|
r6394 | # | ||
|
r330 | # 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. | ||||
|
r6394 | # | ||
|
r330 | # 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 | ||||
|
r8168 | def initialize(attributes=nil, *args) | ||
super | ||||
|
r2963 | if new_record? && custom_field && (customized_type.blank? || (customized && customized.new_record?)) | ||
|
r1076 | self.value ||= custom_field.default_value | ||
end | ||||
end | ||||
|
r6394 | |||
|
r1653 | # Returns true if the boolean custom value is true | ||
def true? | ||||
self.value == '1' | ||||
end | ||||
|
r6394 | |||
|
r2274 | def editable? | ||
custom_field.editable? | ||||
end | ||||
|
r6394 | |||
|
r4268 | def visible? | ||
custom_field.visible? | ||||
end | ||||
|
r6394 | |||
|
r2274 | def required? | ||
custom_field.is_required? | ||||
end | ||||
|
r6394 | |||
|
r2255 | def to_s | ||
value.to_s | ||||
end | ||||
|
r330 | end | ||