Sha256: d30a235050b7243bbac5dff63369e4d019dde5624cf759f983cbb3f813df6e08

Contents?: true

Size: 1.67 KB

Versions: 3

Compression:

Stored size: 1.67 KB

Contents

# frozen_string_literal: true
module Decidim
  module Admin
    # A form object used to create participatory processes from the admin
    # dashboard.
    #
    class ParticipatoryProcessForm < Form
      include TranslatableAttributes

      translatable_attribute :title, String
      translatable_attribute :subtitle, String
      translatable_attribute :description, String
      translatable_attribute :short_description, String
      translatable_attribute :scope, String
      translatable_attribute :developer_group, String
      translatable_attribute :local_area, String
      translatable_attribute :target, String
      translatable_attribute :participatory_scope, String
      translatable_attribute :participatory_structure, String

      mimic :participatory_process

      attribute :end_date, Date
      attribute :slug, String
      attribute :hashtag, String
      attribute :promoted, Boolean
      attribute :hero_image
      attribute :banner_image

      validates :slug, presence: true
      validates :title, :subtitle, :description, :short_description, translatable_presence: true

      validate :slug, :slug_uniqueness

      validates :hero_image, file_size: { less_than_or_equal_to: ->(_record) { Decidim.maximum_attachment_size } }, file_content_type: { allow: ["image/jpeg", "image/png"] }
      validates :banner_image, file_size: { less_than_or_equal_to: ->(_record) { Decidim.maximum_attachment_size } }, file_content_type: { allow: ["image/jpeg", "image/png"] }

      private

      def slug_uniqueness
        return unless current_organization.participatory_processes.where(slug: slug).where.not(id: id).any?

        errors.add(:slug, :taken)
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 2 rubygems

Version Path
decidim-admin-0.0.5 app/forms/decidim/admin/participatory_process_form.rb
decidim-0.0.5 decidim-admin/app/forms/decidim/admin/participatory_process_form.rb
decidim-0.0.4 decidim-admin/app/forms/decidim/admin/participatory_process_form.rb