Sha256: d660231b166f53a0b020212f197a8eb0de116596aa78e960d8e25d227d0e104a

Contents?: true

Size: 1.08 KB

Versions: 30

Compression:

Stored size: 1.08 KB

Contents

module Locomotive
  class EditableFile < EditableElement

    ## behaviours ##
    mount_uploader 'source', EditableFileUploader

    replace_field 'source', ::String, true

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

    ## 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

30 entries across 30 versions & 1 rubygems

Version Path
locomotivecms-4.2.0.alpha2 app/models/locomotive/editable_file.rb
locomotivecms-4.2.0.alpha1 app/models/locomotive/editable_file.rb
locomotivecms-4.1.1 app/models/locomotive/editable_file.rb
locomotivecms-4.1.0 app/models/locomotive/editable_file.rb
locomotivecms-4.1.0.rc1 app/models/locomotive/editable_file.rb
locomotivecms-4.0.3 app/models/locomotive/editable_file.rb
locomotivecms-4.0.2 app/models/locomotive/editable_file.rb
locomotivecms-4.0.1 app/models/locomotive/editable_file.rb
locomotivecms-4.0.0 app/models/locomotive/editable_file.rb
locomotivecms-4.0.0.rc0 app/models/locomotive/editable_file.rb
locomotivecms-4.0.0.alpha3 app/models/locomotive/editable_file.rb
locomotivecms-3.4.1 app/models/locomotive/editable_file.rb
locomotivecms-4.0.0.alpha2 app/models/locomotive/editable_file.rb
locomotivecms-4.0.0.alpha1 app/models/locomotive/editable_file.rb
locomotivecms-3.4.0 app/models/locomotive/editable_file.rb
locomotivecms-3.3.0 app/models/locomotive/editable_file.rb
locomotivecms-3.3.0.rc3 app/models/locomotive/editable_file.rb
locomotivecms-3.3.0.rc2 app/models/locomotive/editable_file.rb
locomotivecms-3.1.2 app/models/locomotive/editable_file.rb
locomotivecms-3.2.1 app/models/locomotive/editable_file.rb