diff --git a/app/assets/javascripts/my_modules.js b/app/assets/javascripts/my_modules.js index cbae6e069..3ad7e2fd7 100644 --- a/app/assets/javascripts/my_modules.js +++ b/app/assets/javascripts/my_modules.js @@ -1,3 +1,4 @@ + // Bind ajax for editing descriptions function bindEditDescriptionAjax() { var editDescriptionModal = $("#manage-module-description-modal"); diff --git a/app/assets/javascripts/my_modules/results.js b/app/assets/javascripts/my_modules/results.js index aa2c45a98..e153fbd54 100644 --- a/app/assets/javascripts/my_modules/results.js +++ b/app/assets/javascripts/my_modules/results.js @@ -1,3 +1,43 @@ +function results_comment_edit(id) { + document.getElementById('edit_comment_'+id).type='text'; + $('#span_comment_'+id).hide(); + return false; +} + +function results_update_comment(id) { + if (document.getElementById('edit_comment_'+id).type=='text') { + var txt = document.getElementById('edit_comment_'+id).value; + $.ajax({ + type: "POST", + url: '/projects/update_comment_results', + dataType: 'json', + data: {id: id, msg: txt}, + success: function (data) { + document.getElementById('edit_comment_'+id).type='hidden'; + var txt = document.getElementById('edit_comment_'+id).value; + $('#span_comment_'+id).text(txt); + $('#span_comment_'+id).show(); + } + }); + } +} + +function results_comment_delete(id) { + if (confirm('Are you sure you want to delete this comment?')) { + $.ajax({ + type: "POST", + url: '/projects/delete_comment_results', + dataType: 'json', + data: {id: id}, + success: function (data) { + $('.content-comments').find('#'+id).remove(); + } + }); + } + + return false; +} + function initHandsOnTables(root) { root.find("div.hot-table").each(function() { var $container = $(this).find(".step-result-hot-table"); @@ -41,13 +81,15 @@ function initResultCommentForm($el) { .on("ajax:success", function (e, data) { if (data.html) { var list = $form.parents("ul"); + var s1 = data.html + var id = s1.substring(s1.lastIndexOf("delete(")+7,s1.lastIndexOf(")'")) // Remove potential "no comments" element list.parent().find(".content-comments") .find("li.no-comments").remove(); list.parent().find(".content-comments") - .prepend("
  • " + data.html + "
  • ") + .prepend("
  • " + data.html + "
  • ") .scrollTop(0); list.parents("ul").find("> li.comment:gt(8)").remove(); $("#comment_message", $form).val(""); diff --git a/app/assets/javascripts/projects/canvas.js b/app/assets/javascripts/projects/canvas.js index 2d3be3200..e077ea582 100644 --- a/app/assets/javascripts/projects/canvas.js +++ b/app/assets/javascripts/projects/canvas.js @@ -676,13 +676,15 @@ function bindFullZoomAjaxTabs() { .on("ajax:success", function (e, data) { if (data.html) { var list = $form.parents("ul"); + var s1 = data.html + var id = s1.substring(s1.lastIndexOf("delete(")+7,s1.lastIndexOf(")'")) // Remove potential "no comments" element list.parent().find(".content-comments") .find("li.no-comments").remove(); list.parent().find(".content-comments") - .prepend("
  • " + data.html + "
  • ") + .prepend("
  • " + data.html + "
  • ") .scrollTop(0); list.parents("ul").find("> li.comment:gt(8)").remove(); $("#comment_message", $form).val(""); @@ -3484,3 +3486,43 @@ function showTutorial() { var currentProjectId = $("#canvas-container").attr("data-project-id"); return tutorialProjectId == currentProjectId; } + +function module_comment_edit(id) { + document.getElementById('edit_comment_'+id).type='text'; + $('#span_comment_'+id).hide(); + return false; +} + +function module_update_comment(id) { + if (document.getElementById('edit_comment_'+id).type=='text') { + var txt = document.getElementById('edit_comment_'+id).value; + $.ajax({ + type: "POST", + url: '/projects/update_comment_modules', + dataType: 'json', + data: {id: id, msg: txt}, + success: function (data) { + document.getElementById('edit_comment_'+id).type='hidden'; + var txt = document.getElementById('edit_comment_'+id).value; + $('#span_comment_'+id).text(txt); + $('#span_comment_'+id).show(); + } + }); + } +} + +function module_comment_delete(id) { + if (confirm('Are you sure you want to delete this comment?')) { + $.ajax({ + type: "POST", + url: '/projects/delete_comment_modules', + dataType: 'json', + data: {id: id}, + success: function (data) { + $('.content-comments').find('#'+id).remove(); + } + }); + } + + return false; +} diff --git a/app/assets/javascripts/projects/index.js b/app/assets/javascripts/projects/index.js index 746b790aa..21ada4c6f 100644 --- a/app/assets/javascripts/projects/index.js +++ b/app/assets/javascripts/projects/index.js @@ -7,6 +7,46 @@ // - refresh project users tab after manage user modal is closed // - refactor view handling using library, ex. backbone.js +function project_comment_edit(id) { + document.getElementById('edit_comment_'+id).type='text'; + $('#span_comment_'+id).hide(); + return false; +} + +function project_update_comment(id) { + if (document.getElementById('edit_comment_'+id).type=='text') { + var txt = document.getElementById('edit_comment_'+id).value; + $.ajax({ + type: "POST", + url: '/projects/update_comment_projects', + dataType: 'json', + data: {id: id, msg: txt}, + success: function (data) { + document.getElementById('edit_comment_'+id).type='hidden'; + var txt = document.getElementById('edit_comment_'+id).value; + $('#span_comment_'+id).text(txt); + $('#span_comment_'+id).show(); + } + }); + } +} + +function project_comment_delete(id) { + if (confirm('Are you sure you want to delete this comment?')) { + $.ajax({ + type: "POST", + url: '/projects/delete_comment_projects', + dataType: 'json', + data: {id: id}, + success: function (data) { + $('.content-comments').find('#'+id).remove(); + } + }); + } + + return false; +} + (function () { var newProjectModal = null; @@ -215,13 +255,15 @@ .on("ajax:success", function (e, data) { if (data.html) { var list = $form.parents("ul"); + var s1 = data.html + var id = s1.substring(s1.lastIndexOf("delete(")+7,s1.lastIndexOf(")'")) // Remove potential "no comments" element list.parent().find(".content-comments") .find("li.no-comments").remove(); list.parent().find(".content-comments") - .prepend("
  • " + data.html + "
  • ") + .prepend("
  • " + data.html + "
  • ") .scrollTop(0); list.parents("ul").find("> li.comment:gt(8)").remove(); $("#comment_message", $form).val(""); diff --git a/app/assets/javascripts/protocols/steps.js b/app/assets/javascripts/protocols/steps.js index 8508b7809..0f0f9d374 100644 --- a/app/assets/javascripts/protocols/steps.js +++ b/app/assets/javascripts/protocols/steps.js @@ -386,13 +386,15 @@ function initStepCommentForm($el) { .on("ajax:success", function (e, data) { if (data.html) { var list = $form.parents("ul"); + var s1 = data.html + var id = s1.substring(s1.lastIndexOf("delete(")+7,s1.lastIndexOf(")'")) // Remove potential "no comments" element list.parent().find(".content-comments") .find("li.no-comments").remove(); list.parent().find(".content-comments") - .prepend("
  • " + data.html + "
  • ") + .prepend("
  • " + data.html + "
  • ") .scrollTop(0); list.parents("ul").find("> li.comment:gt(8)").remove(); $("#comment_message", $form).val(""); @@ -423,9 +425,48 @@ function initStepCommentForm($el) { }); } +function comment_delete(id) { + if (confirm('Are you sure you want to delete this comment?')) { + $.ajax({ + type: "POST", + url: '/protocols/delete_comment', + dataType: 'json', + data: {id: id}, + success: function (data) { + $('.content-comments').find('#'+id).remove(); + } + }); + } + + return false; +} + +function update_comment(id) { + if (document.getElementById('edit_comment_'+id).type=='text') { + var txt = document.getElementById('edit_comment_'+id).value; + $.ajax({ + type: "POST", + url: '/protocols/update_comment', + dataType: 'json', + data: {id: id, msg: txt}, + success: function (data) { + document.getElementById('edit_comment_'+id).type='hidden'; + var txt = document.getElementById('edit_comment_'+id).value; + $('#span_comment_'+id).text(txt); + $('#span_comment_'+id).show(); + } + }); + } +} + +function comment_edit(id) { + document.getElementById('edit_comment_'+id).type='text'; + $('#span_comment_'+id).hide(); + return false; +} + // Initialize show more comments link. function initStepCommentsLink($el) { - $el.find(".btn-more-comments") .on("ajax:success", function (e, data) { if (data.html) { diff --git a/app/controllers/projects_controller.rb b/app/controllers/projects_controller.rb index a9b04b088..b90408350 100644 --- a/app/controllers/projects_controller.rb +++ b/app/controllers/projects_controller.rb @@ -33,6 +33,77 @@ class ProjectsController < ApplicationController @project = Project.new end + def update_comment_modules + id = request.request_parameters[:id] + msg = request.request_parameters[:msg] + + Comment.where(id:id).update_all(message:msg) + + rb_json = JSON.parse('{"json":['+id+']}') + respond_to do |format| + format.json {render json: rb_json["json"]} + end + end + + def delete_comment_modules + id = request.request_parameters[:id] + + MyModuleComment.where(comment_id:id).destroy_all + Comment.find(id).destroy + + rb_json = JSON.parse('{"json":['+id+']}') + respond_to do |format| + format.json {render json: rb_json["json"]} + end + end + + def update_comment_projects + id = request.request_parameters[:id] + msg = request.request_parameters[:msg] + + Comment.where(id:id).update_all(message:msg) + + rb_json = JSON.parse('{"json":['+id+']}') + respond_to do |format| + format.json {render json: rb_json["json"]} + end + end + + def delete_comment_projects + id = request.request_parameters[:id] + + ProjectComment.where(comment_id:id).destroy_all + Comment.find(id).destroy + + rb_json = JSON.parse('{"json":['+id+']}') + respond_to do |format| + format.json {render json: rb_json["json"]} + end + end + + def update_comment_results + id = request.request_parameters[:id] + msg = request.request_parameters[:msg] + + Comment.where(id:id).update_all(message:msg) + + rb_json = JSON.parse('{"json":['+id+']}') + respond_to do |format| + format.json {render json: rb_json["json"]} + end + end + + def delete_comment_results + id = request.request_parameters[:id] + + ResultComment.where(comment_id:id).destroy_all + + rb_json = JSON.parse('{"json":['+id+']}') + respond_to do |format| + format.json {render json: rb_json["json"]} + end + end + def archive @filter_by_archived = true index diff --git a/app/controllers/protocols_controller.rb b/app/controllers/protocols_controller.rb index 29705c8ba..68b5ac375 100644 --- a/app/controllers/protocols_controller.rb +++ b/app/controllers/protocols_controller.rb @@ -67,6 +67,31 @@ class ProtocolsController < ApplicationController def index end + def update_comment + id = request.request_parameters[:id] + msg = request.request_parameters[:msg] + + Comment.where(id:id).update_all(message:msg) + + rb_json = JSON.parse('{"json":['+id+']}') + respond_to do |format| + format.json {render json: rb_json["json"]} + end + end + + def delete_comment + id = request.request_parameters[:id] + + + StepComment.where(comment_id:id).destroy_all + Comment.find(id).destroy + + rb_json = JSON.parse('{"json":['+id+']}') + respond_to do |format| + format.json {render json: rb_json["json"]} + end + end + def datatable respond_to do |format| format.json { diff --git a/app/views/my_module_comments/_comment.html.erb b/app/views/my_module_comments/_comment.html.erb index 95d970ced..36b9416ba 100644 --- a/app/views/my_module_comments/_comment.html.erb +++ b/app/views/my_module_comments/_comment.html.erb @@ -1,3 +1,13 @@ <%= l comment.created_at, format: '%H:%M' %> <%= comment.user.full_name %>: -

    <%= comment.message %>

    \ No newline at end of file + + + <%= comment.message %> +
    + + +
    +
    \ No newline at end of file diff --git a/app/views/my_module_comments/_list.html.erb b/app/views/my_module_comments/_list.html.erb index f4224e036..74cddcedf 100644 --- a/app/views/my_module_comments/_list.html.erb +++ b/app/views/my_module_comments/_list.html.erb @@ -2,11 +2,12 @@ <% current_day = DateTime.current.strftime('%j').to_i %> <% comments.each do |comment| %> -
  • +
  • <% comment_day = comment.created_at.strftime('%j').to_i %> <% if comment_day < current_day and comment_day < day %> <% day = comment.created_at.strftime('%j').to_i %>

    <%= comment.created_at.strftime('%d.%m.%Y') %>

    <% end %> - <%= render 'project_comments/comment.html.erb', comment: comment %>
  • + <%= render 'my_module_comments/comment.html.erb', comment: comment %> + <% end %> diff --git a/app/views/project_comments/_comment.html.erb b/app/views/project_comments/_comment.html.erb index adf691da0..2655c2a20 100644 --- a/app/views/project_comments/_comment.html.erb +++ b/app/views/project_comments/_comment.html.erb @@ -1,3 +1,13 @@ <%= l comment.created_at, format: '%H:%M' %> <%= comment.user.full_name %>: -

    <%= comment.message %>

    + + + <%= comment.message %> +
    + + +
    +
    diff --git a/app/views/project_comments/_list.html.erb b/app/views/project_comments/_list.html.erb index 68e17ebd8..6f472b331 100644 --- a/app/views/project_comments/_list.html.erb +++ b/app/views/project_comments/_list.html.erb @@ -3,7 +3,7 @@ current_day = DateTime.current.strftime('%j').to_i %> <% comments.each do |comment| %> -
  • +
  • <% comment_day = comment.created_at.strftime('%j').to_i diff --git a/app/views/result_comments/_comment.html.erb b/app/views/result_comments/_comment.html.erb index 74715974a..cdb63ad5c 100644 --- a/app/views/result_comments/_comment.html.erb +++ b/app/views/result_comments/_comment.html.erb @@ -1,2 +1,12 @@ <%=t "my_modules.results.comment_title", user: comment.user.full_name, time: l(comment.created_at, format: :time) %> -

    <%= comment.message %>

    + + + <%= comment.message %> +
    + + +
    +
    diff --git a/app/views/result_comments/_list.html.erb b/app/views/result_comments/_list.html.erb index 1d2941643..c5ca79bb1 100644 --- a/app/views/result_comments/_list.html.erb +++ b/app/views/result_comments/_list.html.erb @@ -2,7 +2,7 @@ <% current_day = DateTime.current.strftime('%j').to_i %> <% comments.each do |comment| %> -
  • +
  • <% comment_day = comment.created_at.strftime('%j').to_i %> <% if comment_day < current_day and comment_day < day %> <% day = comment.created_at.strftime('%j').to_i %> diff --git a/app/views/step_comments/_comment.html.erb b/app/views/step_comments/_comment.html.erb index 7a7516ad3..1415304ba 100644 --- a/app/views/step_comments/_comment.html.erb +++ b/app/views/step_comments/_comment.html.erb @@ -1,2 +1,12 @@ <%=t "protocols.steps.comment_title", user: comment.user.full_name, time: l(comment.created_at, format: :time) %> -

    <%= comment.message %>

    + + + <%= comment.message %> +
    + + +
    +
    \ No newline at end of file diff --git a/app/views/step_comments/_index.html.erb b/app/views/step_comments/_index.html.erb index 86c1e3095..a8105d101 100644 --- a/app/views/step_comments/_index.html.erb +++ b/app/views/step_comments/_index.html.erb @@ -5,7 +5,7 @@
  • <%= t 'general.no_comments' %>
  • <% else %> <%= render 'step_comments/list.html.erb', comments: @comments %> - <% end %> + <% end %>ΒΈ <% if @comments.length == @per_page %>
  • diff --git a/app/views/step_comments/_list.html.erb b/app/views/step_comments/_list.html.erb index 19683d30d..acfad058a 100644 --- a/app/views/step_comments/_list.html.erb +++ b/app/views/step_comments/_list.html.erb @@ -2,7 +2,7 @@ <% current_day = DateTime.current.strftime('%j').to_i %> <% comments.each do |comment| %> -
  • +
  • <% comment_day = comment.created_at.strftime('%j').to_i %> <% if comment_day < current_day and comment_day < day %> <% day = comment.created_at.strftime('%j').to_i %> diff --git a/config/routes.rb b/config/routes.rb index 7d53e1c61..20ff36cce 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -46,6 +46,13 @@ Rails.application.routes.draw do end get 'projects/archive', to: 'projects#archive', as: 'projects_archive' + + post 'projects/delete_comment_results', to: 'projects#delete_comment_results' + post 'projects/update_comment_results', to: 'projects#update_comment_results' + post 'projects/delete_comment_projects', to: 'projects#delete_comment_projects' + post 'projects/update_comment_projects', to: 'projects#update_comment_projects' + post 'projects/delete_comment_modules', to: 'projects#delete_comment_modules' + post 'projects/update_comment_modules', to: 'projects#update_comment_modules' resources :projects, except: [:new, :destroy] do resources :user_projects, path: "/users", only: [:new, :create, :index, :edit, :update, :destroy] @@ -229,6 +236,8 @@ Rails.application.routes.draw do get "edit_description_modal", to: "protocols#edit_description_modal" end collection do + post 'delete_comment', to: 'protocols#delete_comment' + post 'update_comment', to: 'protocols#update_comment' get "create_new_modal", to: "protocols#create_new_modal" post "datatable", to: "protocols#datatable" post "make_private", to: "protocols#make_private"