diff --git a/template/app/view/comments/List.js b/template/app/view/comments/List.js index b115e4a980c6638deef8bcc8b338bf5fecba2287..622b4f670ff4c6fef8577627744d2e116d3bdf38 100644 --- a/template/app/view/comments/List.js +++ b/template/app/view/comments/List.js @@ -36,7 +36,8 @@ Ext.define('Docs.view.comments.List', { "score", "upVote", "downVote", - "contentHtml" + "contentHtml", + "deleted" ] }); @@ -63,6 +64,12 @@ Ext.define('Docs.view.comments.List', { this.delegateClick("a.editComment", function(el, r) { this.edit(el, r); }, this); + this.delegateClick("a.deleteComment", function(el, r) { + this.setDeleted(el, r, true); + }, this); + this.delegateClick("a.undoDeleteComment", function(el, r) { + this.setDeleted(el, r, false); + }, this); }, delegateClick: function(selector, callback, scope) { @@ -162,6 +169,25 @@ Ext.define('Docs.view.comments.List', { }); }, + // marks the comment as deleted or undoes the delete + setDeleted: function(el, comment, deleted) { + Docs.Comments.request("ajax", { + url: '/comments/' + comment.get("_id") + (deleted ? '/delete' : '/undo_delete'), + method: 'POST', + callback: function(options, success, response) { + var data = Ext.JSON.decode(response.responseText); + if (data.success) { + comment.set("deleted", deleted); + comment.commit(); + } + else { + Ext.Msg.alert('Error', data.reason || "There was an error submitting your request"); + } + }, + scope: this + }); + }, + /** * Loads array of comments into the view. * @param {Object[]} comments diff --git a/template/app/view/comments/Template.js b/template/app/view/comments/Template.js index e9c310d4f9148d2935687d1d2c592266329ac6c9..e36aa105d1b716b2250cbde5bf34cc7b74e8df82 100644 --- a/template/app/view/comments/Template.js +++ b/template/app/view/comments/Template.js @@ -38,30 +38,34 @@ Ext.define('Docs.view.comments.Template', { '