Class: Locomotive::ContentTypePresenter

Inherits:
BasePresenter show all
Defined in:
app/presenters/locomotive/content_type_presenter.rb

Instance Attribute Summary

Attributes inherited from BasePresenter

#ability, #depth

Instance Method Summary collapse

Methods inherited from BasePresenter

#ability?, #after_initialize, getters_to_hash, #id, setters_to_hash, #site

Methods included from Presentable

#after_initialize, #as_json, #attributes=, #getters, #initialize, #property_options, #setters

Instance Method Details

#entries_custom_fields=(fields) ⇒ Object

other getters / setters ##



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'app/presenters/locomotive/content_type_presenter.rb', line 18

def entries_custom_fields=(fields)
  destroyed_fields = []

  fields.each do |attributes|
    id_or_name  = attributes.delete('id') || attributes.delete('_id') || attributes['name']
    field       = self.source.find_entries_custom_field(id_or_name)

    if field && !!attributes.delete('_destroy')
      destroyed_fields << { :_id => field._id, :_destroy => true }
      next
    end

    field ||= self.source.entries_custom_fields.build

    field.from_presenter(attributes)
  end

  # shift to the accepts_nested_attributes function to delete fields
  self.source.entries_custom_fields_attributes = destroyed_fields
end

#group_by_field_nameObject



44
45
46
# File 'app/presenters/locomotive/content_type_presenter.rb', line 44

def group_by_field_name
  self.source.group_by_field.try(:name)
end

#group_by_field_name=(name) ⇒ Object



48
49
50
51
# File 'app/presenters/locomotive/content_type_presenter.rb', line 48

def group_by_field_name=(name)
  field = self.source.find_entries_custom_field(name)
  self.source.group_by_field_id = field.try(:_id)
end

#nameObject

properties ##



6
# File 'app/presenters/locomotive/content_type_presenter.rb', line 6

properties :name, :description, :slug, :raw_item_template

#order_by_field_nameObject



39
40
41
42
# File 'app/presenters/locomotive/content_type_presenter.rb', line 39

def order_by_field_name
  value = self.source.order_by
  self.source.find_entries_custom_field(value).try(:name) || value
end

#public_submission_account_emailsObject



53
54
55
56
57
# File 'app/presenters/locomotive/content_type_presenter.rb', line 53

def 
  (self.source.public_submission_accounts || []).collect do |_id|
    Locomotive::Account.find(_id).email
  end
end

#public_submission_account_emails=(emails) ⇒ Object



59
60
61
62
63
# File 'app/presenters/locomotive/content_type_presenter.rb', line 59

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