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.
This commit is contained in:
Andy Allan 2023-02-01 15:30:57 +00:00
parent 9748ce301c
commit 9bb8dd739a
3 changed files with 23 additions and 3 deletions

View 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);
}
});

View file

@ -51,7 +51,10 @@
<% 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>