Class: Locomotive::EditableShortText

Inherits:
EditableElement show all
Defined in:
app/models/locomotive/editable_short_text.rb

Direct Known Subclasses

EditableLongText

Instance Method Summary collapse

Methods inherited from EditableElement

#_run_rearrange_callbacks, #add_current_locale, #by_priority, #copy_attributes, #disabled?, #disabled_in_all_translations?, #editable?, #page, #slug

Instance Method Details

#contentObject

fields ##



5
# File 'app/models/locomotive/editable_short_text.rb', line 5

field :content,         :localize => true

#content=(value) ⇒ Object

methods ##



10
11
12
13
14
15
# File 'app/models/locomotive/editable_short_text.rb', line 10

def content=(value)
  return if value == self.content
  self.add_current_locale
  self.default_content = false unless self.new_record?
  super
end

#content_from_default=(content) ⇒ Object



21
22
23
24
25
26
27
# File 'app/models/locomotive/editable_short_text.rb', line 21

def content_from_default=(content)
  if self.default_content?
    self.content_will_change!
    self.attributes['content'] ||= {}
    self.attributes['content'][::Mongoid::Fields::I18n.locale.to_s] = content
  end
end

#copy_attributes_from(el) ⇒ Object



29
30
31
32
33
34
# File 'app/models/locomotive/editable_short_text.rb', line 29

def copy_attributes_from(el)
  super(el)

  self.attributes['content']          = el.content_translations || {}
  self.attributes['default_content']  = el.default_content_translations
end

#default_content?Boolean

Returns:



17
18
19
# File 'app/models/locomotive/editable_short_text.rb', line 17

def default_content?
  !!self.default_content
end

#set_default_content_from(el) ⇒ Object



36
37
38
39
40
41
42
43
44
45
46
47
# File 'app/models/locomotive/editable_short_text.rb', line 36

def set_default_content_from(el)
  super(el)

  locale = ::Mongoid::Fields::I18n.locale.to_s

  if self.default_content? || self.attributes['default_content'][locale].nil?
    self.default_content = true

    self.content_will_change!
    self.attributes['content'][locale] = el.content
  end
end