Class: Decidim::Plans::Admin::UpdateSections

Inherits:
Rectify::Command
  • Object
show all
Includes:
NestedUpdater
Defined in:
app/commands/decidim/plans/admin/update_sections.rb

Overview

This command is executed when the user modifies sections from the admin panel.

Instance Method Summary collapse

Constructor Details

#initialize(form, sections) ⇒ UpdateSections

Initializes a UpdateSections Command.

form - The form from which to get the data. sections - The current set of the sections to be updated.



15
16
17
18
# File 'app/commands/decidim/plans/admin/update_sections.rb', line 15

def initialize(form, sections)
  @form = form
  @sections = sections
end

Instance Method Details

#callObject

Updates the sections if valid.

Broadcasts :ok if successful, :invalid otherwise.



23
24
25
26
27
28
29
30
31
# File 'app/commands/decidim/plans/admin/update_sections.rb', line 23

def call
  return broadcast(:invalid) if @form.invalid?

  Decidim::Plans::Section.transaction do
    update_sections
  end

  broadcast(:ok)
end