Sha256: dcd497d39558348b6173914f9b7cb43e04a00e0471992ea68ce70bff1827cb21

Contents?: true

Size: 1.17 KB

Versions: 13

Compression:

Stored size: 1.17 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
        include Decidim::HasUploadValidations

        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.editor_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

13 entries across 13 versions & 1 rubygems

Version Path
decidim-proposals-0.29.1 app/forms/decidim/proposals/admin/proposal_form.rb
decidim-proposals-0.28.4 app/forms/decidim/proposals/admin/proposal_form.rb
decidim-proposals-0.29.0 app/forms/decidim/proposals/admin/proposal_form.rb
decidim-proposals-0.28.3 app/forms/decidim/proposals/admin/proposal_form.rb
decidim-proposals-0.29.0.rc4 app/forms/decidim/proposals/admin/proposal_form.rb
decidim-proposals-0.29.0.rc3 app/forms/decidim/proposals/admin/proposal_form.rb
decidim-proposals-0.29.0.rc2 app/forms/decidim/proposals/admin/proposal_form.rb
decidim-proposals-0.29.0.rc1 app/forms/decidim/proposals/admin/proposal_form.rb
decidim-proposals-0.28.2 app/forms/decidim/proposals/admin/proposal_form.rb
decidim-proposals-0.28.1 app/forms/decidim/proposals/admin/proposal_form.rb
decidim-proposals-0.28.0 app/forms/decidim/proposals/admin/proposal_form.rb
decidim-proposals-0.28.0.rc5 app/forms/decidim/proposals/admin/proposal_form.rb
decidim-proposals-0.28.0.rc4 app/forms/decidim/proposals/admin/proposal_form.rb