fixed ajax call

This commit is contained in:
zmagod 2016-09-19 16:12:07 +02:00
parent 938aa32190
commit f48553e807
4 changed files with 77 additions and 58 deletions

View file

@ -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,19 +116,17 @@
$.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);
});
});
}
@ -140,45 +138,48 @@
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 bindCommentButton(){
$.each($(".comment-form"), function() {
$(this)
.on("submit", function() {
bindCommentAjax($(this));
});
});
}
// function bindMoreCommentButton(){
// $(".btn-more-comments")
// .each(function(){
// bindCommentAjax($(this));
// });
// }
function bindCommentAjax(form){
function bindCommentAjax(id){
$(document)
.on( 'ajax:success', function() {
debugger;
refreshComments($(form));
})
.on('ajax:error', function () {
refreshComments(form);
refreshComments($(id));
});
}
function updateCommentHTML(parent, data) {
var id = "#" + $(parent.find(".comment-form")).attr("id");
debugger;
var id;
if ( $(parent.find(".comment-form")).attr("id") !== undefined ) {
id = "#" + $(parent.find(".comment-form")).attr("id")
$(parent.children()[0]).html(data.html);
bindCommentAjax(id);
} else {
id = "#" + $( $.parseHTML(data.html) ).find(".comment-form").attr("id");
$(parent.children()[1]).html(data.html);
}
scrollBottom(parent);
}
initializeComments();

View file

@ -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.

View file

@ -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 %>