Class: Locomotive::API::Forms::PageForm

Inherits:
BaseForm
  • Object
show all
Defined in:
app/api/locomotive/api/forms/page_form.rb

Instance Attribute Summary

Attributes inherited from BaseForm

#_persisted, #_policy

Instance Method Summary collapse

Methods inherited from BaseForm

attributes, attrs, define_attribute, #persisted?, #serializable_hash, #set_attribute

Constructor Details

#initialize(site, attributes = {}, existing_page = nil) ⇒ PageForm

Returns a new instance of PageForm.



34
35
36
37
38
# File 'app/api/locomotive/api/forms/page_form.rb', line 34

def initialize(site, attributes = {}, existing_page = nil)
  @site = site
  @existing_page = existing_page
  super(attributes)
end

Instance Method Details

#content_type=(value) ⇒ Object



68
69
70
71
72
# File 'app/api/locomotive/api/forms/page_form.rb', line 68

def content_type=(value)
  self.templatized = true if value.present?

  self.target_klass_slug = value
end

#display_settings=(settings) ⇒ Object



80
81
82
83
84
85
# File 'app/api/locomotive/api/forms/page_form.rb', line 80

def display_settings=(settings)
  (settings || {}).each do |k, v|
    settings[k] = v == 'true'
  end
  set_attribute(:display_settings, settings)
end

#editable_elements=(elements) ⇒ Object



50
51
52
53
54
55
56
57
58
# File 'app/api/locomotive/api/forms/page_form.rb', line 50

def editable_elements=(elements)
  self.editable_elements_attributes = elements.map do |attrs|
    if element = @existing_page.try(:find_editable_element, attrs[:block], attrs[:slug])
      attrs[:_id] = element._id
    end

    EditableElementForm.new(attrs).serializable_hash
  end
end

#parent=(id_or_path) ⇒ Object

Custom setters ##



42
43
44
# File 'app/api/locomotive/api/forms/page_form.rb', line 42

def parent=(id_or_path)
  self.parent_id = @site.pages.by_id_or_fullpath(id_or_path).pluck(:_id).first
end

#redirect_url=(value) ⇒ Object



74
75
76
77
78
# File 'app/api/locomotive/api/forms/page_form.rb', line 74

def redirect_url=(value)
  self.redirect = true if value.present?

  set_attribute :redirect_url, value
end

#sections_content=(value) ⇒ Object



60
61
62
# File 'app/api/locomotive/api/forms/page_form.rb', line 60

def sections_content=(value)
  set_attribute(:sections_content, JSON.parse(value))
end

#sections_dropzone_content=(value) ⇒ Object



64
65
66
# File 'app/api/locomotive/api/forms/page_form.rb', line 64

def sections_dropzone_content=(value)
  set_attribute(:sections_dropzone_content, JSON.parse(value))
end

#template=(template) ⇒ Object



46
47
48
# File 'app/api/locomotive/api/forms/page_form.rb', line 46

def template=(template)
  self.raw_template = template
end