From: Andy Allan Date: Wed, 1 Feb 2023 15:30:57 +0000 (+0000) Subject: Use data attributes to pass alternative button labels X-Git-Tag: live~1365^2~2 X-Git-Url: https://git.openstreetmap.org./rails.git/commitdiff_plain/9bb8dd739a4342441e97254bbf5073f9df022672?hp=9748ce301c9488b9cd32439448770c3d4a38ebd6 Use data attributes to pass alternative button labels This allows the text to be defined in the html partials, instead of looking up the i18n via javascript. --- diff --git a/app/assets/javascripts/index/note.js b/app/assets/javascripts/index/note.js index e5eb3a041..e7790c904 100644 --- a/app/assets/javascripts/index/note.js +++ b/app/assets/javascripts/index/note.js @@ -60,10 +60,10 @@ OSM.Note = function (map) { var form = e.target.form; if ($(e.target).val() === "") { - $(form.close).val(I18n.t("javascripts.notes.show.resolve")); + $(form.close).val($(form.close).data("defaultActionText")); $(form.comment).prop("disabled", true); } else { - $(form.close).val(I18n.t("javascripts.notes.show.comment_and_resolve")); + $(form.close).val($(form.close).data("commentActionText")); $(form.comment).prop("disabled", false); } }); diff --git a/app/views/notes/show.html.erb b/app/views/notes/show.html.erb index 3373b0b6d..980b5062c 100644 --- a/app/views/notes/show.html.erb +++ b/app/views/notes/show.html.erb @@ -51,7 +51,10 @@ <% if current_user.moderator? -%> " class="btn btn-light" data-method="DELETE" data-url="<%= api_note_url(@note, "json") %>"> <% end -%> - " class="btn btn-primary" data-method="POST" data-url="<%= close_api_note_url(@note, "json") %>"> + " class="btn btn-primary" + data-method="POST" data-url="<%= close_api_note_url(@note, "json") %>" + data-default-action-text="<%= t("javascripts.notes.show.resolve") %>" + data-comment-action-text="<%= t("javascripts.notes.show.comment_and_resolve") %>"> " class="btn btn-primary" data-method="POST" data-url="<%= comment_api_note_url(@note, "json") %>" disabled="1"> diff --git a/test/system/note_comments_test.rb b/test/system/note_comments_test.rb new file mode 100644 index 000000000..23f3fc98e --- /dev/null +++ b/test/system/note_comments_test.rb @@ -0,0 +1,17 @@ +require "application_system_test_case" + +class NoteCommentsTest < ApplicationSystemTestCase + def test_action_text + note = create(:note_with_comments) + sign_in_as(create(:user)) + visit note_path(note) + + assert_button "Resolve" + assert_button "Comment", :disabled => true + + fill_in "text", :with => "Some text" + + assert_button "Comment & Resolve" + assert_button "Comment" + end +end