Skip to content

Commit

Permalink
Merge pull request #858 from maisie-fisher/576-commentalert
Browse files Browse the repository at this point in the history
Updated AddComment Functionality
  • Loading branch information
TanyaStere42 authored Nov 1, 2024
2 parents e855293 + 834af5a commit 0f72eb1
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 5 deletions.
5 changes: 4 additions & 1 deletion src/main/java/org/ecocean/servlet/IndividualAddComment.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ public void doPost(HttpServletRequest request, HttpServletResponse response)
response.setContentType("text/html");
PrintWriter out = response.getWriter();
boolean locked = false;
String newComment = "";

myShepherd.beginDBTransaction();
if ((request.getParameter("individual") != null) &&
Expand All @@ -43,9 +44,10 @@ public void doPost(HttpServletRequest request, HttpServletResponse response)
"individual"));
if (ServletUtilities.isUserAuthorizedForIndividual(commentMe, request)) {
try {
commentMe.addComments("<p><em>" + request.getParameter("user") + " on " +
newComment = ("<p><em>" + request.getParameter("user") + " on " +
(new java.util.Date()).toString() + "</em><br>" +
request.getParameter("comments") + "</p>");
commentMe.addComments(newComment);
} catch (Exception le) {
locked = true;
le.printStackTrace();
Expand All @@ -57,6 +59,7 @@ public void doPost(HttpServletRequest request, HttpServletResponse response)
response.setStatus(HttpServletResponse.SC_OK);
out.println(
"<strong>Success:</strong> I have successfully added your comments.");
out.println(newComment);
// out.println("<p><a href=\""+request.getScheme()+"://" + CommonConfiguration.getURLLocation(request) +
// "/individuals.jsp?number=" + request.getParameter("individual") + "\">Return to " + request.getParameter("individual") +
// "</a></p>\n");
Expand Down
42 changes: 38 additions & 4 deletions src/main/webapp/individuals.jsp
Original file line number Diff line number Diff line change
Expand Up @@ -2493,21 +2493,20 @@ if (sharky.getNames() != null) {
if(isOwner){
%>
<p><img align="absmiddle" src="images/Crystal_Clear_app_kaddressbook.gif"> <strong><%=researcherComments %></strong>: </p>

<div style="text-align:left;border:1px solid lightgray;width:100%;height:250px;overflow-y:scroll;overflow-x:scroll;border-radius:5px;">
<div id='commentBoard' style="text-align:left;border:1px solid lightgray;width:100%;height:250px;overflow-y:scroll;overflow-x:scroll;border-radius:5px;">
<p><%=sharky.getComments().replaceAll("\n", "<br>")%></p>
</div>
<%
if (CommonConfiguration.isCatalogEditable(context) && isOwner) {
%>
<p>
<form action="IndividualAddComment" method="post" name="addComments">
<form name="addComments">
<input name="user" type="hidden" value="<%=request.getRemoteUser()%>" id="user">
<input name="individual" type="hidden" value="<%=sharky.getId()%>" id="individual">
<input name="action" type="hidden" value="comments" id="action">

<p><textarea name="comments" cols="60" id="comments" class="form-control" rows="3" style="width: 100%"></textarea> <br />
<input name="Submit" type="submit" value="<%=addComments %>">
<input name="Submit" type="submit" value="<%=addComments %>" id="addCommentsBtn">
</form>
</p>
<%
Expand All @@ -2520,6 +2519,41 @@ if (sharky.getNames() != null) {
</tr>
</table>
</div>
<script type = "text/javascript">
$(window).on('load', function() {
$("#addCommentsBtn").click(function(event) {
event.preventDefault();
$("#addCommentsBtn").hide();
var addCommentUser = $("#user").val();
var addCommentIndividual = $("#individual").val();
var addCommentAction = $("#action").val();
var addCommentComment = $("#comments").val();
$.post("IndividualAddComment", {"user": addCommentUser, "individual": addCommentIndividual, "action": addCommentAction, "comments": addCommentComment},
function(response) {
$("#comments").val("");
let match = response.match(/(<p>.*<\/p>)/);
if (match) {
let newComment = match[1];
$("#commentBoard").append(newComment);
} else {
console.log('Incorrectly Formatted Comment')
}
}).fail(function(response) {
console.log(response);
})
$("#addCommentsBtn").show();
})
})
</script>
<%-- End Comments --%>

</div>
Expand Down

0 comments on commit 0f72eb1

Please sign in to comment.