Merge remote-tracking branch 'upstream/pull/4462'

This commit is contained in:
Tom Hughes 2024-01-17 18:41:16 +00:00
commit 9387df9141
4 changed files with 129 additions and 24 deletions

View file

@ -52,20 +52,18 @@ OSM.Note = function (map) {
OSM.loadSidebarContent(path, function () {
initialize(path, id, moveToNote);
});
},
error: function (xhr) {
$(form).find("#comment-error")
.text(xhr.responseText)
.prop("hidden", false);
updateButtons(form);
}
});
});
content.find("textarea").on("input", function (e) {
var form = e.target.form;
if ($(e.target).val() === "") {
$(form.close).val($(form.close).data("defaultActionText"));
$(form.comment).prop("disabled", true);
} else {
$(form.close).val($(form.close).data("commentActionText"));
$(form.comment).prop("disabled", false);
}
updateButtons(e.target.form);
});
content.find("textarea").val("").trigger("input");
@ -84,6 +82,17 @@ OSM.Note = function (map) {
if (callback) callback();
}
function updateButtons(form) {
$(form).find("input[type=submit]").prop("disabled", false);
if ($(form.text).val() === "") {
$(form.close).val($(form.close).data("defaultActionText"));
$(form.comment).prop("disabled", true);
} else {
$(form.close).val($(form.close).data("commentActionText"));
$(form.comment).prop("disabled", false);
}
}
function moveToNote() {
var data = $(".details").data();
if (!data) return;

View file

@ -49,6 +49,8 @@
<div class="mb-3">
<textarea class="form-control" name="text" cols="40" rows="5" maxlength="2000"></textarea>
</div>
<div id="comment-error" class="alert alert-danger p-2 mb-3" hidden>
</div>
<div class="btn-wrapper">
<% if current_user.moderator? -%>
<%= submit_tag t(".hide"), :name => "hide", :class => "btn btn-light",
@ -73,6 +75,8 @@
<% else %>
<form class="mb-3" action="#">
<input type="hidden" name="text" value="" autocomplete="off">
<div id="comment-error" class="alert alert-danger p-2 mb-3" hidden>
</div>
<div class="btn-wrapper">
<% if @note.status != "hidden" and current_user and current_user.moderator? -%>
<input type="submit" name="hide" value="<%= t(".hide") %>" class="btn btn-light" data-method="DELETE" data-url="<%= api_note_url(@note, "json") %>">