From e3ae22763e62f3cbf4613c47213a10db03120a3f Mon Sep 17 00:00:00 2001 From: zmagod Date: Thu, 15 Sep 2016 08:46:14 +0200 Subject: [PATCH 01/12] removed comments tab in protocol step --- app/assets/javascripts/step_comments.js | 54 +++++++++++++++++++++++++ app/views/my_modules/protocols.html.erb | 1 + app/views/step_comments/_index.html.erb | 6 ++- app/views/steps/_step.html.erb | 19 +++++---- config/initializers/assets.rb | 1 + 5 files changed, 69 insertions(+), 12 deletions(-) diff --git a/app/assets/javascripts/step_comments.js b/app/assets/javascripts/step_comments.js index dee720fac..f9715dd40 100644 --- a/app/assets/javascripts/step_comments.js +++ b/app/assets/javascripts/step_comments.js @@ -1,2 +1,56 @@ // Place all the behaviors and hooks related to the matching controller here. // All this logic will automatically be available in application.js. + + +(function(){ + + function initializeComments(){ + var steps = $(".step-comment"); + $.each(steps, function(){ + var that = $(this); + var link = that.attr("data-href"); + + $.ajax({ + method: 'GET', + url: link, + beforeSend: animateSpinner(that, true), + success: function(data){ + $(that.children()[0]).html(data.html); + animateSpinner(that, false); + }, + complete: animateSpinner(that, false) + }); + }); + } + + function refreshComments(child){ + var parent = chils.closest(".step-comment"); + var link = parent.attr("data-href"); + + $.ajax({ + method: 'GET', + url: link, + beforeSend: animateSpinner(parent, true), + success: function(data){ + $(parent.children()[0]).html(data.html); + animateSpinner(parent, false); + }, + complete: animateSpinner(parent, false) + }); + } + + function commentFormOnSubmitAction(){ + $(".comment-form") + .each(function() { + var obj = $(this); + debugger; + obj + .on('submit', function(){ + refreshComments(obj); + }); + }); + } + + initializeComments(); + commentFormOnSubmitAction(); +})(); diff --git a/app/views/my_modules/protocols.html.erb b/app/views/my_modules/protocols.html.erb index aed62bfba..cf95a38ef 100644 --- a/app/views/my_modules/protocols.html.erb +++ b/app/views/my_modules/protocols.html.erb @@ -44,3 +44,4 @@ <%= stylesheet_link_tag 'datatables' %> <%= javascript_include_tag("my_modules/protocols") %> +<%= javascript_include_tag("step_comments") %> diff --git a/app/views/step_comments/_index.html.erb b/app/views/step_comments/_index.html.erb index e8ae8b27d..b78a306d5 100644 --- a/app/views/step_comments/_index.html.erb +++ b/app/views/step_comments/_index.html.erb @@ -1,4 +1,6 @@ -
<%= t('protocols.steps.comments_tab') %>
+
+ + <%= t('protocols.steps.comments_tab') %>