diff options
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) |
