Sha256: bf015afa3b1c95063dd50e0d6186ff2fbae761cef31fcdb80583afdcbd574bc9

Contents?: true

Size: 1.17 KB

Versions: 9

Compression:

Stored size: 1.17 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).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

9 entries across 9 versions & 1 rubygems

Version Path
decidim-decidim_awesome-0.8.3 app/forms/decidim/decidim_awesome/admin/menu_form.rb
decidim-decidim_awesome-0.8.2 app/forms/decidim/decidim_awesome/admin/menu_form.rb
decidim-decidim_awesome-0.8.1 app/forms/decidim/decidim_awesome/admin/menu_form.rb
decidim-decidim_awesome-0.8.0 app/forms/decidim/decidim_awesome/admin/menu_form.rb
decidim-decidim_awesome-0.7.2 app/forms/decidim/decidim_awesome/admin/menu_form.rb
decidim-decidim_awesome-0.7.0 app/forms/decidim/decidim_awesome/admin/menu_form.rb
decidim-decidim_awesome-0.6.7 app/forms/decidim/decidim_awesome/admin/menu_form.rb
decidim-decidim_awesome-0.6.6 app/forms/decidim/decidim_awesome/admin/menu_form.rb
decidim-decidim_awesome-0.6.5 app/forms/decidim/decidim_awesome/admin/menu_form.rb