Class: Decidim::Templates::Admin::CopyTemplate
- Inherits:
-
Command
- Object
- Command
- Decidim::Templates::Admin::CopyTemplate
- Defined in:
- app/commands/decidim/templates/admin/copy_template.rb
Direct Known Subclasses
Instance Method Summary collapse
-
#call ⇒ Object
Executes the command.
- #copy_template ⇒ Object
-
#initialize(template, user) ⇒ CopyTemplate
constructor
A new instance of CopyTemplate.
Constructor Details
#initialize(template, user) ⇒ CopyTemplate
Returns a new instance of CopyTemplate.
7 8 9 10 |
# File 'app/commands/decidim/templates/admin/copy_template.rb', line 7 def initialize(template, user) @template = template @user = user end |
Instance Method Details
#call ⇒ Object
Executes the command. Broadcasts these events:
-
:ok when everything is valid.
-
:invalid if the form was not valid and we could not proceed.
Returns nothing.
18 19 20 21 22 23 24 25 26 27 28 |
# File 'app/commands/decidim/templates/admin/copy_template.rb', line 18 def call return broadcast(:invalid) unless @template.valid? Decidim.traceability.perform_action!("duplicate", @template, @user) do Template.transaction do copy_template end end broadcast(:ok, @copied_template) end |
#copy_template ⇒ Object
30 31 32 33 34 35 36 37 38 39 |
# File 'app/commands/decidim/templates/admin/copy_template.rb', line 30 def copy_template @copied_template = Template.create!( organization: @template.organization, name: @template.name, description: @template.description, target: @template.target, field_values: @template.field_values, templatable: @template.templatable ) end |