We need to use page body event delegation so it will work with any element even with the ones added through ajax, in this case the annotation comments box form. By doing this way we do not need this code on the server response anymore. Furthermore JS events defined at ajax responses are not part of application javascript and are lost when restoring a page from browser cache, you can try to apply the same event delegation technique to the `erb` file and it wont work just because events added dinamically are not treated the same than `application.js` code. To reproduce the error: 1. Load an annotatable draft version 2. Move to any other page 3. Go back Now "Publish comment" button wont work.
49 lines
2.0 KiB
Plaintext
49 lines
2.0 KiB
Plaintext
<div class="comment-box" id="comments-box-<%= annotation.id %>" data-id="<%= annotation.id %>">
|
|
<div class="comment-header">
|
|
<%= render "comment_header", annotation: annotation %>
|
|
</div>
|
|
<div class="comments-wrapper">
|
|
<div id="comments">
|
|
<%= render "comments", annotation: annotation %>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="comment-footer">
|
|
<% if annotation.comments.roots.count > Legislation::Annotation::COMMENTS_PAGE_SIZE %>
|
|
<%= link_to legislation_process_draft_version_annotation_path(annotation.draft_version.process, annotation.draft_version, annotation), class: "button" do %>
|
|
<strong><%= t("legislation.annotations.comments.see_all") %></strong>
|
|
<% end %>
|
|
<% end %>
|
|
|
|
<% if @process.allegations_phase.open? %>
|
|
<a class="button publish-comment" href="#"><strong><%= t("legislation.annotations.comments.publish_comment") %></strong></a>
|
|
|
|
<% end %>
|
|
|
|
<% if @process.allegations_phase.open? %>
|
|
<% if user_signed_in? %>
|
|
<% css_id = parent_or_commentable_dom_id(nil, annotation) %>
|
|
<div id="js-comment-form-annotation-<%= annotation.id %>" style="display:none" class="comment-form js-comment-form-annotation">
|
|
<%= form_for @comment, url: legislation_process_draft_version_annotation_new_comment_path(annotation.draft_version.process, annotation.draft_version, annotation), remote: true do |f| %>
|
|
<%= f.text_area :body,
|
|
id: "comment-body-#{css_id}",
|
|
maxlength: Comment.body_max_length,
|
|
label: leave_comment_text(annotation),
|
|
rows: 8 %>
|
|
<%= f.submit comment_button_text(nil, annotation), class: "button" %>
|
|
<% end %>
|
|
</div>
|
|
<% else %>
|
|
|
|
<div>
|
|
<div class="participation-not-allowed" style="display: none;" aria-hidden="false">
|
|
<%= sanitize(t("users.login_to_comment",
|
|
signin: link_to_signin, signup: link_to_signup)) %>
|
|
</div>
|
|
</div>
|
|
|
|
<% end %>
|
|
<% end %>
|
|
</div>
|
|
</div>
|