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



20
21
22
23
# File 'app/api/locomotive/api/forms/content_type_form.rb', line 20

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



54
55
56
57
58
59
60
61
62
63
# File 'app/api/locomotive/api/forms/content_type_form.rb', line 54

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



28
29
30
31
32
33
34
35
36
# File 'app/api/locomotive/api/forms/content_type_form.rb', line 28

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



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

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

#public_submission_account_emails=(emails) ⇒ Object



38
39
40
41
42
# File 'app/api/locomotive/api/forms/content_type_form.rb', line 38

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



45
46
47
# File 'app/api/locomotive/api/forms/content_type_form.rb', line 45

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