Class: Decidim::Initiatives::Admin::InitiativesTypesController

Inherits:
ApplicationController
  • Object
show all
Defined in:
app/controllers/decidim/initiatives/admin/initiatives_types_controller.rb

Overview

Controller used to manage the available initiative types for the current organization.

Instance Method Summary collapse

Methods inherited from ApplicationController

#permission_class_chain, #permissions_context

Instance Method Details

#createObject

POST /admin/initiatives_types



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'app/controllers/decidim/initiatives/admin/initiatives_types_controller.rb', line 27

def create
  enforce_permission_to :create, :initiative_type
  @form = initiative_type_form.from_params(params)

  CreateInitiativeType.call(@form) do
    on(:ok) do |initiative_type|
      flash[:notice] = I18n.t("decidim.initiatives.admin.initiatives_types.create.success")
      redirect_to edit_initiatives_type_path(initiative_type)
    end

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

#destroyObject

DELETE /admin/initiatives_types/:id



73
74
75
76
77
78
79
80
# File 'app/controllers/decidim/initiatives/admin/initiatives_types_controller.rb', line 73

def destroy
  enforce_permission_to :destroy, :initiative_type, initiative_type: current_initiative_type
  current_initiative_type.destroy!

  redirect_to initiatives_types_path, flash: {
    notice: I18n.t("decidim.initiatives.admin.initiatives_types.destroy.success")
  }
end

#editObject

GET /admin/initiatives_types/:id/edit



45
46
47
48
49
50
# File 'app/controllers/decidim/initiatives/admin/initiatives_types_controller.rb', line 45

def edit
  enforce_permission_to :edit, :initiative_type, initiative_type: current_initiative_type
  @form = initiative_type_form
          .from_model(current_initiative_type,
                      initiative_type: current_initiative_type)
end

#indexObject

GET /admin/initiatives_types



14
15
16
17
18
# File 'app/controllers/decidim/initiatives/admin/initiatives_types_controller.rb', line 14

def index
  enforce_permission_to :index, :initiative_type

  @initiatives_types = InitiativeTypes.for(current_organization)
end

#newObject

GET /admin/initiatives_types/new



21
22
23
24
# File 'app/controllers/decidim/initiatives/admin/initiatives_types_controller.rb', line 21

def new
  enforce_permission_to :create, :initiative_type
  @form = initiative_type_form.instance
end

#updateObject

PUT /admin/initiatives_types/:id



53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'app/controllers/decidim/initiatives/admin/initiatives_types_controller.rb', line 53

def update
  enforce_permission_to :update, :initiative_type, initiative_type: current_initiative_type

  @form = initiative_type_form
          .from_params(params, initiative_type: current_initiative_type)

  UpdateInitiativeType.call(current_initiative_type, @form) do
    on(:ok) do
      flash[:notice] = I18n.t("decidim.initiatives.admin.initiatives_types.update.success")
      redirect_to edit_initiatives_type_path(current_initiative_type)
    end

    on(:invalid) do
      flash.now[:alert] = I18n.t("decidim.initiatives.admin.initiatives_types.update.error")
      render :edit
    end
  end
end