Sha256: 820d796158303475651263eb628c187dab48d7246a909c2f8f6d65cf1dbfd890

Contents?: true

Size: 1.51 KB

Versions: 22

Compression:

Stored size: 1.51 KB

Contents

# frozen_string_literal: true

module Decidim
  module Meetings
    module Admin
      # This command is executed when the user changes a Meeting from the admin
      # panel.
      class UpdateMeeting < Rectify::Command
        # Initializes a UpdateMeeting Command.
        #
        # form - The form from which to get the data.
        # meeting - The current instance of the page to be updated.
        def initialize(form, meeting)
          @form = form
          @meeting = meeting
        end

        # Updates the meeting if valid.
        #
        # Broadcasts :ok if successful, :invalid otherwise.
        def call
          return broadcast(:invalid) if @form.invalid?

          update_meeting!
          broadcast(:ok, @meeting)
        end

        private

        def update_meeting!
          @meeting.update_attributes!(
            scope: @form.scope,
            category: @form.category,
            title: @form.title,
            description: @form.description,
            end_time: @form.end_time,
            start_time: @form.start_time,
            address: @form.address,
            latitude: @form.latitude,
            longitude: @form.longitude,
            location: @form.location,
            location_hints: @form.location_hints
          )
        end

        def geocode_meeting
          result = @meeting.geocode
          @form.errors.add :address, :invalid unless result
          result
        end

        def update_meeting
          @meeting.save!
        end
      end
    end
  end
end

Version data entries

22 entries across 22 versions & 2 rubygems

Version Path
decidim-meetings-0.5.1 app/commands/decidim/meetings/admin/update_meeting.rb
decidim-0.5.1 decidim-meetings/app/commands/decidim/meetings/admin/update_meeting.rb
decidim-meetings-0.5.0 app/commands/decidim/meetings/admin/update_meeting.rb
decidim-0.5.0 decidim-meetings/app/commands/decidim/meetings/admin/update_meeting.rb
decidim-meetings-0.4.4 app/commands/decidim/meetings/admin/update_meeting.rb
decidim-0.4.4 decidim-meetings/app/commands/decidim/meetings/admin/update_meeting.rb
decidim-meetings-0.4.3 app/commands/decidim/meetings/admin/update_meeting.rb
decidim-meetings-0.4.2 app/commands/decidim/meetings/admin/update_meeting.rb
decidim-meetings-0.4.1 app/commands/decidim/meetings/admin/update_meeting.rb
decidim-0.4.3 decidim-meetings/app/commands/decidim/meetings/admin/update_meeting.rb
decidim-0.4.2 decidim-meetings/app/commands/decidim/meetings/admin/update_meeting.rb
decidim-0.4.1 decidim-meetings/app/commands/decidim/meetings/admin/update_meeting.rb
decidim-meetings-0.4.0 app/commands/decidim/meetings/admin/update_meeting.rb
decidim-0.4.0 decidim-meetings/app/commands/decidim/meetings/admin/update_meeting.rb
decidim-meetings-0.3.2 app/commands/decidim/meetings/admin/update_meeting.rb
decidim-0.3.2 decidim-meetings/app/commands/decidim/meetings/admin/update_meeting.rb
decidim-meetings-0.3.1 app/commands/decidim/meetings/admin/update_meeting.rb
decidim-0.3.1 decidim-meetings/app/commands/decidim/meetings/admin/update_meeting.rb
decidim-meetings-0.3.0 app/commands/decidim/meetings/admin/update_meeting.rb
decidim-0.3.0 decidim-meetings/app/commands/decidim/meetings/admin/update_meeting.rb