Sha256: ca582dc4fd65bd57d636201818ceea15ba5bd8f5c28d257e71d18aad0d7ec7fa

Contents?: true

Size: 1.18 KB

Versions: 6

Compression:

Stored size: 1.18 KB

Contents

# frozen_string_literal: true

module Decidim
  module DecidimAwesome
    module Admin
      class MenuForm < Decidim::Form
        include Decidim::TranslatableAttributes
        VISIBILITY_STATES = %w(default hidden logged non_logged verified_user).freeze

        translatable_attribute :raw_label, String
        attribute :url, String
        attribute :position, Integer
        attribute :target, String
        attribute :visibility, String

        validates :raw_label, translatable_presence: true
        validates :url, presence: true
        validates :position, numericality: { greater_than: 0 }
        validates :visibility, inclusion: { in: VISIBILITY_STATES }
        validates :target, inclusion: { in: ["", "_blank"] }

        # remove query string from native menu element (to avoid interactions with the locale in the generated url)
        def map_model(model)
          self.url = Addressable::URI.parse(model.url).path if model.native?
        end

        def to_params
          {
            label: raw_label,
            position: position,
            url: url,
            target: target,
            visibility: visibility
          }
        end
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
decidim-decidim_awesome-0.10.3 app/forms/decidim/decidim_awesome/admin/menu_form.rb
decidim-decidim_awesome-0.10.2 app/forms/decidim/decidim_awesome/admin/menu_form.rb
decidim-decidim_awesome-0.10.1 app/forms/decidim/decidim_awesome/admin/menu_form.rb
decidim-decidim_awesome-0.10.0 app/forms/decidim/decidim_awesome/admin/menu_form.rb
decidim-decidim_awesome-0.9.3 app/forms/decidim/decidim_awesome/admin/menu_form.rb
decidim-decidim_awesome-0.9.1 app/forms/decidim/decidim_awesome/admin/menu_form.rb