delete and edit comments for projects, protocols, results, and workflow elements

This commit is contained in:
scibb 2016-08-22 15:10:06 +02:00 committed by Luka Murn
parent 4c0765a47e
commit a76d82d188
17 changed files with 329 additions and 15 deletions

View file

@ -1,3 +1,4 @@
// Bind ajax for editing descriptions
function bindEditDescriptionAjax() {
var editDescriptionModal = $("#manage-module-description-modal");

View file

@ -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("<li class='comment'>" + data.html + "</li>")
.prepend("<li class='comment' id='"+id+"'>" + data.html + "</li>")
.scrollTop(0);
list.parents("ul").find("> li.comment:gt(8)").remove();
$("#comment_message", $form).val("");

View file

@ -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("<li class='comment'>" + data.html + "</li>")
.prepend("<li class='comment' id='"+id+"'>" + data.html + "</li>")
.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;
}

View file

@ -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("<li class='comment'>" + data.html + "</li>")
.prepend("<li class='comment' id='"+id+"'>" + data.html + "</li>")
.scrollTop(0);
list.parents("ul").find("> li.comment:gt(8)").remove();
$("#comment_message", $form).val("");

View file

@ -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("<li class='comment'>" + data.html + "</li>")
.prepend("<li class='comment' id='"+id+"'>" + data.html + "</li>")
.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) {

View file

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

View file

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

View file

@ -1,3 +1,13 @@
<span class="text-muted pull-right"><%= l comment.created_at, format: '%H:%M' %></span>
<strong><%= comment.user.full_name %>:</strong>
<p><span><%= comment.message %></p>
<span class="input-group">
<input type="hidden" class="form-control" id="edit_comment_<%= comment.id %>" value="<%= comment.message %>" onkeydown="if (event.keyCode==13) module_update_comment(<%= comment.id %>)" >
<span id="span_comment_<%= comment.id %>" style="display:block;width:200px;word-wrap:break-word;"><%= comment.message %></span>
<div class="input-group-btn">
<button class="btn btn-default dropdown-toggle" type="button" data-toggle="dropdown"><span class="caret"></span></button>
<ul class="dropdown-menu pull-right">
<li><a href="#" onclick='return module_comment_edit(<%= comment.id %>)'>Edit</a></li>
<li><a href="#" onclick='return module_comment_delete(<%= comment.id %>)'>Delete</a></li>
</ul>
</div>
</span>

View file

@ -2,11 +2,12 @@
<% current_day = DateTime.current.strftime('%j').to_i %>
<% comments.each do |comment| %>
<li class="comment">
<li class="comment" id="<%= comment.id %>">
<% 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 %>
<p class="text-center"><%= comment.created_at.strftime('%d.%m.%Y') %></p>
<% end %>
<%= render 'project_comments/comment.html.erb', comment: comment %></li>
<%= render 'my_module_comments/comment.html.erb', comment: comment %></li>
<!--= render 'project_comments/comment.html.erb', comment: comment %></li-->
<% end %>

View file

@ -1,3 +1,13 @@
<span class="text-muted pull-right"><%= l comment.created_at, format: '%H:%M' %></span>
<strong><%= comment.user.full_name %>:</strong>
<p><span><%= comment.message %></p>
<span class="input-group">
<input type="hidden" class="form-control" id="edit_comment_<%= comment.id %>" value="<%= comment.message %>" onkeydown="if (event.keyCode==13) project_update_comment(<%= comment.id %>)" >
<span id="span_comment_<%= comment.id %>" style="display:block;width:200px;word-wrap:break-word;"><%= comment.message %></span>
<div class="input-group-btn">
<button class="btn btn-default dropdown-toggle" type="button" data-toggle="dropdown"><span class="caret"></span></button>
<ul class="dropdown-menu pull-right">
<li><a href="#" onclick='return project_comment_edit(<%= comment.id %>)'>Edit</a></li>
<li><a href="#" onclick='return project_comment_delete(<%= comment.id %>)'>Delete</a></li>
</ul>
</div>
</span>

View file

@ -3,7 +3,7 @@
current_day = DateTime.current.strftime('%j').to_i
%>
<% comments.each do |comment| %>
<li class="comment">
<li class="comment" id="<%= comment.id %>">
<%
comment_day = comment.created_at.strftime('%j').to_i

View file

@ -1,2 +1,12 @@
<strong><%=t "my_modules.results.comment_title", user: comment.user.full_name, time: l(comment.created_at, format: :time) %></strong>
<p><span><%= comment.message %></p>
<span class="input-group">
<input type="hidden" class="form-control" id="edit_comment_<%= comment.id %>" value="<%= comment.message %>" onkeydown="if (event.keyCode==13) results_update_comment(<%= comment.id %>)" >
<span id="span_comment_<%= comment.id %>"><%= comment.message %></span>
<div class="input-group-btn">
<button class="btn btn-default dropdown-toggle" type="button" data-toggle="dropdown"><span class="caret"></span></button>
<ul class="dropdown-menu pull-right">
<li><a href="#" onclick='return results_comment_edit(<%= comment.id %>)'>Edit</a></li>
<li><a href="#" onclick='return results_comment_delete(<%= comment.id %>)'>Delete</a></li>
</ul>
</div>
</span>

View file

@ -2,7 +2,7 @@
<% current_day = DateTime.current.strftime('%j').to_i %>
<% comments.each do |comment| %>
<li class="comment">
<li class="comment" id="<%= comment.id %>" >
<% 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 %>

View file

@ -1,2 +1,12 @@
<strong><%=t "protocols.steps.comment_title", user: comment.user.full_name, time: l(comment.created_at, format: :time) %></strong>
<p><span><%= comment.message %></p>
<span class="input-group">
<input type="hidden" class="form-control" id="edit_comment_<%= comment.id %>" value="<%= comment.message %>" onkeydown="if (event.keyCode==13) update_comment(<%= comment.id %>)" >
<span id="span_comment_<%= comment.id %>" ><%= comment.message %></span>
<div class="input-group-btn">
<button class="btn btn-default dropdown-toggle" type="button" data-toggle="dropdown"><span class="caret"></span></button>
<ul class="dropdown-menu pull-right">
<li><a href="#" onclick='return comment_edit(<%= comment.id %>)'>Edit</a></li>
<li><a href="#" onclick='return comment_delete(<%= comment.id %>)'>Delete</a></li>
</ul>
</div>
</span>

View file

@ -5,7 +5,7 @@
<li class="no-comments"><em><%= t 'general.no_comments' %></em></li>
<% else %>
<%= render 'step_comments/list.html.erb', comments: @comments %>
<% end %>
<% end %>¸
<% if @comments.length == @per_page %>
<li class="text-center">
<a class="btn btn-default btn-more-comments" href="<%= more_comments_url %>" data-remote="true">

View file

@ -2,7 +2,7 @@
<% current_day = DateTime.current.strftime('%j').to_i %>
<% comments.each do |comment| %>
<li class="comment">
<li class="comment" id="<%= comment.id %>" >
<% 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 %>

View file

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