Sha256: 2b035eed8fe2722b13bf90426cf00d617f817c841e3d1c5e47cf5cbea84ae14c

Contents?: true

Size: 1.47 KB

Versions: 12

Compression:

Stored size: 1.47 KB

Contents

# frozen_string_literal: true

module Decidim
  module Admin
    class RemindersController < Admin::ApplicationController
      include Decidim::ComponentPathHelper

      helper_method :reminder_manifest

      def new
        enforce_permission_to :create, :reminder

        @form = reminder_form_from_params(name: reminder_manifest.name)
        render :new
      end

      def create
        enforce_permission_to :create, :reminder

        @form = reminder_form_from_params(params)

        command_class.call(@form) do
          on(:ok) do |reminders_queued|
            flash[:notice] = t("decidim.admin.reminders.create.success", count: reminders_queued)
            redirect_to manage_component_path(current_component)
          end

          on(:invalid) do
            flash.now[:alert] = t("decidim.admin.reminders.create.error")
            render :new
          end
        end
      end

      private

      def reminder_form_from_params(params)
        form(reminder_manifest.form_class).from_params(
          params,
          current_component: current_component
        )
      end

      def reminder_manifest
        @reminder_manifest ||= Decidim.reminders_registry.for(reminder_name)
      end

      def reminder_name
        params[:name]
      end

      def command_class
        reminder_manifest.command_class
      end

      def current_component
        @current_component ||= current_participatory_space.components.find(params[:component_id])
      end
    end
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
decidim-admin-0.27.9 app/controllers/decidim/admin/reminders_controller.rb
decidim-admin-0.27.8 app/controllers/decidim/admin/reminders_controller.rb
decidim-admin-0.27.7 app/controllers/decidim/admin/reminders_controller.rb
decidim-admin-0.27.6 app/controllers/decidim/admin/reminders_controller.rb
decidim-admin-0.27.5 app/controllers/decidim/admin/reminders_controller.rb
decidim-admin-0.27.4 app/controllers/decidim/admin/reminders_controller.rb
decidim-admin-0.27.3 app/controllers/decidim/admin/reminders_controller.rb
decidim-admin-0.27.2 app/controllers/decidim/admin/reminders_controller.rb
decidim-admin-0.27.1 app/controllers/decidim/admin/reminders_controller.rb
decidim-admin-0.27.0 app/controllers/decidim/admin/reminders_controller.rb
decidim-admin-0.27.0.rc2 app/controllers/decidim/admin/reminders_controller.rb
decidim-admin-0.27.0.rc1 app/controllers/decidim/admin/reminders_controller.rb