From: Andy Allan Date: Wed, 29 May 2019 14:09:14 +0000 (+0200) Subject: Refactor diary entry form X-Git-Tag: live~2545^2~1 X-Git-Url: https://git.openstreetmap.org/rails.git/commitdiff_plain/1b1d90a0f951a4aa26a6cb6f912a35efd5762962?ds=sidebyside Refactor diary entry form This uses the built-in helpers for naming form elements, rather than having to override with specific i18n labels. It also changes the label to 'Update', and capitalizes the title on the edit page. --- diff --git a/app/views/diary_entries/_form.html.erb b/app/views/diary_entries/_form.html.erb new file mode 100644 index 000000000..0d8f7ef5b --- /dev/null +++ b/app/views/diary_entries/_form.html.erb @@ -0,0 +1,35 @@ +
+
+
+ + <%= f.text_field :title, :class => "richtext_title" %> +
+
+ + <%= richtext_area :diary_entry, :body, :cols => 80, :rows => 20, :format => @diary_entry.body_format %> +
+
+ + <%= f.collection_select :language_code, Language.order(:english_name), :code, :name %> +
+
+
+ + <%= content_tag "div", "", :id => "map", :data => { :lat => @lat, :lon => @lon, :zoom => @zoom } %> +
+
+ + <%= f.text_field :latitude, :size => 20, :id => "latitude" %> +
+
+ + <%= f.text_field :longitude, :size => 20, :id => "longitude" %> +
+ +
+
+ + <%= f.submit %> +
diff --git a/app/views/diary_entries/edit.html.erb b/app/views/diary_entries/edit.html.erb index bee94a595..eba18cbaf 100644 --- a/app/views/diary_entries/edit.html.erb +++ b/app/views/diary_entries/edit.html.erb @@ -9,39 +9,5 @@ <%= error_messages_for "diary_entry" %> <%= form_for @diary_entry, :url => diary_entry_path(current_user, @diary_entry), :html => { :method => :put } do |f| %> -
-
-
- - <%= f.text_field :title, :class => "richtext_title" %> -
-
- - <%= richtext_area :diary_entry, :body, :cols => 80, :rows => 20, :format => @diary_entry.body_format %> -
-
- - <%= f.collection_select :language_code, Language.order(:english_name), :code, :name %> -
-
-
- - <%= content_tag "div", "", :id => "map", :data => { :lat => @lat, :lon => @lon, :zoom => @zoom } %> -
-
- - <%= f.text_field :latitude, :size => 20, :id => "latitude" %> -
-
- - <%= f.text_field :longitude, :size => 20, :id => "longitude" %> -
- -
-
- - <%= submit_tag t(".save_button") %> -
+ <%= render :partial => "form", :locals => { :f => f } %> <% end %> diff --git a/app/views/diary_entries/new.html.erb b/app/views/diary_entries/new.html.erb index b1645d5c5..d71331fcf 100644 --- a/app/views/diary_entries/new.html.erb +++ b/app/views/diary_entries/new.html.erb @@ -9,39 +9,5 @@ <%= error_messages_for "diary_entry" %> <%= form_for @diary_entry do |f| %> -
-
-
- - <%= f.text_field :title, :class => "richtext_title" %> -
-
- - <%= richtext_area :diary_entry, :body, :cols => 80, :rows => 20, :format => @diary_entry.body_format %> -
-
- - <%= f.collection_select :language_code, Language.order(:english_name), :code, :name %> -
-
-
- - <%= content_tag "div", "", :id => "map", :data => { :lat => @lat, :lon => @lon, :zoom => @zoom } %> -
-
- - <%= f.text_field :latitude, :size => 20, :id => "latitude" %> -
-
- - <%= f.text_field :longitude, :size => 20, :id => "longitude" %> -
- -
-
- - <%= submit_tag t("diary_entries.new.publish_button") %> -
+ <%= render :partial => "form", :locals => { :f => f } %> <% end %> diff --git a/config/locales/en.yml b/config/locales/en.yml index 1b160c92e..ec6591226 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -5,6 +5,11 @@ en: formats: friendly: "%e %B %Y at %H:%M" blog: "%e %B %Y" + helpers: + submit: + diary_entry: + create: "Publish" + update: "Update" activerecord: errors: messages: @@ -282,6 +287,7 @@ en: diary_entries: new: title: New Diary Entry + form: subject: "Subject:" body: "Body:" language: "Language:" @@ -289,8 +295,6 @@ en: latitude: "Latitude:" longitude: "Longitude:" use_map_link: "use map" - marker_text: Diary entry location - publish_button: "Publish" index: title: "Users' diaries" title_friends: "Friends' diaries" @@ -304,15 +308,7 @@ en: older_entries: Older Entries newer_entries: Newer Entries edit: - title: "Edit diary entry" - subject: "Subject:" - body: "Body:" - language: "Language:" - location: "Location:" - latitude: "Latitude:" - longitude: "Longitude:" - use_map_link: "use map" - save_button: "Save" + title: Edit Diary Entry marker_text: Diary entry location show: title: "%{user}'s diary | %{title}" diff --git a/test/controllers/diary_entries_controller_test.rb b/test/controllers/diary_entries_controller_test.rb index bd9f0ed71..88a67ef12 100644 --- a/test/controllers/diary_entries_controller_test.rb +++ b/test/controllers/diary_entries_controller_test.rb @@ -279,9 +279,9 @@ class DiaryEntriesControllerTest < ActionController::TestCase :params => { :display_name => entry.user.display_name, :id => entry.id }, :session => { :user => entry.user } assert_response :success - assert_select "title", :text => /Edit diary entry/, :count => 1 + assert_select "title", :text => /Edit Diary Entry/, :count => 1 assert_select "div.content-heading", :count => 1 do - assert_select "h1", :text => /Edit diary entry/, :count => 1 + assert_select "h1", :text => /Edit Diary Entry/, :count => 1 end assert_select "div#content", :count => 1 do assert_select "form[action='/user/#{ERB::Util.u(entry.user.display_name)}/diary/#{entry.id}'][method=post]", :count => 1 do @@ -290,7 +290,7 @@ class DiaryEntriesControllerTest < ActionController::TestCase assert_select "select#diary_entry_language_code", :count => 1 assert_select "input#latitude[name='diary_entry[latitude]']", :count => 1 assert_select "input#longitude[name='diary_entry[longitude]']", :count => 1 - assert_select "input[name=commit][type=submit][value=Save]", :count => 1 + assert_select "input[name=commit][type=submit][value=Update]", :count => 1 assert_select "input[name=commit][type=submit][value=Edit]", :count => 1 assert_select "input[name=commit][type=submit][value=Preview]", :count => 1 assert_select "input", :count => 8