2020-08-06 16:35:45 +02:00
|
|
|
|
# == Schema Information
|
|
|
|
|
#
|
|
|
|
|
# Table name: champs
|
|
|
|
|
#
|
|
|
|
|
# id :integer not null, primary key
|
|
|
|
|
# private :boolean default(FALSE), not null
|
|
|
|
|
# row :integer
|
|
|
|
|
# type :string
|
|
|
|
|
# value :string
|
|
|
|
|
# created_at :datetime
|
|
|
|
|
# updated_at :datetime
|
|
|
|
|
# dossier_id :integer
|
|
|
|
|
# etablissement_id :integer
|
|
|
|
|
# parent_id :bigint
|
|
|
|
|
# type_de_champ_id :integer
|
|
|
|
|
#
|
2018-02-13 18:18:20 +01:00
|
|
|
|
class Champs::DateChamp < Champ
|
2018-06-14 17:41:31 +02:00
|
|
|
|
before_save :format_before_save
|
|
|
|
|
|
2018-07-25 19:34:06 +02:00
|
|
|
|
def search_terms
|
|
|
|
|
# Text search is pretty useless for dates so we’re not including these champs
|
|
|
|
|
end
|
|
|
|
|
|
2018-12-28 15:37:20 +01:00
|
|
|
|
def to_s
|
2019-11-25 14:39:42 +01:00
|
|
|
|
value.present? ? I18n.l(Time.zone.parse(value), format: '%d %B %Y') : ""
|
2018-12-28 15:37:20 +01:00
|
|
|
|
end
|
|
|
|
|
|
2019-09-11 16:04:42 +02:00
|
|
|
|
def for_tag
|
2019-11-25 14:39:42 +01:00
|
|
|
|
value.present? ? I18n.l(Time.zone.parse(value), format: '%d %B %Y') : ""
|
2019-09-11 16:04:42 +02:00
|
|
|
|
end
|
|
|
|
|
|
2018-06-14 17:41:31 +02:00
|
|
|
|
private
|
|
|
|
|
|
|
|
|
|
def format_before_save
|
|
|
|
|
self.value =
|
|
|
|
|
begin
|
2019-11-25 14:39:42 +01:00
|
|
|
|
Time.zone.parse(value).to_date.iso8601
|
2018-06-14 17:41:31 +02:00
|
|
|
|
rescue
|
|
|
|
|
nil
|
|
|
|
|
end
|
|
|
|
|
end
|
2018-02-13 18:18:20 +01:00
|
|
|
|
end
|