2011-10-30 23:02:41 +00:00
|
|
|
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
|
2011-10-30 23:02:41 +00:00
|
|
|
|
|
|
|
## methods ##
|
|
|
|
|
2012-03-19 01:29:59 +00:00
|
|
|
def content=(value)
|
2012-03-21 02:21:29 +00:00
|
|
|
self.add_current_locale
|
2012-03-19 01:29:59 +00:00
|
|
|
self.default_content = false unless self.new_record?
|
|
|
|
super
|
2011-10-30 23:02:41 +00:00
|
|
|
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
|
|
|
|
2011-11-21 01:27:05 +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
|
|
|
|
|
2011-10-30 23:02:41 +00:00
|
|
|
end
|
|
|
|
end
|