scinote-web/app/models/custom_field.rb

35 lines
1.4 KiB
Ruby
Raw Normal View History

2016-02-12 23:52:43 +08:00
class CustomField < ActiveRecord::Base
auto_strip_attributes :name, nullify: false
2016-02-12 23:52:43 +08:00
validates :name,
presence: true,
length: { maximum: Constants::NAME_MAX_LENGTH },
uniqueness: { scope: :organization, case_sensitive: true },
exclusion: { in: ['Assigned', 'Sample name', 'Sample type',
'Sample group', 'Added on', 'Added by'] }
2016-02-12 23:52:43 +08:00
validates :user, :organization, presence: true
belongs_to :user, inverse_of: :custom_fields
belongs_to :organization, inverse_of: :custom_fields
belongs_to :last_modified_by,
foreign_key: 'last_modified_by_id',
class_name: 'User'
2016-02-12 23:52:43 +08:00
has_many :sample_custom_fields, inverse_of: :custom_field
2016-12-07 23:57:17 +08:00
def self.create(opt)
user = opt[:user]
org = opt[:organization]
samples_table = SamplesTable.where(user: user,
organization: org)
org_status = samples_table.first['status']
index = org_status['columns'].count
org_status['columns'][index] = { 'visible' => true,
'search' => { 'search' => '',
'smart' => true,
'regex' => false,
'caseInsensitive' => true } }
org_status['ColReorder'] << index
samples_table.first.update(status: org_status)
super(opt)
end
2016-02-12 23:52:43 +08:00
end