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.



27
28
29
30
31
# File 'app/api/locomotive/api/forms/page_form.rb', line 27

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

Instance Method Details

#content_type=(value) ⇒ Object



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

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

  self.target_klass_slug = value
end

#editable_elements=(elements) ⇒ Object



43
44
45
46
47
48
49
50
51
# File 'app/api/locomotive/api/forms/page_form.rb', line 43

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 ##



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

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



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

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

  set_attribute :redirect_url, value
end

#template=(template) ⇒ Object



39
40
41
# File 'app/api/locomotive/api/forms/page_form.rb', line 39

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