Class: Locomotive::API::Forms::ContentTypeForm

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

Instance Attribute Summary collapse

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 = {}) ⇒ ContentTypeForm

Returns a new instance of ContentTypeForm.

Parameters:

  • the (Site)

    current site, or site to scope to


23
24
25
26
# File 'app/api/locomotive/api/forms/content_type_form.rb', line 23

def initialize(site, attributes = {})
  self.site = site
  super(attributes)
end

Instance Attribute Details

#siteObject

Returns the value of attribute site


7
8
9
# File 'app/api/locomotive/api/forms/content_type_form.rb', line 7

def site
  @site
end

Instance Method Details

#display_settings=(settings) ⇒ Object


57
58
59
60
61
62
63
64
65
66
# File 'app/api/locomotive/api/forms/content_type_form.rb', line 57

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

#fields=(fields) ⇒ Object

If the current content type exists, look up the fields and add their IDs to the attributes hash. If not, set the entries_custom_fields_attributes as-is


31
32
33
34
35
36
37
38
39
# File 'app/api/locomotive/api/forms/content_type_form.rb', line 31

def fields=(fields)
  self.entries_custom_fields_attributes = fields.map do |attrs|
    if field = existing_content_type.try(:find_entries_custom_field, attrs[:name])
      attrs[:_id] = field._id
    end

    ContentTypeFieldForm.new(content_type_service, field, attrs).serializable_hash
  end
end

#order_by=(field) ⇒ Object


52
53
54
55
# File 'app/api/locomotive/api/forms/content_type_form.rb', line 52

def order_by=(field)
  field = '_position' if field == 'manually'
  set_attribute(:order_by, field)
end

#public_submission_account_emails=(emails) ⇒ Object


41
42
43
44
45
# File 'app/api/locomotive/api/forms/content_type_form.rb', line 41

def (emails)
  self.public_submission_accounts = emails.collect do |email|
    Locomotive::Account.where(email: email).first
  end.compact.map(&:id)
end

#raw_item_template=(template) ⇒ Object

deprecated


48
49
50
# File 'app/api/locomotive/api/forms/content_type_form.rb', line 48

def raw_item_template=(template)
  set_attribute(:entry_template, template)
end