2015-11-03 15:27:49 +01:00
|
|
|
class Champ < ActiveRecord::Base
|
2015-11-03 10:48:40 +01:00
|
|
|
belongs_to :dossier
|
2015-11-05 11:21:44 +01:00
|
|
|
belongs_to :type_de_champ
|
2016-03-15 17:17:56 +01:00
|
|
|
|
2016-08-09 16:21:39 +02:00
|
|
|
delegate :libelle, :type_champ, :order_place, :mandatory, :description, :drop_down_list, to: :type_de_champ
|
2016-03-15 17:17:56 +01:00
|
|
|
|
|
|
|
def mandatory?
|
|
|
|
mandatory
|
|
|
|
end
|
2016-06-09 12:08:18 +02:00
|
|
|
|
|
|
|
def data_provide
|
2016-10-10 16:17:17 +02:00
|
|
|
return 'datepicker' if (type_champ == 'datetime' || type_champ == 'date') && !(BROWSER.value.chrome? || BROWSER.value.edge?)
|
2016-06-09 12:08:18 +02:00
|
|
|
return 'typeahead' if type_champ == 'address'
|
|
|
|
end
|
2016-06-22 11:25:41 +02:00
|
|
|
|
|
|
|
def data_date_format
|
|
|
|
('dd/mm/yyyy' if type_champ == 'datetime' || type_champ == 'date')
|
|
|
|
end
|
|
|
|
|
|
|
|
def same_hour? num
|
|
|
|
same_date? num, '%H'
|
|
|
|
end
|
|
|
|
|
|
|
|
def same_minute? num
|
|
|
|
same_date? num, '%M'
|
|
|
|
end
|
|
|
|
|
|
|
|
def same_date? num, compare
|
|
|
|
if type_champ == 'datetime' && !value.nil?
|
|
|
|
if value.to_datetime.strftime(compare) == num
|
|
|
|
return true
|
|
|
|
end
|
|
|
|
end
|
|
|
|
false
|
|
|
|
end
|
2016-10-12 17:22:56 +02:00
|
|
|
|
|
|
|
def self.regions
|
|
|
|
JSON.parse(Carto::GeoAPI::Driver.regions).sort_by{|e| e['nom']}.inject([]){|acc, liste| acc.push(liste['nom']) }
|
|
|
|
end
|
|
|
|
|
|
|
|
def self.departements
|
|
|
|
JSON.parse(Carto::GeoAPI::Driver.departements).inject([]){|acc, liste| acc.push(liste['code'] + ' - ' + liste['nom']) }
|
|
|
|
end
|
|
|
|
|
|
|
|
def self.pays
|
|
|
|
JSON.parse(Carto::GeoAPI::Driver.pays).inject([]){|acc, liste| acc.push(liste['nom']) }
|
|
|
|
end
|
2015-11-03 10:48:40 +01:00
|
|
|
end
|