app/models/locomotive/editable_element.rb in locomotive_cms-2.0.0.rc12 vs app/models/locomotive/editable_element.rb in locomotive_cms-2.0.0

- old
+ new

@@ -1,9 +1,10 @@ module Locomotive class EditableElement - include ::Mongoid::Document + # include ::Mongoid::Document + include Locomotive::Mongoid::Document ## fields ## field :slug field :block field :hint @@ -36,11 +37,14 @@ end # Determines if the current element can be edited in the back-office # def editable? - !self.disabled? && self.locales.include?(::Mongoid::Fields::I18n.locale.to_s) && (!self.fixed? || !self.from_parent?) + !self.disabled? && + self.locales.include?(::Mongoid::Fields::I18n.locale.to_s) && + (!self.fixed? || !self.from_parent?) && + !self.destroyed? end def _run_rearrange_callbacks # callback from page/tree. not needed in the editable elements end @@ -68,10 +72,17 @@ 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 + # 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. + def set_default_content_from(el) + self.add_current_locale + end + # 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. # def add_current_locale @@ -95,11 +106,11 @@ { 'site_id' => self.page.site_id, "template_dependencies.#{locale}" => { '$in' => [self.page._id] }, 'editable_elements.fixed' => true, 'editable_elements.block' => self.block, - 'editable_elements.slug' => self.slug + 'editable_elements.slug' => self.slug, } end # Update the value (or content) of the elements matching the same block/slug # as the current element in all the pages inheriting from the current page. @@ -109,6 +120,6 @@ def propagate_content true end end -end \ No newline at end of file +end