Sha256: defc4bb137ca1046a94ac47daaae06d1512626b9dd8249543c045b94cc906db4

Contents?: true

Size: 1011 Bytes

Versions: 23

Compression:

Stored size: 1011 Bytes

Contents

# frozen_string_literal: true

module Decidim
  module Conferences
    module Admin
      # A form object used to create conference media link from the admin dashboard.
      class MediaLinkForm < Form
        include TranslatableAttributes

        mimic :conference_media_link

        translatable_attribute :title, String

        attribute :link, String
        attribute :date, Decidim::Attributes::LocalizedDate
        attribute :weight, Integer, default: 0

        validates :title, :date, :link, presence: true
        validate :link_format

        def link
          return if super.blank?

          return "http://" + super unless super.match?(%r{\A(http|https)://}i)

          super
        end

        private

        def link_format
          return if link.blank?

          uri = URI.parse(link)
          errors.add :link, :invalid if !uri.is_a?(URI::HTTP) || uri.host.nil?
        rescue URI::InvalidURIError
          errors.add :link, :invalid
        end
      end
    end
  end
end

Version data entries

23 entries across 23 versions & 1 rubygems

Version Path
decidim-conferences-0.23.6 app/forms/decidim/conferences/admin/media_link_form.rb
decidim-conferences-0.23.5 app/forms/decidim/conferences/admin/media_link_form.rb
decidim-conferences-0.23.4 app/forms/decidim/conferences/admin/media_link_form.rb
decidim-conferences-0.23.3 app/forms/decidim/conferences/admin/media_link_form.rb
decidim-conferences-0.23.2 app/forms/decidim/conferences/admin/media_link_form.rb
decidim-conferences-0.23.1 app/forms/decidim/conferences/admin/media_link_form.rb
decidim-conferences-0.23.1.rc1 app/forms/decidim/conferences/admin/media_link_form.rb
decidim-conferences-0.23.0 app/forms/decidim/conferences/admin/media_link_form.rb
decidim-conferences-0.22.0 app/forms/decidim/conferences/admin/media_link_form.rb
decidim-conferences-0.21.0 app/forms/decidim/conferences/admin/media_link_form.rb
decidim-conferences-0.20.1 app/forms/decidim/conferences/admin/media_link_form.rb
decidim-conferences-0.20.0 app/forms/decidim/conferences/admin/media_link_form.rb
decidim-conferences-0.19.1 app/forms/decidim/conferences/admin/media_link_form.rb
decidim-conferences-0.18.1 app/forms/decidim/conferences/admin/media_link_form.rb
decidim-conferences-0.19.0 app/forms/decidim/conferences/admin/media_link_form.rb
decidim-conferences-0.17.2 app/forms/decidim/conferences/admin/media_link_form.rb
decidim-conferences-0.18.0 app/forms/decidim/conferences/admin/media_link_form.rb
decidim-conferences-0.17.1 app/forms/decidim/conferences/admin/media_link_form.rb
decidim-conferences-0.16.1 app/forms/decidim/conferences/admin/media_link_form.rb
decidim-conferences-0.17.0 app/forms/decidim/conferences/admin/media_link_form.rb