mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2025-02-21 22:33:13 +08:00
js tweaks
This commit is contained in:
parent
635f6b92d6
commit
938aa32190
4 changed files with 138 additions and 122 deletions
|
@ -354,116 +354,6 @@ function initEditableHandsOnTable(root) {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// Initialize comment form.
|
|
||||||
function initStepCommentForm(ev, $el) {
|
|
||||||
var $form = $el.find("ul form");
|
|
||||||
|
|
||||||
var $commentInput = $form.find("#comment_message");
|
|
||||||
|
|
||||||
$(".help-block", $form).addClass("hide");
|
|
||||||
|
|
||||||
$form
|
|
||||||
.on("ajax:send", function (data) {
|
|
||||||
$("#comment_message", $form).attr("readonly", true);
|
|
||||||
})
|
|
||||||
.on("ajax:success", function (e, data) {
|
|
||||||
if (data.html) {
|
|
||||||
var list = $form.parents("ul");
|
|
||||||
|
|
||||||
// Remove potential "no comments" element
|
|
||||||
list.parent().find(".content-comments")
|
|
||||||
.find("li.no-comments").remove();
|
|
||||||
|
|
||||||
list.parent().find(".content-comments")
|
|
||||||
.prepend("<li class='comment'>" + data.html + "</li>")
|
|
||||||
.scrollTop(0);
|
|
||||||
list.parents("ul").find("> li.comment:gt(8)").remove();
|
|
||||||
$("#comment_message", $form).val("");
|
|
||||||
$(".form-group", $form)
|
|
||||||
.removeClass("has-error");
|
|
||||||
$(".help-block", $form)
|
|
||||||
.html("")
|
|
||||||
.addClass("hide");
|
|
||||||
scrollCommentOptions(
|
|
||||||
list.parent().find(".content-comments .dropdown-comment")
|
|
||||||
);
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.on("ajax:error", function (ev, xhr) {
|
|
||||||
if (xhr.status === 400) {
|
|
||||||
var messageError = xhr.responseJSON.errors.message;
|
|
||||||
|
|
||||||
if (messageError) {
|
|
||||||
$(".form-group", $form)
|
|
||||||
.addClass("has-error");
|
|
||||||
$(".help-block", $form)
|
|
||||||
.html(messageError[0])
|
|
||||||
.removeClass("hide");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.on("ajax:complete", function () {
|
|
||||||
$("#comment_message", $form)
|
|
||||||
.attr("readonly", false)
|
|
||||||
.focus();
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
// Initialize show more comments link.
|
|
||||||
function initStepCommentsLink($el) {
|
|
||||||
$el.find(".btn-more-comments")
|
|
||||||
.on("ajax:success", function (e, data) {
|
|
||||||
if (data.html) {
|
|
||||||
var list = $(this).parents("ul");
|
|
||||||
var moreBtn = list.find(".btn-more-comments");
|
|
||||||
var listItem = moreBtn.parents('li');
|
|
||||||
$(data.html).insertBefore(listItem);
|
|
||||||
if (data.results_number < data.per_page) {
|
|
||||||
moreBtn.remove();
|
|
||||||
} else {
|
|
||||||
moreBtn.attr("href", data.more_url);
|
|
||||||
moreBtn.trigger("blur");
|
|
||||||
}
|
|
||||||
|
|
||||||
// Reposition dropdown comment options
|
|
||||||
scrollCommentOptions(listItem.closest(".content-comments")
|
|
||||||
.find(".dropdown-comment"));
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
function initStepCommentTabAjax() {
|
|
||||||
$(".comment-tab-link")
|
|
||||||
.on("ajax:before", function (e) {
|
|
||||||
var $this = $(this);
|
|
||||||
var parentNode = $this.parents("li");
|
|
||||||
var targetId = $this.attr("aria-controls");
|
|
||||||
|
|
||||||
if (parentNode.hasClass("active")) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.on("ajax:success", function (e, data) {
|
|
||||||
if (data.html) {
|
|
||||||
var $this = $(this);
|
|
||||||
var targetId = $this.attr("aria-controls");
|
|
||||||
var target = $("#" + targetId);
|
|
||||||
var parentNode = $this.parents("ul").parent();
|
|
||||||
|
|
||||||
target.html(data.html);
|
|
||||||
initStepCommentForm(e, parentNode);
|
|
||||||
initStepCommentsLink(parentNode);
|
|
||||||
|
|
||||||
parentNode.find(".active").removeClass("active");
|
|
||||||
$this.parents("li").addClass("active");
|
|
||||||
target.addClass("active");
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.on("ajax:error", function(e, xhr, status, error) {
|
|
||||||
// TODO
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
function applyCancelOnNew() {
|
function applyCancelOnNew() {
|
||||||
$("[data-action='cancel-new']").click(function() {
|
$("[data-action='cancel-new']").click(function() {
|
||||||
var $form = $(this).closest("form");
|
var $form = $(this).closest("form");
|
||||||
|
@ -486,7 +376,6 @@ function initCallBacks() {
|
||||||
applyEditCallBack();
|
applyEditCallBack();
|
||||||
applyMoveStepCallBack();
|
applyMoveStepCallBack();
|
||||||
applyCollapseLinkCallBack();
|
applyCollapseLinkCallBack();
|
||||||
initStepCommentTabAjax();
|
|
||||||
initDeleteStep();
|
initDeleteStep();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,19 +1,135 @@
|
||||||
(function(){
|
(function(){
|
||||||
|
"use strict";
|
||||||
|
|
||||||
|
// // Initialize comment form.
|
||||||
|
// function initStepCommentForm(ev, $el) {
|
||||||
|
// var $form = $el.find("ul form");
|
||||||
|
//
|
||||||
|
// var $commentInput = $form.find("#comment_message");
|
||||||
|
//
|
||||||
|
// $(".help-block", $form).addClass("hide");
|
||||||
|
//
|
||||||
|
// $form
|
||||||
|
// .on("ajax:send", function (data) {
|
||||||
|
// $("#comment_message", $form).attr("readonly", true);
|
||||||
|
// })
|
||||||
|
// .on("ajax:success", function (e, data) {
|
||||||
|
// if (data.html) {
|
||||||
|
// var list = $form.parents("ul");
|
||||||
|
//
|
||||||
|
// // Remove potential "no comments" element
|
||||||
|
// list.parent().find(".content-comments")
|
||||||
|
// .find("li.no-comments").remove();
|
||||||
|
//
|
||||||
|
// list.parent().find(".content-comments")
|
||||||
|
// .prepend("<li class='comment'>" + data.html + "</li>")
|
||||||
|
// .scrollTop(0);
|
||||||
|
// list.parents("ul").find("> li.comment:gt(8)").remove();
|
||||||
|
// $("#comment_message", $form).val("");
|
||||||
|
// $(".form-group", $form)
|
||||||
|
// .removeClass("has-error");
|
||||||
|
// $(".help-block", $form)
|
||||||
|
// .html("")
|
||||||
|
// .addClass("hide");
|
||||||
|
// scrollCommentOptions(
|
||||||
|
// list.parent().find(".content-comments .dropdown-comment")
|
||||||
|
// );
|
||||||
|
// }
|
||||||
|
// })
|
||||||
|
// .on("ajax:error", function (ev, xhr) {
|
||||||
|
// if (xhr.status === 400) {
|
||||||
|
// var messageError = xhr.responseJSON.errors.message;
|
||||||
|
//
|
||||||
|
// if (messageError) {
|
||||||
|
// $(".form-group", $form)
|
||||||
|
// .addClass("has-error");
|
||||||
|
// $(".help-block", $form)
|
||||||
|
// .html(messageError[0])
|
||||||
|
// .removeClass("hide");
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// })
|
||||||
|
// .on("ajax:complete", function () {
|
||||||
|
// $("#comment_message", $form)
|
||||||
|
// .attr("readonly", false)
|
||||||
|
// .focus();
|
||||||
|
// });
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// // Initialize show more comments link.
|
||||||
|
// function initStepCommentsLink($el) {
|
||||||
|
// $el.find(".btn-more-comments")
|
||||||
|
// .on("ajax:success", function (e, data) {
|
||||||
|
// if (data.html) {
|
||||||
|
// var list = $(this).parents("ul");
|
||||||
|
// var moreBtn = list.find(".btn-more-comments");
|
||||||
|
// var listItem = moreBtn.parents('li');
|
||||||
|
// $(data.html).insertBefore(listItem);
|
||||||
|
// if (data.results_number < data.per_page) {
|
||||||
|
// moreBtn.remove();
|
||||||
|
// } else {
|
||||||
|
// moreBtn.attr("href", data.more_url);
|
||||||
|
// moreBtn.trigger("blur");
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// // Reposition dropdown comment options
|
||||||
|
// scrollCommentOptions(listItem.closest(".content-comments")
|
||||||
|
// .find(".dropdown-comment"));
|
||||||
|
// }
|
||||||
|
// });
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// function initStepCommentTabAjax() {
|
||||||
|
// $(".comment-tab-link")
|
||||||
|
// .on("ajax:before", function (e) {
|
||||||
|
// var $this = $(this);
|
||||||
|
// var parentNode = $this.parents("li");
|
||||||
|
// var targetId = $this.attr("aria-controls");
|
||||||
|
//
|
||||||
|
// if (parentNode.hasClass("active")) {
|
||||||
|
// return false;
|
||||||
|
// }
|
||||||
|
// })
|
||||||
|
// .on("ajax:success", function (e, data) {
|
||||||
|
// if (data.html) {
|
||||||
|
// var $this = $(this);
|
||||||
|
// var targetId = $this.attr("aria-controls");
|
||||||
|
// var target = $("#" + targetId);
|
||||||
|
// var parentNode = $this.parents("ul").parent();
|
||||||
|
//
|
||||||
|
// target.html(data.html);
|
||||||
|
// initStepCommentForm(e, parentNode);
|
||||||
|
// initStepCommentsLink(parentNode);
|
||||||
|
//
|
||||||
|
// parentNode.find(".active").removeClass("active");
|
||||||
|
// $this.parents("li").addClass("active");
|
||||||
|
// target.addClass("active");
|
||||||
|
// }
|
||||||
|
// })
|
||||||
|
// .on("ajax:error", function(e, xhr, status, error) {
|
||||||
|
// // TODO
|
||||||
|
// });
|
||||||
|
// }
|
||||||
|
|
||||||
function initializeComments(){
|
function initializeComments(){
|
||||||
var steps = $(".step-comment");
|
var steps = $(".step-comment");
|
||||||
$.each(steps, function(){
|
$.each(steps, function(){
|
||||||
var that = $(this);
|
var that = $(this);
|
||||||
var link = that.attr("data-href");
|
var link = that.attr("data-href");
|
||||||
|
var parentNode = that.parents("ul").parent();
|
||||||
|
debugger;
|
||||||
$.ajax({ method: 'GET',
|
$.ajax({ method: 'GET',
|
||||||
url: link,
|
url: link,
|
||||||
beforeSend: animateSpinner(that, true) })
|
beforeSend: animateSpinner(that, true) })
|
||||||
.done(function(data){
|
.done(function(data){
|
||||||
|
debugger;
|
||||||
updateCommentHTML(that, data);
|
updateCommentHTML(that, data);
|
||||||
animateSpinner(that, false);
|
animateSpinner(that, false);
|
||||||
})
|
})
|
||||||
.always(animateSpinner(that, false));
|
.always(function(data){
|
||||||
|
debugger;
|
||||||
|
animateSpinner(that, false)
|
||||||
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -24,6 +140,7 @@
|
||||||
url: link,
|
url: link,
|
||||||
beforeSend: animateSpinner(parent, true) })
|
beforeSend: animateSpinner(parent, true) })
|
||||||
.done(function(data){
|
.done(function(data){
|
||||||
|
debugger;
|
||||||
updateCommentHTML(parent, data);
|
updateCommentHTML(parent, data);
|
||||||
animateSpinner(parent, false);
|
animateSpinner(parent, false);
|
||||||
})
|
})
|
||||||
|
@ -34,23 +151,33 @@
|
||||||
function commentFormOnSubmitAction(){
|
function commentFormOnSubmitAction(){
|
||||||
$(".comment-form")
|
$(".comment-form")
|
||||||
.each(function() {
|
.each(function() {
|
||||||
|
debigger;
|
||||||
bindCommentAjax("#" + $(this).attr("id"));
|
bindCommentAjax("#" + $(this).attr("id"));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// function bindMoreCommentButton(){
|
||||||
|
// $(".btn-more-comments")
|
||||||
|
// .each(function(){
|
||||||
|
// bindCommentAjax($(this));
|
||||||
|
// });
|
||||||
|
// }
|
||||||
|
|
||||||
function bindCommentAjax(form){
|
function bindCommentAjax(form){
|
||||||
$(document)
|
$(document)
|
||||||
.on('ajax:success', function () {
|
.on('ajax:success', function () {
|
||||||
refreshComments($(form));
|
debugger;
|
||||||
|
refreshComments($(form));
|
||||||
})
|
})
|
||||||
.on('ajax:error', function () {
|
.on('ajax:error', function () {
|
||||||
refreshComments(form);
|
refreshComments(form);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function updateCommentHTML(parent, data) {
|
function updateCommentHTML(parent, data) {
|
||||||
$(parent.children()[0]).html(data.html);
|
|
||||||
var id = "#" + $(parent.find(".comment-form")).attr("id");
|
var id = "#" + $(parent.find(".comment-form")).attr("id");
|
||||||
|
debugger;
|
||||||
|
$(parent.children()[0]).html(data.html);
|
||||||
bindCommentAjax(id);
|
bindCommentAjax(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -92,7 +92,7 @@ class Step < ActiveRecord::Base
|
||||||
Comment.joins(:step_comment)
|
Comment.joins(:step_comment)
|
||||||
.where(step_comments: {step_id: id})
|
.where(step_comments: {step_id: id})
|
||||||
.where('comments.id < ?', last_id)
|
.where('comments.id < ?', last_id)
|
||||||
.order(created_at: :desc)
|
.order(created_at: :asc)
|
||||||
.limit(per_page)
|
.limit(per_page)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -1,11 +1,6 @@
|
||||||
<h5 class="text-center"><%= t('protocols.steps.comments_tab') %></h5>
|
<h5 class="text-center"><%= t('protocols.steps.comments_tab') %></h5>
|
||||||
<hr>
|
<hr>
|
||||||
<ul class="no-style double-line content-comments">
|
<ul class="no-style double-line content-comments">
|
||||||
<% if @comments.size == 0 then %>
|
|
||||||
<li class="no-comments"><em><%= t 'general.no_comments' %></em></li>
|
|
||||||
<% else %>
|
|
||||||
<%= render 'step_comments/list.html.erb', comments: @comments %>
|
|
||||||
<% end %>
|
|
||||||
<% if @comments.length == @per_page %>
|
<% if @comments.length == @per_page %>
|
||||||
<li class="comment-more text-center">
|
<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="<%= more_comments_url %>" data-remote="true">
|
||||||
|
@ -13,6 +8,11 @@
|
||||||
</a>
|
</a>
|
||||||
</li>
|
</li>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
<% if @comments.size == 0 then %>
|
||||||
|
<li class="no-comments"><em><%= t 'general.no_comments' %></em></li>
|
||||||
|
<% else %>
|
||||||
|
<%= render 'step_comments/list.html.erb', comments: @comments %>
|
||||||
|
<% end %>
|
||||||
</ul>
|
</ul>
|
||||||
<% if can_add_step_comment_in_protocol(@protocol) %>
|
<% if can_add_step_comment_in_protocol(@protocol) %>
|
||||||
<ul class="no-style double-line">
|
<ul class="no-style double-line">
|
||||||
|
|
Loading…
Reference in a new issue