diff options
| author | erdgeist <erdgeist@erdgeist.org> | 2026-07-13 17:09:31 +0200 |
|---|---|---|
| committer | erdgeist <erdgeist@erdgeist.org> | 2026-07-13 17:09:31 +0200 |
| commit | aa14587b052a0aa7884aaf27183981975168ab14 (patch) | |
| tree | 2b043061a06474929bbfb9fe79a7985267ccef17 /app/controllers | |
| parent | 0b6ae26f3b4c3c8278e569fa6644a544e996c25d (diff) | |
Wire real autosave into translation editing
The shared TinyMCE setup initializes cccms.setup_autosave() on any
page with a textarea.with_editor, unconditionally starting a
7-second interval that submits to the form's data-autosave-url --
which the translation edit form never set, so the interval PUT the
current page URL itself and 404'd on a nonexistent route.
Fixed by actually giving it something to talk to, rather than
suppressing it: a real autosave endpoint, and update now goes
through Node#autosave!/#save_draft! -- the same pipeline the
primary editor uses, fixed earlier this session for exactly this
kind of cross-locale carryover. This was the autosave-buffer parity
already flagged as due after the proof of concept; the shared JS
just forced the timing.
Diffstat (limited to 'app/controllers')
| -rw-r--r-- | app/controllers/page_translations_controller.rb | 17 |
1 files changed, 14 insertions, 3 deletions
diff --git a/app/controllers/page_translations_controller.rb b/app/controllers/page_translations_controller.rb index 47f01f7..9446cd2 100644 --- a/app/controllers/page_translations_controller.rb +++ b/app/controllers/page_translations_controller.rb | |||
| @@ -3,7 +3,7 @@ class PageTranslationsController < ApplicationController | |||
| 3 | 3 | ||
| 4 | before_action :login_required | 4 | before_action :login_required |
| 5 | before_action :find_node | 5 | before_action :find_node |
| 6 | before_action :find_locale, :only => [:show, :edit, :update, :destroy] | 6 | before_action :find_locale, :only => [:show, :edit, :update, :autosave, :destroy] |
| 7 | 7 | ||
| 8 | def index | 8 | def index |
| 9 | page = @node.draft || @node.head | 9 | page = @node.draft || @node.head |
| @@ -26,8 +26,8 @@ class PageTranslationsController < ApplicationController | |||
| 26 | end | 26 | end |
| 27 | 27 | ||
| 28 | def update | 28 | def update |
| 29 | draft = ensure_editable_draft | 29 | Globalize.with_locale(@locale) { @node.autosave!(translation_params, current_user) } |
| 30 | Globalize.with_locale(@locale) { draft.update!(translation_params) } | 30 | @node.save_draft!(current_user) |
| 31 | flash[:notice] = "#{@locale.upcase} translation saved. Publish the draft to make it live." | 31 | flash[:notice] = "#{@locale.upcase} translation saved. Publish the draft to make it live." |
| 32 | 32 | ||
| 33 | if params[:commit] == "Save + Unlock + Exit" | 33 | if params[:commit] == "Save + Unlock + Exit" |
| @@ -41,6 +41,17 @@ class PageTranslationsController < ApplicationController | |||
| 41 | redirect_to node_path(@node) | 41 | redirect_to node_path(@node) |
| 42 | end | 42 | end |
| 43 | 43 | ||
| 44 | def autosave | ||
| 45 | Globalize.with_locale(@locale) { @node.autosave!(translation_params, current_user) } | ||
| 46 | head :ok | ||
| 47 | rescue LockedByAnotherUser => e | ||
| 48 | render plain: e.message, status: :locked | ||
| 49 | rescue ActiveRecord::RecordInvalid => e | ||
| 50 | render plain: e.message, status: :unprocessable_entity | ||
| 51 | rescue StandardError => e | ||
| 52 | render plain: "Autosave failed", status: :internal_server_error | ||
| 53 | end | ||
| 54 | |||
| 44 | def destroy | 55 | def destroy |
| 45 | base = @node.draft || @node.head | 56 | base = @node.draft || @node.head |
| 46 | unless base && base.translated_locales.include?(@locale) | 57 | unless base && base.translated_locales.include?(@locale) |
