diff --git a/app/assets/javascripts/step_comments.js b/app/assets/javascripts/step_comments.js index e0d81aa37..c4b654672 100644 --- a/app/assets/javascripts/step_comments.js +++ b/app/assets/javascripts/step_comments.js @@ -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(); diff --git a/app/models/experiment.rb b/app/models/experiment.rb index 5723fdea1..a90a5a6ac 100644 --- a/app/models/experiment.rb +++ b/app/models/experiment.rb @@ -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. diff --git a/app/models/step.rb b/app/models/step.rb index bb1d169ef..2b59b1907 100644 --- a/app/models/step.rb +++ b/app/models/step.rb @@ -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) diff --git a/app/views/steps/_step.html.erb b/app/views/steps/_step.html.erb index 7396dda17..a4e8c943c 100644 --- a/app/views/steps/_step.html.erb +++ b/app/views/steps/_step.html.erb @@ -129,7 +129,8 @@ <% if can_view_step_comments(@protocol) %>
-
+
+
<% end %>