Sha256: 00548aa422b5d234505f53f2b7f4bb5b3c2ddbde9634f8ffd590e32c5ad1e90b

Contents?: true

Size: 1.12 KB

Versions: 29

Compression:

Stored size: 1.12 KB

Contents

# frozen_string_literal: true

module Decidim
  module Proposals
    module Admin
      # A form object to be used when admin users want to create a proposal.
      class ProposalForm < Decidim::Proposals::Admin::ProposalBaseForm
        translatable_attribute :title, String do |field, _locale|
          validates field, length: { in: 15..150 }, if: proc { |resource| resource.send(field).present? }
        end
        translatable_attribute :body, String

        validates :title, :body, translatable_presence: true

        validate :notify_missing_attachment_if_errored

        def map_model(model)
          super(model)
          presenter = ProposalPresenter.new(model)

          self.title = presenter.title(all_locales: title.is_a?(Hash))
          self.body = presenter.body(all_locales: body.is_a?(Hash))
          self.attachment = if model.documents.first.present?
                              { file: model.documents.first.file, title: translated_attribute(model.documents.first.title) }
                            else
                              {}
                            end
        end
      end
    end
  end
end

Version data entries

29 entries across 29 versions & 1 rubygems

Version Path
decidim-proposals-0.26.10 app/forms/decidim/proposals/admin/proposal_form.rb
decidim-proposals-0.26.9 app/forms/decidim/proposals/admin/proposal_form.rb
decidim-proposals-0.26.8 app/forms/decidim/proposals/admin/proposal_form.rb
decidim-proposals-0.26.7 app/forms/decidim/proposals/admin/proposal_form.rb
decidim-proposals-0.26.5 app/forms/decidim/proposals/admin/proposal_form.rb
decidim-proposals-0.26.4 app/forms/decidim/proposals/admin/proposal_form.rb
decidim-proposals-0.26.3 app/forms/decidim/proposals/admin/proposal_form.rb
decidim-proposals-0.26.2 app/forms/decidim/proposals/admin/proposal_form.rb
decidim-proposals-0.26.1 app/forms/decidim/proposals/admin/proposal_form.rb
decidim-proposals-0.26.0 app/forms/decidim/proposals/admin/proposal_form.rb
decidim-proposals-0.26.0.rc2 app/forms/decidim/proposals/admin/proposal_form.rb
decidim-proposals-0.26.0.rc1 app/forms/decidim/proposals/admin/proposal_form.rb
decidim-proposals-0.25.2 app/forms/decidim/proposals/admin/proposal_form.rb
decidim-proposals-0.25.1 app/forms/decidim/proposals/admin/proposal_form.rb
decidim-proposals-0.25.0 app/forms/decidim/proposals/admin/proposal_form.rb
decidim-proposals-0.25.0.rc4 app/forms/decidim/proposals/admin/proposal_form.rb
decidim-proposals-0.25.0.rc3 app/forms/decidim/proposals/admin/proposal_form.rb
decidim-proposals-0.25.0.rc2 app/forms/decidim/proposals/admin/proposal_form.rb
decidim-proposals-0.25.0.rc1 app/forms/decidim/proposals/admin/proposal_form.rb
decidim-proposals-0.24.3 app/forms/decidim/proposals/admin/proposal_form.rb