]> git.openstreetmap.org Git - rails.git/commitdiff
Use data attributes to pass alternative button labels
authorAndy Allan <git@gravitystorm.co.uk>
Wed, 1 Feb 2023 15:30:57 +0000 (15:30 +0000)
committerAndy Allan <git@gravitystorm.co.uk>
Wed, 1 Feb 2023 17:24:47 +0000 (17:24 +0000)
This allows the text to be defined in the html partials, instead
of looking up the i18n via javascript.

app/assets/javascripts/index/note.js
app/views/notes/show.html.erb
test/system/note_comments_test.rb [new file with mode: 0644]

index e5eb3a04148112279862854d3136ced79cbfe175..e7790c904b111804f7332b46cc7a81bffcee654e 100644 (file)
@@ -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);
       }
     });
index 3373b0b6dada316b82248f9d4d2f0bd0a4094f86..980b5062cf858258a1ac76666bb72d828e4e874a 100644 (file)
           <% if current_user.moderator? -%>
             <input type="submit" name="hide" value="<%= t("javascripts.notes.show.hide") %>" class="btn btn-light" data-method="DELETE" data-url="<%= api_note_url(@note, "json") %>">
           <% end -%>
-          <input type="submit" name="close" value="<%= t("javascripts.notes.show.resolve") %>" class="btn btn-primary" data-method="POST" data-url="<%= close_api_note_url(@note, "json") %>">
+          <input type="submit" name="close" value="<%= t("javascripts.notes.show.resolve") %>" 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") %>">
           <input type="submit" name="comment" value="<%= t("javascripts.notes.show.comment") %>" class="btn btn-primary" data-method="POST" data-url="<%= comment_api_note_url(@note, "json") %>" disabled="1">
         </div>
       </form>
diff --git a/test/system/note_comments_test.rb b/test/system/note_comments_test.rb
new file mode 100644 (file)
index 0000000..23f3fc9
--- /dev/null
@@ -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