|
|
@ -1,6 +1,6 @@ |
|
|
|
class CaseLogValidator < ActiveModel::Validator |
|
|
|
class CaseLogValidator < ActiveModel::Validator |
|
|
|
# Validations methods need to be called 'validate_<page_name>' to run on model save |
|
|
|
# Validations methods need to be called 'validate_' to run on model save |
|
|
|
# or 'validate_' to run on submit as well |
|
|
|
# or form page submission |
|
|
|
include HouseholdValidations |
|
|
|
include HouseholdValidations |
|
|
|
include PropertyValidations |
|
|
|
include PropertyValidations |
|
|
|
include FinancialValidations |
|
|
|
include FinancialValidations |
|
|
@ -8,16 +8,8 @@ class CaseLogValidator < ActiveModel::Validator |
|
|
|
include DateValidations |
|
|
|
include DateValidations |
|
|
|
|
|
|
|
|
|
|
|
def validate(record) |
|
|
|
def validate(record) |
|
|
|
# If we've come from the form UI we only want to validate the specific fields |
|
|
|
validation_methods = public_methods.select { |method| method.starts_with?("validate_") } |
|
|
|
# that have just been submitted. If we're submitting a log via API or Bulk Upload |
|
|
|
validation_methods.each { |meth| public_send(meth, record) } |
|
|
|
# we want to validate all data fields. |
|
|
|
|
|
|
|
page_to_validate = record.page_id |
|
|
|
|
|
|
|
if page_to_validate |
|
|
|
|
|
|
|
public_send("validate_#{page_to_validate}", record) if respond_to?("validate_#{page_to_validate}") |
|
|
|
|
|
|
|
else |
|
|
|
|
|
|
|
validation_methods = public_methods.select { |method| method.starts_with?("validate_") } |
|
|
|
|
|
|
|
validation_methods.each { |meth| public_send(meth, record) } |
|
|
|
|
|
|
|
end |
|
|
|
|
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
private |
|
|
|
private |
|
|
@ -44,8 +36,6 @@ class CaseLog < ApplicationRecord |
|
|
|
validates_with CaseLogValidator |
|
|
|
validates_with CaseLogValidator |
|
|
|
before_save :update_status! |
|
|
|
before_save :update_status! |
|
|
|
|
|
|
|
|
|
|
|
attr_accessor :page_id |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
enum status: { "not_started" => 0, "in_progress" => 1, "completed" => 2 } |
|
|
|
enum status: { "not_started" => 0, "in_progress" => 1, "completed" => 2 } |
|
|
|
|
|
|
|
|
|
|
|
enum ethnic: DbEnums.ethnic |
|
|
|
enum ethnic: DbEnums.ethnic |
|
|
|