Class: Locomotive::EditableElement
- Inherits:
-
Object
- Object
- Locomotive::EditableElement
- Includes:
- Mongoid::Document
- Defined in:
- app/models/locomotive/editable_element.rb
Direct Known Subclasses
Instance Method Summary collapse
- #_run_rearrange_callbacks ⇒ Object
-
#add_current_locale ⇒ Object
Make sure the current locale is added to the list of locales for the current element so that we know in which languages the element was translated.
-
#by_priority ⇒ Object
scopes ##.
-
#content_from_default=(content) ⇒ Object
Set the content of the editable element with a default value only if the content has not already been modified by the user.
-
#copy_attributes(attributes) ⇒ Object
Copy attributes extracted from the corresponding Liquid tag Each editable element overrides this method.
-
#copy_attributes_from(el) ⇒ Object
Copy attributes from an existing editable element coming from the parent page.
- #default_content? ⇒ Boolean
-
#disabled? ⇒ Boolean
methods ##.
- #disabled_in_all_translations? ⇒ Boolean
-
#editable? ⇒ Boolean
Determines if the current element can be edited in the back-office.
-
#page ⇒ Object
associations ##.
-
#set_default_content_from(el) ⇒ Object
Set the default content from an existing editable element coming from the parent page.
-
#slug ⇒ Object
validations ##.
Instance Method Details
#_run_rearrange_callbacks ⇒ Object
45 46 47 |
# File 'app/models/locomotive/editable_element.rb', line 45 def _run_rearrange_callbacks # callback from page/tree. not needed in the editable elements end |
#add_current_locale ⇒ Object
Make sure the current locale is added to the list of locales for the current element so that we know in which languages the element was translated.
85 86 87 88 |
# File 'app/models/locomotive/editable_element.rb', line 85 def add_current_locale locale = ::Mongoid::Fields::I18n.locale.to_s self.locales << locale unless self.locales.include?(locale) end |
#by_priority ⇒ Object
scopes ##
27 |
# File 'app/models/locomotive/editable_element.rb', line 27 scope :by_priority, :order_by => [[:priority, :desc]] |
#content_from_default=(content) ⇒ Object
Set the content of the editable element with a default value only if the content has not already been modified by the user.
95 96 97 |
# File 'app/models/locomotive/editable_element.rb', line 95 def content_from_default=(content) # needs to be overridden for each kind of elements end |
#copy_attributes(attributes) ⇒ Object
Copy attributes extracted from the corresponding Liquid tag Each editable element overrides this method.
59 60 61 |
# File 'app/models/locomotive/editable_element.rb', line 59 def copy_attributes(attributes) self.attributes = attributes end |
#copy_attributes_from(el) ⇒ Object
Copy attributes from an existing editable element coming from the parent page. Each editable element may or not override this method. The source element is a new record.
69 70 71 72 |
# File 'app/models/locomotive/editable_element.rb', line 69 def copy_attributes_from(el) self.attributes = el.attributes.reject { |attr| !%w(slug block hint priority fixed disabled locales from_parent).include?(attr) } self.from_parent = true end |
#default_content? ⇒ Boolean
49 50 51 52 |
# File 'app/models/locomotive/editable_element.rb', line 49 def default_content? # needs to be overridden for each kind of elements true end |
#disabled? ⇒ Boolean
methods ##
31 32 33 |
# File 'app/models/locomotive/editable_element.rb', line 31 def disabled? !!self.disabled # the original method does not work quite well with the localization end |
#disabled_in_all_translations? ⇒ Boolean
35 36 37 |
# File 'app/models/locomotive/editable_element.rb', line 35 def disabled_in_all_translations? self.disabled_translations.all? { |_, v| v == true } end |
#editable? ⇒ Boolean
Determines if the current element can be edited in the back-office
41 42 43 |
# File 'app/models/locomotive/editable_element.rb', line 41 def editable? !self.disabled? && self.locales.include?(::Mongoid::Fields::I18n.locale.to_s) && (!self.fixed? || !self.from_parent?) end |
#page ⇒ Object
associations ##
18 |
# File 'app/models/locomotive/editable_element.rb', line 18 :page, :class_name => 'Locomotive::Page', :inverse_of => :editable_elements |
#set_default_content_from(el) ⇒ Object
Set the default content from an existing editable element coming from the parent page. Each editable element may or not override this method. The source element is an existing record.
77 78 79 |
# File 'app/models/locomotive/editable_element.rb', line 77 def set_default_content_from(el) self.add_current_locale end |
#slug ⇒ Object
validations ##
8 |
# File 'app/models/locomotive/editable_element.rb', line 8 field :slug |