From 1af6d26d175311bf0882a2c4624cbcbf7b349c90 Mon Sep 17 00:00:00 2001 From: Rene Saarsoo Date: Mon, 1 Oct 2012 17:11:04 -0700 Subject: [PATCH] Delete and undo_delete of comments. --- template/app/view/comments/List.js | 28 ++++++++++++++- template/app/view/comments/Template.js | 48 ++++++++++++++------------ 2 files changed, 53 insertions(+), 23 deletions(-) diff --git a/template/app/view/comments/List.js b/template/app/view/comments/List.js index b115e4a9..622b4f67 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 e9c310d4..e36aa105 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', { '
', '', '
', - '
', - '{[Docs.Comments.avatar(values.emailHash)]}', - '
moderator" title="Sencha Engineer">', - '{author}', - '', - ' on {[this.target(values.target)]}', + '', + '
Comment was deleted. Undo.
', + '', + '
', + '{[Docs.Comments.avatar(values.emailHash)]}', + '
moderator" title="Sencha Engineer">', + '{author}', + '', + ' on {[this.target(values.target)]}', + '', + '
', + '', + 'read">Read', '', + '', + 'EditDelete', + '', + '
{[this.dateStr(values.createdAt)]}
', + '
', + ' ', + '{score}', + ' ', + '
', '
', - '', - 'read">Read', - '
', - '', - 'EditDelete', - '', - '
{[this.dateStr(values.createdAt)]}
', - '
', - ' ', - '{score}', - ' ', - '
', - '
', - '
{contentHtml}
', + '
{contentHtml}
', + '', '
', '', '
', -- GitLab