Skip to content

Commit

Permalink
added ability to add comment if user is logged in
Browse files Browse the repository at this point in the history
  • Loading branch information
Saurabh Joshi committed Dec 7, 2014
1 parent e7d7fc3 commit 92a9756
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 4 deletions.
27 changes: 23 additions & 4 deletions app/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ var Issue = Parse.Object.extend("Issue", {
},
descShort: function() {
return ellipsize(this.get("content"), 140);
},
isLoggedIn: function() {
return Parse.User.current() != null;
}
});
var Comment = Parse.Object.extend("Comment", {
Expand Down Expand Up @@ -205,10 +208,25 @@ function loadComments(issue, results) {
$("#sidebar").html(html);
}

function viewIssue(issue_id) {
var comments = Parse.Query(Comment);

$("#sidebar").html();
function makeComment(e) {
e.preventDefault();
var issue = new Issue();
issue.id = $("#txtIssueId").val();
var comment = new Comment();
comment.set("author", loggedInUser);
comment.set("issue", issue);
comment.set("comment", $("#txtComment").val());
comment.save(null, {
success: function(obj) {
// Execute any logic that should take place after the object is saved.
alert('New object created with objectId: ' + obj.id);
},
error: function(obj, error) {
// Execute any logic that should take place if the save fails.
// error is a Parse.Error with an error code and message.
alert('Failed to create new object, with error code: ' + error.message);
}
});
}

$(function(){
Expand All @@ -232,6 +250,7 @@ $(function(){
$(window).on("resize", applyMargins);

$('body').on('click', '.issue-item', loadIssueComments);
$('body').on('click', '#btnMakeComent', makeComment);

olMap = new ol.Map({
target: "map",
Expand Down
25 changes: 25 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,31 @@ <h3>Comments (<%= comments.length %>)</h3>
<h3> Comments </h3>
<p> There are no comments. </p>
<% } %>

<% if(issue.isLoggedIn()) { %>
<form class="form-horizontal">
<fieldset>

</div>
<!-- Textarea -->
<div class="form-group">
<label class="col-md-4 control-label" for="txtComment">Comment</label>
<div class="col-md-4">
<textarea class="form-control" id="txtComment" name="txtComment"></textarea>
</div>
</div>
<!-- Button -->
<div class="form-group">
<label class="col-md-4 control-label" for="btnMakeComment"></label>
<div class="col-md-4">
<button id="btnMakeComment" name="btnMakeComment" class="btn btn-primary">Make Comment</button>
</div>
</div>
</fieldset>
</form>
<% } else { %>
You must be logged in to make a comment.
<% } %>
</script>

</head>
Expand Down

0 comments on commit 92a9756

Please sign in to comment.