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("
")
+ .prepend("")
.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("")
+ .prepend("")
.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("")
+ .prepend("")
.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("")
+ .prepend("")
.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
+
+
+
+
+
+
+
+
\ 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| %>
-
+ <%= 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 %>
+
+
+
+
+
+
+
+
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| %>
-
<% else %>
<%= render 'step_comments/list.html.erb', comments: @comments %>
- <% end %>
+ <% end %>ΒΈ
<% if @comments.length == @per_page %>