summaryrefslogtreecommitdiff
path: root/app/controllers/nodes_controller.rb
diff options
context:
space:
mode:
authorerdgeist <erdgeist@erdgeist.org>2026-07-25 03:51:44 +0200
committererdgeist <erdgeist@erdgeist.org>2026-07-25 03:51:44 +0200
commitbaace1fa5df46694ddd515dc3bbca59b22df8692 (patch)
tree6a8b587ca5d6d38377fe132b02c857f1c4149231 /app/controllers/nodes_controller.rb
parented32bc6902ab634451539770bcd910662212e01a (diff)
Extract flashes to i18n and stop dispatching on submit labels
Diffstat (limited to 'app/controllers/nodes_controller.rb')
-rw-r--r--app/controllers/nodes_controller.rb45
1 files changed, 23 insertions, 22 deletions
diff --git a/app/controllers/nodes_controller.rb b/app/controllers/nodes_controller.rb
index ce8f0538..50b30881 100644
--- a/app/controllers/nodes_controller.rb
+++ b/app/controllers/nodes_controller.rb
@@ -55,9 +55,9 @@ class NodesController < ApplicationController
55 if params[:asset_id].present? && (asset = Asset.find(params[:asset_id])) 55 if params[:asset_id].present? && (asset = Asset.find(params[:asset_id]))
56 result = @node.attach_asset!(asset, :user => current_user, 56 result = @node.attach_asset!(asset, :user => current_user,
57 :headline => params[:asset_headline].present?) 57 :headline => params[:asset_headline].present?)
58 flash[:notice] = "Page created with “#{asset.name}” attached." 58 flash[:notice] = t("flash.nodes.created_with_attachment", :name => asset.name)
59 flash[:notice] += " It is the page's headline." if result[:headline] == :set 59 flash[:notice] += " " + t("flash.common.now_headline") if result[:headline] == :set
60 flash[:error] = "This asset type cannot be a headline." if result[:headline] == :not_eligible 60 flash[:error] = t("flash.common.headline_ineligible") if result[:headline] == :not_eligible
61 end 61 end
62 62
63 redirect_to(edit_node_path(@node)) 63 redirect_to(edit_node_path(@node))
@@ -83,14 +83,12 @@ class NodesController < ApplicationController
83 @page = @node.autosave || @node.draft || @node.head 83 @page = @node.autosave || @node.draft || @node.head
84 84
85 if @node.autosave 85 if @node.autosave
86 flash.now[:notice] = 86 flash.now[:notice] = t("flash.nodes.autosave_banner")
87 "This page has unsaved changes from a previous session, shown below. " \
88 "Save to keep them, or use \"Discard Autosave\" below to go back to the last saved version."
89 elsif freshly_locked 87 elsif freshly_locked
90 flash.now[:notice] ||= "Node locked and ready to edit" 88 flash.now[:notice] ||= t("flash.nodes.locked_ready")
91 end 89 end
92 rescue LockedByAnotherUser => e 90 rescue LockedByAnotherUser => e
93 flash[:error] = e.message 91 flash[:error] = t("flash.common.locked_by_other")
94 redirect_to(request.referer || node_path(@node)) 92 redirect_to(request.referer || node_path(@node))
95 end 93 end
96 94
@@ -99,7 +97,7 @@ class NodesController < ApplicationController
99 @node.autosave!( page_params.merge(:tag_list => params[:tag_list]), current_user ) 97 @node.autosave!( page_params.merge(:tag_list => params[:tag_list]), current_user )
100 @node.save_draft!(current_user) 98 @node.save_draft!(current_user)
101 99
102 flash[:notice] = "Draft saved. Publish your changes in the Status section once you're done." 100 flash[:notice] = t("flash.nodes.draft_saved")
103 flash[:status_path] = node_path(@node) 101 flash[:status_path] = node_path(@node)
104 102
105 if @node.draft.translated_locales.size > 1 103 if @node.draft.translated_locales.size > 1
@@ -112,7 +110,7 @@ class NodesController < ApplicationController
112 end 110 end
113 end 111 end
114 112
115 if params[:commit] == "Save + Unlock + Exit" 113 if params[:unlock_exit].present?
116 @node.unlock! 114 @node.unlock!
117 redirect_to node_path(@node) 115 redirect_to node_path(@node)
118 else 116 else
@@ -156,13 +154,16 @@ class NodesController < ApplicationController
156 154
157 def trash 155 def trash
158 if @node.trash!(current_user) 156 if @node.trash!(current_user)
159 flash[:notice] = "Page has been moved to the Trash" 157 flash[:notice] = t("flash.nodes.trashed")
160 redirect_to trashed_nodes_path 158 redirect_to trashed_nodes_path
161 else 159 else
162 flash[:notice] = "Page is already in the Trash" 160 flash[:notice] = t("flash.nodes.already_trashed")
163 redirect_to node_path(@node) 161 redirect_to node_path(@node)
164 end 162 end
165 rescue ActiveRecord::RecordInvalid, LockedByAnotherUser => e 163 rescue LockedByAnotherUser
164 flash[:error] = t("flash.common.locked_by_other")
165 redirect_to node_path(@node)
166 rescue ActiveRecord::RecordInvalid => e
166 flash[:error] = e.message 167 flash[:error] = e.message
167 redirect_to node_path(@node) 168 redirect_to node_path(@node)
168 end 169 end
@@ -170,10 +171,10 @@ class NodesController < ApplicationController
170 def restore_from_trash 171 def restore_from_trash
171 parent = Node.find(params[:parent_id]) 172 parent = Node.find(params[:parent_id])
172 @node.restore_from_trash!(parent, current_user) 173 @node.restore_from_trash!(parent, current_user)
173 flash[:notice] = "Page has been restored from the Trash" 174 flash[:notice] = t("flash.nodes.restored")
174 redirect_to node_path(@node) 175 redirect_to node_path(@node)
175 rescue ActiveRecord::RecordNotFound 176 rescue ActiveRecord::RecordNotFound
176 flash[:error] = "Restore target not found" 177 flash[:error] = t("flash.nodes.restore_target_missing")
177 redirect_to node_path(@node) 178 redirect_to node_path(@node)
178 rescue ActiveRecord::RecordInvalid => e 179 rescue ActiveRecord::RecordInvalid => e
179 flash[:error] = e.message 180 flash[:error] = e.message
@@ -182,7 +183,7 @@ class NodesController < ApplicationController
182 183
183 def destroy 184 def destroy
184 @node.destroy_from_trash!(current_user) 185 @node.destroy_from_trash!(current_user)
185 flash[:notice] = "Page has been permanently deleted" 186 flash[:notice] = t("flash.nodes.deleted")
186 redirect_to trashed_nodes_path 187 redirect_to trashed_nodes_path
187 188
188 rescue ActiveRecord::RecordInvalid, ActiveRecord::RecordNotDestroyed => e 189 rescue ActiveRecord::RecordInvalid, ActiveRecord::RecordNotDestroyed => e
@@ -192,15 +193,15 @@ class NodesController < ApplicationController
192 193
193 def publish 194 def publish
194 @node.publish_draft!(current_user) 195 @node.publish_draft!(current_user)
195 flash[:notice] = "Draft has been published" 196 flash[:notice] = t("flash.nodes.published")
196 redirect_to node_path(@node) 197 redirect_to node_path(@node)
197 end 198 end
198 199
199 def unlock 200 def unlock
200 if @node.unlock! 201 if @node.unlock!
201 flash[:notice] = "Node unlocked" 202 flash[:notice] = t("flash.nodes.unlocked")
202 else 203 else
203 flash[:notice] = "Already unlocked" 204 flash[:notice] = t("flash.nodes.already_unlocked")
204 end 205 end
205 206
206 redirect_to node_path(@node) 207 redirect_to node_path(@node)
@@ -210,9 +211,9 @@ class NodesController < ApplicationController
210 @node = Node.find(params[:id]) 211 @node = Node.find(params[:id])
211 if @node.draft 212 if @node.draft
212 @node.draft.ensure_preview_token! 213 @node.draft.ensure_preview_token!
213 flash[:notice] = "Shareable preview link created - see below." 214 flash[:notice] = t("flash.nodes.preview_created")
214 else 215 else
215 flash[:notice] = "Create or edit a draft first - shared preview links are only available for pages with an active draft." 216 flash[:notice] = t("flash.nodes.preview_needs_draft")
216 end 217 end
217 redirect_to node_path(@node) 218 redirect_to node_path(@node)
218 end 219 end
@@ -220,7 +221,7 @@ class NodesController < ApplicationController
220 def revoke_shared_preview 221 def revoke_shared_preview
221 @node = Node.find(params[:id]) 222 @node = Node.find(params[:id])
222 @node.draft.revoke_preview_token! if @node.draft 223 @node.draft.revoke_preview_token! if @node.draft
223 flash[:notice] = "Shareable preview link revoked." 224 flash[:notice] = t("flash.nodes.preview_revoked")
224 redirect_to node_path(@node) 225 redirect_to node_path(@node)
225 end 226 end
226 227