Class: Decidim::Proposals::CollaborativeDraftsController
Overview
Exposes Collaborative Drafts resource so users can view and create them.
Instance Method Summary
collapse
#proposal_limit, #proposal_limit_reached?, #proposals
Instance Method Details
#create ⇒ Object
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
|
# File 'app/controllers/decidim/proposals/collaborative_drafts_controller.rb', line 53
def create
enforce_permission_to :create, :collaborative_draft
@form = form(CollaborativeDraftForm).from_params(params)
CreateCollaborativeDraft.call(@form, current_user) do
on(:ok) do |collaborative_draft|
flash[:notice] = I18n.t("proposals.collaborative_drafts.create.success", scope: "decidim")
redirect_to Decidim::ResourceLocatorPresenter.new(collaborative_draft).path
end
on(:invalid) do
flash.now[:alert] = I18n.t("proposals.collaborative_drafts.create.error", scope: "decidim")
render :new
end
end
end
|
#edit ⇒ Object
71
72
73
74
75
76
|
# File 'app/controllers/decidim/proposals/collaborative_drafts_controller.rb', line 71
def edit
enforce_permission_to :edit, :collaborative_draft, collaborative_draft: @collaborative_draft
@form = form(CollaborativeDraftForm).from_model(@collaborative_draft)
@form.attachment = form(AttachmentForm).from_model(@collaborative_draft.attachments.first)
end
|
#index ⇒ Object
26
27
28
29
30
31
32
33
34
35
|
# File 'app/controllers/decidim/proposals/collaborative_drafts_controller.rb', line 26
def index
@collaborative_drafts = search
.result
.not_hidden
.includes(:category)
.includes(:scope)
@collaborative_drafts = reorder(@collaborative_drafts)
@collaborative_drafts = paginate(@collaborative_drafts)
end
|
#new ⇒ Object
45
46
47
48
49
50
51
|
# File 'app/controllers/decidim/proposals/collaborative_drafts_controller.rb', line 45
def new
enforce_permission_to :create, :collaborative_draft
@form = form(CollaborativeDraftForm).from_params(
attachment: form(AttachmentForm).from_params({})
)
end
|
#publish ⇒ Object
108
109
110
111
112
113
114
115
116
117
118
119
120
|
# File 'app/controllers/decidim/proposals/collaborative_drafts_controller.rb', line 108
def publish
PublishCollaborativeDraft.call(@collaborative_draft, current_user) do
on(:ok) do |proposal|
flash[:notice] = I18n.t("publish.success", scope: "decidim.proposals.collaborative_drafts.collaborative_draft")
redirect_to Decidim::ResourceLocatorPresenter.new(proposal).path
end
on(:invalid) do
flash.now[:alert] = t("publish.error", scope: "decidim.proposals.collaborative_drafts.collaborative_draft")
redirect_to Decidim::ResourceLocatorPresenter.new(@collaborative_draft).path
end
end
end
|
#update ⇒ Object
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
|
# File 'app/controllers/decidim/proposals/collaborative_drafts_controller.rb', line 78
def update
enforce_permission_to :edit, :collaborative_draft, collaborative_draft: @collaborative_draft
@form = form(CollaborativeDraftForm).from_params(params)
UpdateCollaborativeDraft.call(@form, current_user, @collaborative_draft) do
on(:ok) do |collaborative_draft|
flash[:notice] = I18n.t("proposals.collaborative_drafts.update.success", scope: "decidim")
redirect_to Decidim::ResourceLocatorPresenter.new(collaborative_draft).path
end
on(:invalid) do
flash.now[:alert] = I18n.t("proposals.collaborative_drafts.update.error", scope: "decidim")
render :edit
end
end
end
|
#withdraw ⇒ Object
95
96
97
98
99
100
101
102
103
104
105
106
|
# File 'app/controllers/decidim/proposals/collaborative_drafts_controller.rb', line 95
def withdraw
WithdrawCollaborativeDraft.call(@collaborative_draft, current_user) do
on(:ok) do
flash[:notice] = t("withdraw.success", scope: "decidim.proposals.collaborative_drafts.collaborative_draft")
end
on(:invalid) do
flash.now[:alert] = t("withdraw.error", scope: "decidim.proposals.collaborative_drafts.collaborative_draft")
end
end
redirect_to Decidim::ResourceLocatorPresenter.new(@collaborative_draft).path
end
|