mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2025-03-03 11:13:06 +08:00
Refactor result and step comments initialization [SCI-2830]
This commit is contained in:
parent
84df2c81f9
commit
fb309a12b9
10 changed files with 68 additions and 42 deletions
|
@ -16,18 +16,21 @@ var Comments = (function() {
|
|||
$.each(comments, function(){
|
||||
var that = $(this);
|
||||
var link = that.attr('data-href');
|
||||
$.ajax({ method: 'GET',
|
||||
url: link,
|
||||
beforeSend: animateSpinner(that, true) })
|
||||
.done(function(data) {
|
||||
that.html(data.html);
|
||||
initCommentForm(that);
|
||||
initCommentsLink(that);
|
||||
scrollBottom(that.find('.content-comments'));
|
||||
})
|
||||
.always(function() {
|
||||
animateSpinner(that, false);
|
||||
});
|
||||
if(that.html().length === 0) {
|
||||
$.ajax({ method: 'GET',
|
||||
url: link,
|
||||
beforeSend: animateSpinner(that, true) })
|
||||
.done(function(data) {
|
||||
that.html(data.html);
|
||||
|
||||
})
|
||||
.always(function() {
|
||||
animateSpinner(that, false);
|
||||
});
|
||||
}
|
||||
initCommentForm(that);
|
||||
initCommentsLink(that);
|
||||
scrollBottom(that.find('.content-comments'));
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -238,7 +241,8 @@ var Comments = (function() {
|
|||
}
|
||||
|
||||
function initDeleteComments(parent) {
|
||||
$(parent).on('click', '[data-action=delete-comment]', function() {
|
||||
$(parent).on('click', '[data-action=delete-comment]', function(ev) {
|
||||
ev.preventDefault();
|
||||
var $this = $(this);
|
||||
if (confirm($this.attr('data-confirm-message'))) {
|
||||
$.ajax({
|
||||
|
|
|
@ -18,9 +18,9 @@ class ResultCommentsController < ApplicationController
|
|||
# messages. 'list' partial is used for showing more
|
||||
# comments.
|
||||
partial = 'index.html.erb'
|
||||
partial = 'list.html.erb' if @last_comment_id > 0
|
||||
partial = 'list.html.erb' if @last_comment_id.positive?
|
||||
more_url = ''
|
||||
if @comments.count > 0
|
||||
if @comments.size.positive?
|
||||
more_url = url_for(result_result_comments_path(@result,
|
||||
format: :json,
|
||||
from: @comments
|
||||
|
@ -28,11 +28,14 @@ class ResultCommentsController < ApplicationController
|
|||
end
|
||||
render json: {
|
||||
perPage: @per_page,
|
||||
resultsNumber: @comments.length,
|
||||
resultsNumber: @comments.size,
|
||||
moreUrl: more_url,
|
||||
html: render_to_string(partial: partial,
|
||||
locals: { comments: @comments,
|
||||
more_comments_url: more_url })
|
||||
html: render_to_string(
|
||||
partial: partial,
|
||||
locals: {
|
||||
result: @result, comments: @comments, per_page: @per_page
|
||||
}
|
||||
)
|
||||
}
|
||||
end
|
||||
end
|
||||
|
|
|
@ -19,20 +19,21 @@ class StepCommentsController < ApplicationController
|
|||
# messages. 'list' partial is used for showing more
|
||||
# comments.
|
||||
partial = 'index.html.erb'
|
||||
partial = 'list.html.erb' if @last_comment_id > 0
|
||||
partial = 'list.html.erb' if @last_comment_id.positive?
|
||||
more_url = ''
|
||||
if @comments.count > 0
|
||||
if @comments.size.positive?
|
||||
more_url = url_for(step_step_comments_path(@step,
|
||||
format: :json,
|
||||
from: @comments.first.id))
|
||||
end
|
||||
render json: {
|
||||
perPage: @per_page,
|
||||
resultsNumber: @comments.length,
|
||||
resultsNumber: @comments.size,
|
||||
moreUrl: more_url,
|
||||
html: render_to_string(partial: partial,
|
||||
locals: { comments: @comments,
|
||||
more_comments_url: more_url })
|
||||
html: render_to_string(
|
||||
partial: partial,
|
||||
locals: { step: @step, comments: @comments, per_page: @per_page }
|
||||
)
|
||||
}
|
||||
end
|
||||
end
|
||||
|
|
|
@ -14,6 +14,6 @@
|
|||
</span>
|
||||
</div>
|
||||
<span class="help-block hide"></span>
|
||||
<a data-action="cancel" href="#"><%= t('general.cancel') %></a>
|
||||
<a data-action="cancel" data-turbolinks="false" href="#"><%= t('general.cancel') %></a>
|
||||
</div>
|
||||
<% end %>
|
||||
|
|
|
@ -51,6 +51,8 @@
|
|||
<div class="result-comment"
|
||||
id="result-comments-<%= result.id %>"
|
||||
data-href="<%= result_result_comments_url(result) %>">
|
||||
<%= render partial: "result_comments/index.html.erb",
|
||||
locals: { result: result, comments: result.last_comments, per_page: Constants::COMMENTS_SEARCH_LIMIT } %>
|
||||
</div>
|
||||
</div>
|
||||
<% end %>
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
<div>
|
||||
<strong>
|
||||
<%=t "my_modules.results.comment_title", user: comment.user.full_name, time: l(comment.created_at, format: :time) %>
|
||||
</strong>
|
||||
|
@ -28,7 +29,7 @@
|
|||
data-action="delete-comment"
|
||||
data-url="<%= result_result_comment_path(comment.result, comment, format: :json) %>"
|
||||
data-confirm-message="<%= t('comments.delete_confirm') %>"
|
||||
data-no-turbolink="true">
|
||||
data-turbolinks="false">
|
||||
<%= t('comments.options_dropdown.delete') %>
|
||||
</a>
|
||||
</li>
|
||||
|
|
|
@ -4,24 +4,30 @@
|
|||
</div>
|
||||
<hr>
|
||||
<ul class="no-style double-line content-comments">
|
||||
<% if @comments.length == @per_page %>
|
||||
<% if comments.size == per_page %>
|
||||
<li class="comment-more text-center">
|
||||
<a class="btn btn-default btn-more-comments" href="<%= more_comments_url %>" data-remote="true">
|
||||
<a class="btn btn-default btn-more-comments"
|
||||
href="<%= url_for(result_result_comments_path(result, format: :json, from: comments.first.id)) %>"
|
||||
data-remote="true">
|
||||
<%=t "general.more_comments" %>
|
||||
</a>
|
||||
</li>
|
||||
<% end %>
|
||||
<% if @comments.size == 0 then %>
|
||||
<% if comments.size == 0 then %>
|
||||
<li class="no-comments"><em><%= t 'general.no_comments' %></em></li>
|
||||
<% else %>
|
||||
<%= render 'result_comments/list.html.erb', comments: @comments %>
|
||||
<%= render 'result_comments/list.html.erb', comments: comments %>
|
||||
<% end %>
|
||||
</ul>
|
||||
<% if can_create_comments_in_module?(@my_module) then %>
|
||||
<ul class="no-style double-line">
|
||||
<li>
|
||||
<hr>
|
||||
<%= bootstrap_form_for :comment, url: { format: :json }, method: :post, remote: true, html: { class: 'comment-form' } do |f| %>
|
||||
<%= bootstrap_form_for :comment,
|
||||
url: result_result_comments_path(result, format: :json),
|
||||
method: :post,
|
||||
remote: true,
|
||||
html: { class: 'comment-form' } do |f| %>
|
||||
<%= f.smart_text_area :message,
|
||||
single_line: true,
|
||||
hide_label: true,
|
||||
|
|
|
@ -28,7 +28,8 @@
|
|||
<a href="#"
|
||||
data-action="delete-comment"
|
||||
data-url="<%= step_step_comment_path(comment.step, comment, format: :json) %>"
|
||||
data-confirm-message="<%= t('comments.delete_confirm') %>">
|
||||
data-confirm-message="<%= t('comments.delete_confirm') %>"
|
||||
data-turbolinks="false">
|
||||
<%= t('comments.options_dropdown.delete') %>
|
||||
</a>
|
||||
</li>
|
||||
|
|
|
@ -4,24 +4,30 @@
|
|||
</div>
|
||||
<hr>
|
||||
<ul class="no-style double-line content-comments">
|
||||
<% if @comments.length == @per_page %>
|
||||
<li class="comment-more text-center">
|
||||
<a class="btn btn-default btn-more-comments" href="<%= more_comments_url %>" data-remote="true">
|
||||
<%=t "general.more_comments" %>
|
||||
</a>
|
||||
</li>
|
||||
<% if comments.size == per_page %>
|
||||
<li class="comment-more text-center">
|
||||
<a class="btn btn-default btn-more-comments"
|
||||
href="<%= url_for(step_step_comments_path(step, format: :json, from: comments.first.id)) %>"
|
||||
data-remote="true">
|
||||
<%=t "general.more_comments" %>
|
||||
</a>
|
||||
</li>
|
||||
<% end %>
|
||||
<% if @comments.size == 0 then %>
|
||||
<% if comments.size == 0 %>
|
||||
<li class="no-comments"><em><%= t 'general.no_comments' %></em></li>
|
||||
<% else %>
|
||||
<%= render 'step_comments/list.html.erb', comments: @comments %>
|
||||
<%= render 'step_comments/list.html.erb', comments: comments %>
|
||||
<% end %>
|
||||
</ul>
|
||||
<% if can_create_comments_in_module?(@protocol.my_module) %>
|
||||
<ul class="no-style double-line">
|
||||
<li>
|
||||
<hr>
|
||||
<%= bootstrap_form_for :comment, url: { format: :json }, html: { class: 'comment-form', id: "step-comment-#{@step.id}" }, method: :post, remote: true do |f| %>
|
||||
<%= bootstrap_form_for :comment,
|
||||
url: step_step_comments_path(step, format: :json),
|
||||
html: { class: 'comment-form', id: "step-comment-#{step.id}" },
|
||||
method: :post,
|
||||
remote: true do |f| %>
|
||||
<%= f.smart_text_area :message,
|
||||
single_line: true,
|
||||
hide_label: true,
|
||||
|
|
|
@ -151,6 +151,8 @@
|
|||
<div class="step-comment"
|
||||
id="step-comments-<%= step.id %>"
|
||||
data-href="<%= url_for step_step_comments_path(step_id: step.id, format: :json) %>">
|
||||
<%= render partial: "step_comments/index.html.erb",
|
||||
locals: { step: step, comments: step.last_comments, per_page: Constants::COMMENTS_SEARCH_LIMIT } %>
|
||||
</div>
|
||||
</div>
|
||||
<% end %>
|
||||
|
|
Loading…
Reference in a new issue