Sha256: 7697f4f1fe3ecf650b41a41977b6e0c711b353c3946ad430a1ea5002f6050ce7

Contents?: true

Size: 878 Bytes

Versions: 37

Compression:

Stored size: 878 Bytes

Contents

# frozen_string_literal: true

module Decidim
  module Votings
    module Admin
      class PollingOfficerForm < Decidim::Form
        attribute :name, String
        attribute :email, String
        attribute :user_id, Integer
        attribute :existing_user, Boolean, default: false

        validates :email, presence: true, format: { with: ::Devise.email_regexp }, unless: ->(form) { form.existing_user }
        validates :name, presence: true, format: { with: UserBaseEntity::REGEXP_NAME }, unless: ->(form) { form.existing_user }
        validates :user, presence: true, if: ->(form) { form.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
      end
    end
  end
end

Version data entries

37 entries across 37 versions & 1 rubygems

Version Path
decidim-elections-0.27.9 app/forms/decidim/votings/admin/polling_officer_form.rb
decidim-elections-0.27.8 app/forms/decidim/votings/admin/polling_officer_form.rb
decidim-elections-0.27.7 app/forms/decidim/votings/admin/polling_officer_form.rb
decidim-elections-0.27.6 app/forms/decidim/votings/admin/polling_officer_form.rb
decidim-elections-0.26.10 app/forms/decidim/votings/admin/polling_officer_form.rb
decidim-elections-0.26.9 app/forms/decidim/votings/admin/polling_officer_form.rb
decidim-elections-0.27.5 app/forms/decidim/votings/admin/polling_officer_form.rb
decidim-elections-0.26.8 app/forms/decidim/votings/admin/polling_officer_form.rb
decidim-elections-0.27.4 app/forms/decidim/votings/admin/polling_officer_form.rb
decidim-elections-0.27.3 app/forms/decidim/votings/admin/polling_officer_form.rb
decidim-elections-0.26.7 app/forms/decidim/votings/admin/polling_officer_form.rb
decidim-elections-0.26.5 app/forms/decidim/votings/admin/polling_officer_form.rb
decidim-elections-0.27.2 app/forms/decidim/votings/admin/polling_officer_form.rb
decidim-elections-0.27.1 app/forms/decidim/votings/admin/polling_officer_form.rb
decidim-elections-0.26.4 app/forms/decidim/votings/admin/polling_officer_form.rb
decidim-elections-0.27.0 app/forms/decidim/votings/admin/polling_officer_form.rb
decidim-elections-0.26.3 app/forms/decidim/votings/admin/polling_officer_form.rb
decidim-elections-0.27.0.rc2 app/forms/decidim/votings/admin/polling_officer_form.rb
decidim-elections-0.27.0.rc1 app/forms/decidim/votings/admin/polling_officer_form.rb
decidim-elections-0.26.2 app/forms/decidim/votings/admin/polling_officer_form.rb