engine/app/models/locomotive/editable_short_text.rb

48 lines
1.2 KiB
Ruby
Raw Normal View History

module Locomotive
class EditableShortText < EditableElement
## fields ##
2012-03-19 01:29:59 +00:00
field :content, :localize => true
field :default_content, :type => Boolean, :localize => true, :default => true
## methods ##
2012-03-19 01:29:59 +00:00
def content=(value)
self.add_current_locale
2012-03-19 01:29:59 +00:00
self.default_content = false unless self.new_record?
super
end
2012-03-19 01:29:59 +00:00
def default_content?
!!self.default_content
end
def copy_attributes_from(el)
super(el)
self.attributes['content'] = el.content_translations || {}
self.attributes['default_content'] = el.default_content_translations
end
2012-01-25 21:07:10 +00:00
def as_json(options = {})
Locomotive::EditableShortTextPresenter.new(self).as_json
end
2012-03-19 01:29:59 +00:00
protected
def propagate_content
if self.content_changed?
operations = {
'$set' => {
"editable_elements.$.content.#{::Mongoid::Fields::I18n.locale}" => self.content,
"editable_elements.$.default_content.#{::Mongoid::Fields::I18n.locale}" => false,
}
}
self.page.collection.update self._selector, operations, :multi => true
end
true
end
end
end