Permalink
Browse files

Add person to samples

  • Loading branch information...
1 parent 6cdfa36 commit a48b48cd1e3cfeee936bbd2cfb36310507e6e826 Egils Mūzis committed May 19, 2011
Showing with 23 additions and 1 deletion.
  1. +7 −0 app/models/person.rb
  2. +11 −1 app/models/sample.rb
  3. +4 −0 app/views/samples/new.html.erb
  4. +1 −0 public/stylesheets/base.css
View
@@ -4,6 +4,7 @@ class Person
include Mongoid::Search
field :first_name
field :last_name
+ field :full_name
field :date_of_birth
field :diagnosed_at
field :age_at_diagnosis
@@ -15,6 +16,8 @@ class Person
validates_uniqueness_of :social_number
validates_presence_of :first_name, :last_name, :date_of_birth, :social_number
+ before_save :add_full_name
+
embeds_many :used_people_attribute_groups, :dependent => :destroy
accepts_nested_attributes_for :used_people_attribute_groups,
:reject_if => lambda {|a| a[:alternate_name].blank? }, :allow_destroy => true
@@ -32,6 +35,10 @@ def people_attribute_values
private
+ def add_full_name
+ self.full_name = "#{first_name} #{last_name}"
+ end
+
def validate_date_correctivness
if (!date_of_birth.blank? && (Date.parse(date_of_birth) rescue ArgumentError) == ArgumentError)
errors.add(:date_of_birth, "ir nekorekts datums")
View
@@ -6,7 +6,11 @@ class Sample
field :alternate_code
field :person_id
- validates_uniqueness_of :code, :alternate_code
+ attr_accessor :person_name
+
+ before_validation :add_person
+
+ validates_uniqueness_of :code, :alternate_code, :allow_blank => true
validates_presence_of :code
belongs_to :person
@@ -25,4 +29,10 @@ def sample_attribute_values
used_sample_attribute_groups.map{|p|p.sample_attribute_values}.flatten
end
+ private
+
+ def add_person
+ self.person_id = Person.where(:full_name => person_name).first.try(:id)
+ end
+
end
@@ -15,6 +15,10 @@
<%= f.label :alternate_code, "Papildus kods" %>
<%= f.text_field :alternate_code %>
</div>
+ <div class="form_field">
+ <%= f.label :person_name, "Persona" %>
+ <%= f.text_field :person_name, :value => f.object.person.try(:full_name) %>
+ </div>
<div class="attribute_groups" id="sortable">
<% @sample.ordered_attribute_groups.each do |o| %>
@@ -214,6 +214,7 @@ div.form_field {
}
div.form_field input {
height: 12px;
+ margin-left:0;
}
div.form_field label {
padding: 7px;

0 comments on commit a48b48c

Please sign in to comment.