mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2025-03-06 04:34:06 +08:00
fixed ajax call
This commit is contained in:
parent
938aa32190
commit
f48553e807
4 changed files with 77 additions and 58 deletions
|
@ -57,27 +57,27 @@
|
|||
// }
|
||||
//
|
||||
// // 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 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")
|
||||
|
@ -116,69 +116,70 @@
|
|||
$.each(steps, function(){
|
||||
var that = $(this);
|
||||
var link = that.attr("data-href");
|
||||
var parentNode = that.parents("ul").parent();
|
||||
debugger;
|
||||
$.ajax({ method: 'GET',
|
||||
url: link,
|
||||
beforeSend: animateSpinner(that, true) })
|
||||
.done(function(data){
|
||||
debugger;
|
||||
updateCommentHTML(that, data);
|
||||
bindCommentButton();
|
||||
initStepCommentsLink(that);
|
||||
animateSpinner(that, false);
|
||||
})
|
||||
.always(function(data){
|
||||
debugger;
|
||||
animateSpinner(that, false)
|
||||
animateSpinner(that, false);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function refreshComments(child){
|
||||
function refreshComments(child) {
|
||||
var parent = child.closest(".step-comment");
|
||||
var link = parent.attr("data-href");
|
||||
$.ajax({ method: 'GET',
|
||||
url: link,
|
||||
beforeSend: animateSpinner(parent, true) })
|
||||
.done(function(data){
|
||||
debugger;
|
||||
updateCommentHTML(parent, data);
|
||||
bindCommentButton();
|
||||
initStepCommentsLink(parent);
|
||||
animateSpinner(parent, false);
|
||||
})
|
||||
.always(animateSpinner(parent, false));
|
||||
|
||||
}
|
||||
|
||||
function commentFormOnSubmitAction(){
|
||||
$(".comment-form")
|
||||
.each(function() {
|
||||
debigger;
|
||||
bindCommentAjax("#" + $(this).attr("id"));
|
||||
});
|
||||
function scrollBottom(id) {
|
||||
var list = id.find(".content-comments");
|
||||
if ( list && list.length > 0) {
|
||||
list.scrollTop($(list)[0].scrollHeight);
|
||||
}
|
||||
}
|
||||
|
||||
// function bindMoreCommentButton(){
|
||||
// $(".btn-more-comments")
|
||||
// .each(function(){
|
||||
// bindCommentAjax($(this));
|
||||
// });
|
||||
// }
|
||||
function bindCommentButton(){
|
||||
$.each($(".comment-form"), function() {
|
||||
$(this)
|
||||
.on("submit", function() {
|
||||
bindCommentAjax($(this));
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function bindCommentAjax(form){
|
||||
function bindCommentAjax(id){
|
||||
$(document)
|
||||
.on('ajax:success', function () {
|
||||
debugger;
|
||||
refreshComments($(form));
|
||||
})
|
||||
.on('ajax:error', function () {
|
||||
refreshComments(form);
|
||||
.on( 'ajax:success', function() {
|
||||
refreshComments($(id));
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
function updateCommentHTML(parent, data) {
|
||||
var id = "#" + $(parent.find(".comment-form")).attr("id");
|
||||
debugger;
|
||||
$(parent.children()[0]).html(data.html);
|
||||
bindCommentAjax(id);
|
||||
var id;
|
||||
if ( $(parent.find(".comment-form")).attr("id") !== undefined ) {
|
||||
id = "#" + $(parent.find(".comment-form")).attr("id")
|
||||
$(parent.children()[0]).html(data.html);
|
||||
} else {
|
||||
id = "#" + $( $.parseHTML(data.html) ).find(".comment-form").attr("id");
|
||||
$(parent.children()[1]).html(data.html);
|
||||
}
|
||||
scrollBottom(parent);
|
||||
}
|
||||
|
||||
initializeComments();
|
||||
|
|
|
@ -377,6 +377,7 @@ class Experiment < ActiveRecord::Base
|
|||
end
|
||||
|
||||
save
|
||||
touch(:workflowimg_updated_at)
|
||||
end
|
||||
|
||||
# Get projects where user is either owner or user in the same organization
|
||||
|
@ -498,8 +499,11 @@ class Experiment < ActiveRecord::Base
|
|||
raise ActiveRecord::ActiveRecordError
|
||||
end
|
||||
|
||||
my_module.save!
|
||||
my_module.save
|
||||
end
|
||||
|
||||
# Generate workflow image for the experiment in which we moved the task
|
||||
generate_workflow_img_for_moved_modules(to_move)
|
||||
end
|
||||
|
||||
# Move module groups; this method accepts a map where keys
|
||||
|
@ -543,6 +547,19 @@ class Experiment < ActiveRecord::Base
|
|||
group.save!
|
||||
end
|
||||
end
|
||||
|
||||
# Generate workflow image for the experiment in which we moved the workflow
|
||||
generate_workflow_img_for_moved_modules(to_move)
|
||||
end
|
||||
|
||||
# Generates workflow img when the workflow or module is moved
|
||||
# to other experiment
|
||||
def generate_workflow_img_for_moved_modules(to_move)
|
||||
to_move.values.uniq.each do |id|
|
||||
experiment = Experiment.find_by_id(id)
|
||||
next unless experiment
|
||||
experiment.delay.generate_workflow_img
|
||||
end
|
||||
end
|
||||
|
||||
# Update connections for all modules in this project.
|
||||
|
|
|
@ -90,10 +90,10 @@ class Step < ActiveRecord::Base
|
|||
def last_comments(last_id = 1, per_page = 20)
|
||||
last_id = 9999999999999 if last_id <= 1
|
||||
Comment.joins(:step_comment)
|
||||
.where(step_comments: {step_id: id})
|
||||
.where('comments.id < ?', last_id)
|
||||
.order(created_at: :asc)
|
||||
.limit(per_page)
|
||||
.where(step_comments: { step_id: id })
|
||||
.where('comments.id < ?', last_id)
|
||||
.order(created_at: :asc)
|
||||
.limit(per_page)
|
||||
end
|
||||
|
||||
def save(current_user=nil)
|
||||
|
|
|
@ -129,7 +129,8 @@
|
|||
<% if can_view_step_comments(@protocol) %>
|
||||
<div class="row">
|
||||
<div class="step-comment" data-href="<%= url_for step_step_comments_path(step_id: step.id, format: :json) %>">
|
||||
<div id="step-comments-<%= step.id %>"></div>
|
||||
<div id="step-comments-<%= step.id %>">
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<% end %>
|
||||
|
|
Loading…
Reference in a new issue