Class: Ecoportal::API::V2::Page::Component::DateField

Inherits:
Ecoportal::API::V2::Page::Component show all
Defined in:
lib/ecoportal/api/v2/page/component/date_field.rb

Constant Summary collapse

ISO8601 =

"%Y-%m-%dT%H:%M:00.00Z"

"%Y-%m-%dT%H:%M:00Z"

Constants included from Common::Content::StringDigest

Common::Content::StringDigest::MAX_HASH_LABEL

Constants inherited from Common::Content::DoubleModel

Common::Content::DoubleModel::NOT_USED

Constants included from Common::Content::ClassHelpers

Common::Content::ClassHelpers::NOT_USED

Instance Attribute Summary

Attributes inherited from Common::Content::DoubleModel

#_key, #_parent, #_read_only

Instance Method Summary collapse

Methods inherited from Ecoportal::API::V2::Page::Component

#attached?, #bindings, #bindings?, #delete!, #forces, get_class, #indexable_label, #move, #multi_section?, new_doc, #ooze, #ref, #ref_backend, #replace, #replace_bindings, #section, #unattach!

Methods included from Common::Content::StringDigest

#hash_label, #indexable_label

Methods inherited from Common::Content::DoubleModel

#_doc_key, #as_json, #as_update, #consolidate!, #dirty?, #doc, embeds_many, embeds_one, enforce!, #initialize, #key, #key=, key?, new_uuid, #original_doc, pass_reader, pass_writer, passarray, passboolean, passdate, passforced, passkey, passthrough, #print_pretty, read_only!, read_only?, #read_only?, #replace_doc, #reset!, #resolved_doc_key, #root, #to_json

Methods included from Common::Content::ClassHelpers

#inheritable_attrs, #inheritable_class_vars, #inherited, #instance_variable_name, #new_class, #resolve_class, #to_constant, #to_time, #uid, #used_param?

Constructor Details

This class inherits a constructor from Ecoportal::API::Common::Content::DoubleModel

Instance Method Details

#configure(*conf) ⇒ Object

Quick config helper

Parameters:

  • conf (Symbol, Array<Symbol>)
    • :time to show time
    • :now_button to display NOW button
    • :past to only allow past dates
    • :event to enable event
    • :reminder to set the reminder (requires :event)
      • :never
      • :one_day
      • :three_days
      • :one_week
      • :two_weeks
      • :one_month


59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/ecoportal/api/v2/page/component/date_field.rb', line 59

def configure(*conf)
  conf.each_with_object([]) do |cnf, unused|
    case cnf
    when :time
      self.show_time  = true
    when :now_button
      self.today_button = true
    when :past
      self.past_only = true
    when :event
      self.create_event = true
    when Hash
      supported = [:reminder]
      unless (rest = hash_except(cnf.dup, *supported)).empty?
        unused.push(rest)
      end
      if cnf.key?(:reminder) then configure_reminder(cnf[:reminder]) end
    else
      unused.push(cnf)
    end
  end.yield_self do |unused|
    super(*unused)
  end
end

#create_event=(value) ⇒ Object



36
37
38
39
# File 'lib/ecoportal/api/v2/page/component/date_field.rb', line 36

def create_event=(value)
  self.past_only = false
  doc["create_event"] = !!value
end

#empty?Boolean

Returns:

  • (Boolean)


17
18
19
# File 'lib/ecoportal/api/v2/page/component/date_field.rb', line 17

def empty?
  !value
end

#to_sObject



41
42
43
44
# File 'lib/ecoportal/api/v2/page/component/date_field.rb', line 41

def to_s
  return nil unless value
  to_local_time(value).strftime(ISO8601)
end

#valueObject



28
29
30
31
32
33
34
# File 'lib/ecoportal/api/v2/page/component/date_field.rb', line 28

def value
  if val = doc["value"]
    (Time.parse(val) rescue nil).yield_self do |datetime|
      datetime.localtime if datetime
    end
  end
end

#value=(val) ⇒ Object



21
22
23
24
25
26
# File 'lib/ecoportal/api/v2/page/component/date_field.rb', line 21

def value=(val)
  doc["value"] = self.class.to_time(val).yield_self do |datetime|
    datetime = datetime.utc.strftime(ISO8601) if datetime
    datetime
  end
end