Sha256: 67278d4b9f74a7ac102ae6088b7bfd6b62003acbf354bb6603b3a088b0ec67a9

Contents?: true

Size: 1.02 KB

Versions: 26

Compression:

Stored size: 1.02 KB

Contents

module Locomotive
  class EditableControl < EditableElement

    ## fields ##
    field :content
    field :options, type: Array,   default: []

    ## methods ##

    def options=(value)
      if value.respond_to?(:split)
        value = value.split(/\s*\,\s*/).map do |option|
          first, last = *option.split(/\s*=\s*/)
          last ||= first
          { 'value' => first, 'text' => last }
        end
      end

      super(value)
    end

    def default_content?
      false
    end

    def copy_attributes_from(el)
      super(el)

      %w(content options).each do |meth|
        self.attributes[meth] = el.attributes[meth]
      end
    end

    protected

    def propagate_content
      if self.content_changed?
        operations  = {
          '$set' => {
            'editable_elements.$.content' => self.content,
            'editable_elements.$.options' => self.options,
          }
        }

        self.page.collection.find(self._selector).update(operations, multi: true)
      end
      true
    end

  end
end

Version data entries

26 entries across 26 versions & 1 rubygems

Version Path
locomotive_cms-2.2.0 app/models/locomotive/editable_control.rb
locomotive_cms-2.1.4 app/models/locomotive/editable_control.rb
locomotive_cms-2.1.3 app/models/locomotive/editable_control.rb
locomotive_cms-2.1.2 app/models/locomotive/editable_control.rb
locomotive_cms-2.1.1 app/models/locomotive/editable_control.rb
locomotive_cms-2.1.0 app/models/locomotive/editable_control.rb