]> git.openstreetmap.org Git - rails.git/commitdiff
Added bootstrap alert when body preview is empty
authorNenad Vujicic <nenadus@gmail.com>
Tue, 30 Jul 2024 22:24:45 +0000 (00:24 +0200)
committerNenad Vujicic <nenadus@gmail.com>
Tue, 30 Jul 2024 22:24:45 +0000 (00:24 +0200)
Fixes #3748. Added check to SiteController#preview to detect if (message, diary entry, diary entry comment) body is empty and if positive, returns rendered bootstrap alert "Nothing to preview" to be displayed in richtext_field.

app/controllers/site_controller.rb
config/locales/en.yml

index 5d63e79fd3937fc178791920477b3668129e92ce..58f0a11c9340bbd796082622f3d6dcdbe852d13d 100644 (file)
@@ -138,7 +138,12 @@ class SiteController < ApplicationController
   end
 
   def preview
-    render :html => RichText.new(params[:type], params[:text]).to_html
+    if params[:text].blank?
+      flash.now[:warning] = t("layouts.nothing_to_preview")
+      render :partial => "layouts/flash"
+    else
+      render :html => RichText.new(params[:type], params[:text]).to_html
+    end
   end
 
   def id
index 3f2e8a93b0d7bf78c346f7f0f255d51e1a09e2fd..1c119fcf3cca30d3a0a98c8f6c81ec67dcf6366b 100644 (file)
@@ -1586,6 +1586,7 @@ en:
     tou: "Terms of Use"
     osm_offline: "The OpenStreetMap database is currently offline while essential database maintenance work is carried out."
     osm_read_only: "The OpenStreetMap database is currently in read-only mode while essential database maintenance work is carried out."
+    nothing_to_preview: "Nothing to preview."
     donate: "Support OpenStreetMap by %{link} to the Hardware Upgrade Fund."
     help: Help
     about: About