Class: Decidim::Plans::PlansController
Overview
Exposes the plan resource so users can view and create them.
Instance Method Summary
collapse
#attached_proposals_picker_field, #search_proposals
#plan_limit, #plan_limit_reached?, #plans
Instance Method Details
#close ⇒ Object
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
|
# File 'app/controllers/decidim/plans/plans_controller.rb', line 147
def close
enforce_permission_to :close, :plan, plan: @plan
ClosePlan.call(@plan, current_user) do
on(:ok) do |plan|
flash[:notice] = I18n.t("close.success", scope: "decidim.plans.plans.plan")
redirect_to Decidim::ResourceLocatorPresenter.new(plan).path
end
on(:invalid) do
flash.now[:alert] = t("close.error", scope: "decidim.plans.plans.plan")
redirect_to Decidim::ResourceLocatorPresenter.new(@plan).path
end
end
end
|
#create ⇒ Object
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
|
# File 'app/controllers/decidim/plans/plans_controller.rb', line 50
def create
enforce_permission_to :create, :plan
@form = form(PlanForm).from_params(params, component: current_component)
CreatePlan.call(@form, current_user) do
on(:ok) do |plan|
flash[:notice] = I18n.t("plans.plans.create.success", scope: "decidim")
redirect_to Decidim::ResourceLocatorPresenter.new(plan).path + "/preview"
end
on(:invalid) do
flash.now[:alert] = I18n.t("plans.plans.create.error", scope: "decidim")
render :new
end
end
end
|
#destroy ⇒ Object
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
|
# File 'app/controllers/decidim/plans/plans_controller.rb', line 94
def destroy
enforce_permission_to :edit, :plan, plan: @plan
@form = form(PlanForm).from_model(@plan)
DestroyPlan.call(@plan, current_user) do
on(:ok) do
flash[:notice] = I18n.t("plans.plans.destroy.success", scope: "decidim")
redirect_to new_plan_path
end
on(:invalid) do
flash.now[:alert] = I18n.t("plans.plans.destroy.error", scope: "decidim")
render :edit
end
end
end
|
#edit ⇒ Object
68
69
70
71
72
|
# File 'app/controllers/decidim/plans/plans_controller.rb', line 68
def edit
enforce_permission_to :edit, :plan, plan: @plan
@form = form(PlanForm).from_model(@plan)
end
|
#index ⇒ Object
25
26
27
28
29
30
31
32
33
34
35
|
# File 'app/controllers/decidim/plans/plans_controller.rb', line 25
def index
@plans = search
.results
.published
.not_hidden
.includes(:category)
.includes(:scope)
@plans = paginate(@plans)
@plans = reorder(@plans)
end
|
#new ⇒ Object
44
45
46
47
48
|
# File 'app/controllers/decidim/plans/plans_controller.rb', line 44
def new
enforce_permission_to :create, :plan
@form = form(PlanForm).from_model(Plan.new(component: current_component))
end
|
#preview ⇒ Object
129
|
# File 'app/controllers/decidim/plans/plans_controller.rb', line 129
def preview; end
|
#publish ⇒ Object
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
|
# File 'app/controllers/decidim/plans/plans_controller.rb', line 131
def publish
enforce_permission_to :publish, :plan, plan: @plan
PublishPlan.call(@plan, current_user) do
on(:ok) do |plan|
flash[:notice] = I18n.t("publish.success", scope: "decidim.plans.plans.plan")
redirect_to Decidim::ResourceLocatorPresenter.new(plan).path
end
on(:invalid) do
flash.now[:alert] = t("publish.error", scope: "decidim.plans.plans.plan")
redirect_to Decidim::ResourceLocatorPresenter.new(@plan).path
end
end
end
|
#show ⇒ Object
37
38
39
40
41
42
|
# File 'app/controllers/decidim/plans/plans_controller.rb', line 37
def show
@report_form = form(Decidim::ReportForm).from_params(reason: "spam")
@request_access_form = form(RequestAccessToPlanForm).from_params({})
@accept_request_form = form(AcceptAccessToPlanForm).from_params({})
@reject_request_form = form(RejectAccessToPlanForm).from_params({})
end
|
#update ⇒ Object
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
|
# File 'app/controllers/decidim/plans/plans_controller.rb', line 74
def update
enforce_permission_to :edit, :plan, plan: @plan
@form = form(PlanForm).from_params(params, compontent: current_component)
UpdatePlan.call(@form, current_user, @plan) do
on(:ok) do |plan|
flash[:notice] = I18n.t("plans.plans.update.success", scope: "decidim")
return redirect_to Decidim::ResourceLocatorPresenter.new(plan).path if plan.published?
redirect_to Decidim::ResourceLocatorPresenter.new(plan).path + "/preview"
end
on(:invalid) do
flash.now[:alert] = I18n.t("plans.plans.update.error", scope: "decidim")
render :edit
end
end
end
|
#withdraw ⇒ Object
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
|
# File 'app/controllers/decidim/plans/plans_controller.rb', line 113
def withdraw
raise ActionController::RoutingError, "Not Found" if @plan.withdrawn?
enforce_permission_to :withdraw, :plan, plan: @plan
WithdrawPlan.call(@plan, current_user) do
on(:ok) do
flash[:notice] = t("withdraw.success", scope: "decidim.plans.plans")
end
on(:invalid) do
flash.now[:alert] = t("withdraw.error", scope: "decidim.plans.plans")
end
end
redirect_to Decidim::ResourceLocatorPresenter.new(@plan).path
end
|