From 9efba5d532ed594d3e15b525635ae37d4b0ae5ea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Oliver=20G=C3=BCnther?= Date: Fri, 25 May 2018 12:32:10 +0200 Subject: [PATCH] Correct date writing for consent_date --- app/assets/javascripts/settings.js.erb | 2 +- app/models/setting.rb | 19 ++++++++++++++++--- app/views/settings/_users.html.erb | 2 +- 3 files changed, 18 insertions(+), 5 deletions(-) diff --git a/app/assets/javascripts/settings.js.erb b/app/assets/javascripts/settings.js.erb index 2693158f71..cc949446ac 100644 --- a/app/assets/javascripts/settings.js.erb +++ b/app/assets/javascripts/settings.js.erb @@ -65,7 +65,7 @@ See doc/COPYRIGHT.rdoc for more details. }); /* Javascript for user settings consent date */ - $("#consent-date").datepicker(); + $("#settings_consent_date").datepicker(); }); /** Toggle notification settings fields */ diff --git a/app/models/setting.rb b/app/models/setting.rb index 3363896f25..a47246908c 100644 --- a/app/models/setting.rb +++ b/app/models/setting.rb @@ -136,11 +136,24 @@ class Setting < ActiveRecord::Base end def value=(v) - if v && @@available_settings[name] && @@available_settings[name]['serialized'] - v = v.to_yaml + write_attribute(:value, formatted_value(v)) + end + + def formatted_value(value) + return value unless value.present? + + default = @@available_settings[name] + + if default['serialized'] + return value.to_yaml end - write_attribute(:value, v.to_s) + case default['format'] + when "datetime" + value.iso8601 + else + value.to_s + end end # Returns the value of the setting named name diff --git a/app/views/settings/_users.html.erb b/app/views/settings/_users.html.erb index 66ac13a423..db3b690bfc 100644 --- a/app/views/settings/_users.html.erb +++ b/app/views/settings/_users.html.erb @@ -49,7 +49,7 @@ See doc/COPYRIGHT.rdoc for more details.
<%= setting_block("consent_date") do %> - + <% end %>