Loading template/app/view/comments/List.js +56 −7 Original line number Diff line number Diff line Loading @@ -8,7 +8,8 @@ Ext.define('Docs.view.comments.List', { 'Docs.Auth', 'Docs.Syntax', 'Docs.Comments', 'Docs.view.comments.Template' 'Docs.view.comments.Template', 'Docs.Tip' ], itemSelector: "div.comment", Loading @@ -19,7 +20,7 @@ Ext.define('Docs.view.comments.List', { initComponent: function() { this.store = Ext.create('Ext.data.Store', { fields: [ "id", "_id", "author", "emailHash", "moderator", Loading @@ -36,7 +37,59 @@ Ext.define('Docs.view.comments.List', { this.callParent(arguments); this.on("refresh", this.syntaxHighlight, this); this.on("refresh", function() { Docs.Syntax.highlight(this.getEl()); }, this); this.on("itemupdate", function(record, index, node) { Docs.Syntax.highlight(node); }, this); }, afterRender: function() { this.callParent(arguments); this.delegateClick("a.voteCommentUp", function(el, r) { this.vote(el, r, "up"); }, this); this.delegateClick("a.voteCommentDown", function(el, r) { this.vote(el, r, "down"); }, this); }, delegateClick: function(selector, callback, scope) { this.getEl().on("click", function(event, el) { callback.call(scope, el, this.getRecord(this.findItemByChild(el))); }, this, {preventDefault: true, delegate: selector}); }, vote: function(el, record, direction) { if (!Docs.Auth.isLoggedIn()) { Docs.Tip.show('Please login to vote on this comment', el); return; } if (record.get("upVote") && direction === "up" || record.get("downVote") && direction === "down") { Docs.Tip.show('You have already voted on this comment', el); return; } Docs.Comments.request("ajax", { url: '/comments/' + record.get("_id"), method: 'POST', params: { vote: direction }, callback: function(options, success, response) { var data = Ext.JSON.decode(response.responseText); if (data.success) { record.set("score", data.total); record.set("upVote", data.direction === "up"); record.set("downVote", data.direction === "down"); record.commit(); } else { Docs.Tip.show(data.reason, el); } }, scope: this }); }, /** Loading @@ -51,10 +104,6 @@ Ext.define('Docs.view.comments.List', { } this.store.loadData(comments, append); }, syntaxHighlight: function() { Docs.Syntax.highlight(this.getEl()); } }); Loading
template/app/view/comments/List.js +56 −7 Original line number Diff line number Diff line Loading @@ -8,7 +8,8 @@ Ext.define('Docs.view.comments.List', { 'Docs.Auth', 'Docs.Syntax', 'Docs.Comments', 'Docs.view.comments.Template' 'Docs.view.comments.Template', 'Docs.Tip' ], itemSelector: "div.comment", Loading @@ -19,7 +20,7 @@ Ext.define('Docs.view.comments.List', { initComponent: function() { this.store = Ext.create('Ext.data.Store', { fields: [ "id", "_id", "author", "emailHash", "moderator", Loading @@ -36,7 +37,59 @@ Ext.define('Docs.view.comments.List', { this.callParent(arguments); this.on("refresh", this.syntaxHighlight, this); this.on("refresh", function() { Docs.Syntax.highlight(this.getEl()); }, this); this.on("itemupdate", function(record, index, node) { Docs.Syntax.highlight(node); }, this); }, afterRender: function() { this.callParent(arguments); this.delegateClick("a.voteCommentUp", function(el, r) { this.vote(el, r, "up"); }, this); this.delegateClick("a.voteCommentDown", function(el, r) { this.vote(el, r, "down"); }, this); }, delegateClick: function(selector, callback, scope) { this.getEl().on("click", function(event, el) { callback.call(scope, el, this.getRecord(this.findItemByChild(el))); }, this, {preventDefault: true, delegate: selector}); }, vote: function(el, record, direction) { if (!Docs.Auth.isLoggedIn()) { Docs.Tip.show('Please login to vote on this comment', el); return; } if (record.get("upVote") && direction === "up" || record.get("downVote") && direction === "down") { Docs.Tip.show('You have already voted on this comment', el); return; } Docs.Comments.request("ajax", { url: '/comments/' + record.get("_id"), method: 'POST', params: { vote: direction }, callback: function(options, success, response) { var data = Ext.JSON.decode(response.responseText); if (data.success) { record.set("score", data.total); record.set("upVote", data.direction === "up"); record.set("downVote", data.direction === "down"); record.commit(); } else { Docs.Tip.show(data.reason, el); } }, scope: this }); }, /** Loading @@ -51,10 +104,6 @@ Ext.define('Docs.view.comments.List', { } this.store.loadData(comments, append); }, syntaxHighlight: function() { Docs.Syntax.highlight(this.getEl()); } });