aboutsummaryrefslogtreecommitdiffstats
path: root/app/inputs
diff options
context:
space:
mode:
authorZog2018-04-25 15:34:57 +0200
committerAlban Peignier2018-04-25 22:44:51 +0200
commit0e64912dd2c299df543ed03e2cd6609bc7d6dec6 (patch)
treee9fa08b24b8c231d4671bfc15a7e3c59ffc66950 /app/inputs
parentb930761de0a269c45876b2242e085e23070f8325 (diff)
downloadchouette-core-0e64912dd2c299df543ed03e2cd6609bc7d6dec6.tar.bz2
Refs #6683; Uniformize the time_zones notation
Diffstat (limited to 'app/inputs')
-rw-r--r--app/inputs/full_time_zone_input.rb24
1 files changed, 24 insertions, 0 deletions
diff --git a/app/inputs/full_time_zone_input.rb b/app/inputs/full_time_zone_input.rb
new file mode 100644
index 000000000..f5d8a9ba2
--- /dev/null
+++ b/app/inputs/full_time_zone_input.rb
@@ -0,0 +1,24 @@
+class FullTimeZoneInput < SimpleForm::Inputs::CollectionSelectInput
+ def collection
+ @collection ||= begin
+ collection = options.delete(:collection) || ActiveSupport::TimeZone::MAPPING
+ collection.respond_to?(:call) ? collection.call : collection.to_a
+ end
+ end
+
+ def detect_collection_methods
+ label, value = options.delete(:label_method), options.delete(:value_method)
+
+ label ||= ->(tz) do
+ tz = ActiveSupport::TimeZone[tz.last]
+ "(#{tz.formatted_offset}) #{tz.name}"
+ end
+ value ||= :last
+
+ [label, value]
+ end
+
+ def input(wrapper_options = {})
+ super wrapper_options
+ end
+end