Sha256: 5ef05da3266fc797a6d06f2357500ee70b9db4d043c21c7c857419234fb8d1af

Contents?: true

Size: 1.81 KB

Versions: 22

Compression:

Stored size: 1.81 KB

Contents

# frozen_string_literal: true

module Decidim
  module Assemblies
    module Admin
      # A form object used to create assembly members from the admin dashboard.
      #
      class AssemblyMemberForm < Form
        mimic :assembly_member

        attribute :weight, Integer, default: 0
        attribute :full_name, String
        attribute :gender, String
        attribute :birthday, Decidim::Attributes::TimeWithZone
        attribute :birthplace, String
        attribute :ceased_date, Decidim::Attributes::LocalizedDate
        attribute :designation_date, Decidim::Attributes::LocalizedDate
        attribute :designation_mode, String
        attribute :position, String
        attribute :position_other, String
        attribute :user_id, Integer
        attribute :existing_user, Boolean, default: false

        validates :designation_date, presence: true
        validates :full_name, presence: true, unless: proc { |object| object.existing_user }
        validates :position, presence: true, inclusion: { in: Decidim::AssemblyMember::POSITIONS }
        validates :position_other, presence: true, if: ->(form) { form.position == "other" }
        validates :ceased_date, date: { after: :designation_date, allow_blank: true }
        validates :user, presence: true, if: proc { |object| object.existing_user }

        def map_model(model)
          self.user_id = model.decidim_user_id
          self.existing_user = user_id.present?
        end

        def user
          @user ||= current_organization.users.find_by(id: user_id)
        end

        def positions_for_select
          Decidim::AssemblyMember::POSITIONS.map do |position|
            [
              I18n.t(position, scope: "decidim.admin.models.assembly_member.positions"),
              position
            ]
          end
        end
      end
    end
  end
end

Version data entries

22 entries across 22 versions & 1 rubygems

Version Path
decidim-assemblies-0.24.3 app/forms/decidim/assemblies/admin/assembly_member_form.rb
decidim-assemblies-0.23.6 app/forms/decidim/assemblies/admin/assembly_member_form.rb
decidim-assemblies-0.24.2 app/forms/decidim/assemblies/admin/assembly_member_form.rb
decidim-assemblies-0.23.5 app/forms/decidim/assemblies/admin/assembly_member_form.rb
decidim-assemblies-0.24.1 app/forms/decidim/assemblies/admin/assembly_member_form.rb
decidim-assemblies-0.24.0 app/forms/decidim/assemblies/admin/assembly_member_form.rb
decidim-assemblies-0.24.0.rc2 app/forms/decidim/assemblies/admin/assembly_member_form.rb
decidim-assemblies-0.23.4 app/forms/decidim/assemblies/admin/assembly_member_form.rb
decidim-assemblies-0.24.0.rc1 app/forms/decidim/assemblies/admin/assembly_member_form.rb
decidim-assemblies-0.23.3 app/forms/decidim/assemblies/admin/assembly_member_form.rb
decidim-assemblies-0.23.2 app/forms/decidim/assemblies/admin/assembly_member_form.rb
decidim-assemblies-0.23.1 app/forms/decidim/assemblies/admin/assembly_member_form.rb
decidim-assemblies-0.23.1.rc1 app/forms/decidim/assemblies/admin/assembly_member_form.rb
decidim-assemblies-0.23.0 app/forms/decidim/assemblies/admin/assembly_member_form.rb
decidim-assemblies-0.22.0 app/forms/decidim/assemblies/admin/assembly_member_form.rb
decidim-assemblies-0.21.0 app/forms/decidim/assemblies/admin/assembly_member_form.rb
decidim-assemblies-0.20.1 app/forms/decidim/assemblies/admin/assembly_member_form.rb
decidim-assemblies-0.20.0 app/forms/decidim/assemblies/admin/assembly_member_form.rb
decidim-assemblies-0.19.1 app/forms/decidim/assemblies/admin/assembly_member_form.rb
decidim-assemblies-0.18.1 app/forms/decidim/assemblies/admin/assembly_member_form.rb