|
|
|
@ -9,7 +9,7 @@ class CaseLogValidator < ActiveModel::Validator
|
|
|
|
|
# If we've come from the form UI we only want to validate the specific fields |
|
|
|
|
# that have just been submitted. If we're submitting a log via API or Bulk Upload |
|
|
|
|
# we want to validate all data fields. |
|
|
|
|
question_to_validate = options[:previous_page] |
|
|
|
|
question_to_validate = options[:page] |
|
|
|
|
if question_to_validate |
|
|
|
|
if respond_to?("validate_#{question_to_validate}") |
|
|
|
|
public_send("validate_#{question_to_validate}", record) |
|
|
|
@ -40,19 +40,16 @@ class CaseLog < ApplicationRecord
|
|
|
|
|
include SoftValidations |
|
|
|
|
default_scope -> { kept } |
|
|
|
|
|
|
|
|
|
validate :instance_validations |
|
|
|
|
validates_with CaseLogValidator, ({ page: @current_page } || {}) |
|
|
|
|
before_save :update_status! |
|
|
|
|
|
|
|
|
|
attr_accessor :current_page, :previous_page |
|
|
|
|
attr_accessor :previous_page |
|
|
|
|
attr_writer :current_page |
|
|
|
|
|
|
|
|
|
enum status: { "not_started" => 0, "in_progress" => 1, "completed" => 2 } |
|
|
|
|
|
|
|
|
|
AUTOGENERATED_FIELDS = %w[id status created_at updated_at discarded_at].freeze |
|
|
|
|
|
|
|
|
|
def instance_validations |
|
|
|
|
validates_with CaseLogValidator, ({ current_page: current_page } || {}) |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
def self.editable_fields |
|
|
|
|
attribute_names - AUTOGENERATED_FIELDS |
|
|
|
|
end |
|
|
|
|