Class: Decidim::Templates::Admin::CreateProposalAnswerTemplate

Inherits:
Command
  • Object
show all
Defined in:
app/commands/decidim/templates/admin/create_proposal_answer_template.rb

Instance Method Summary collapse

Constructor Details

#initialize(form) ⇒ CreateProposalAnswerTemplate

Initializes the command.

form - The source for this ProposalAnswerTemplate.



10
11
12
# File 'app/commands/decidim/templates/admin/create_proposal_answer_template.rb', line 10

def initialize(form)
  @form = form
end

Instance Method Details

#callObject



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'app/commands/decidim/templates/admin/create_proposal_answer_template.rb', line 14

def call
  return broadcast(:component_selected) if @form.select_component
  return broadcast(:invalid) unless @form.valid?

  @template = Decidim.traceability.create!(
    Template,
    @form.current_user,
    name: @form.name,
    description: @form.description,
    organization: @form.current_organization,
    field_values: { proposal_state_id: @form.proposal_state_id },
    target: :proposal_answer
  )

  @template.update!(templatable: identify_templateable_resource)

  broadcast(:ok, @template)
end