Sha256: 1326f52b78bfcacd55ca8af5f147c0bd9bb52345e6741b360260c99617db5637

Contents?: true

Size: 1.05 KB

Versions: 7

Compression:

Stored size: 1.05 KB

Contents

module Locomotive
  class EditableFile < EditableElement

    ## behaviours ##
    mount_uploader 'source', EditableFileUploader

    replace_field 'source', ::String, true

    ## fields ##
    field :default_source_url, localize: true

    ## callbacks ##
    after_initialize :init_localized_source

    ## methods ##

    # Returns the url or the path to the uploaded file
    # if it exists. Otherwise returns the default url.
    #
    # @note This method is not used for the rendering, only for the back-office
    #
    # @return [String] The url or path of the file
    #
    def content
      self.source? ? self.source.url : self.default_source_url
    end

    alias :content= :source=

    def remove_source=(value)
      self.source_will_change! # notify the page to run the callbacks for that element
      super
    end

    private

    def init_localized_source
      # FIXME: the source of the element is not correctly set for the first time (certainly because the source is localized)
      attributes[:source] = {} unless self.persisted?
    end

  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
locomotivecms-3.0.0.rc6 app/models/locomotive/editable_file.rb
locomotivecms-3.0.0.rc5 app/models/locomotive/editable_file.rb
locomotivecms-3.0.0.rc4 app/models/locomotive/editable_file.rb
locomotivecms-3.0.0.rc3 app/models/locomotive/editable_file.rb
locomotivecms-3.0.0.rc2 app/models/locomotive/editable_file.rb
locomotivecms-3.0.0.rc1 app/models/locomotive/editable_file.rb
locomotivecms-3.0.0.pre.beta.1 app/models/locomotive/editable_file.rb