Loading template/app/Comments.js +19 −0 Original line number Diff line number Diff line Loading @@ -59,6 +59,25 @@ Ext.define('Docs.Comments', { return this.counts.getClassTotal(className); }, /** * Loads the comments of a particular target. * @param {String[]} target An array of `[type, cls, member]` * @param {Function} callback Called when finished. * @param {Object[]} callback.comments An array of comments. * @param {Object} scope */ load: function(target, callback, scope) { this.request("jsonp", { url: '/comments', method: 'GET', params: { startkey: Ext.JSON.encode(target) }, success: callback, scope: scope }); }, /** * Performs request to the comments server. * Loading template/app/view/comments/Expander.js +16 −10 Original line number Diff line number Diff line Loading @@ -4,6 +4,10 @@ Ext.define('Docs.view.comments.Expander', { alias: "widget.commentsExpander", extend: 'Ext.Component', requires: [ 'Docs.Comments', 'Docs.view.comments.List' ], /** * @cfg {String} type Loading @@ -21,12 +25,6 @@ Ext.define('Docs.view.comments.Expander', { * @cfg {Number} count */ /** * @event fetchComments * Fired when new comments need to be loaded. * @param {String} id ID of the comments expander div. */ initComponent: function() { this.tpl = new Ext.XTemplate( '<div class="comments-div first-child" id="comments-{id}">', Loading @@ -40,8 +38,6 @@ Ext.define('Docs.view.comments.Expander', { } ); this.loadingTpl = new Ext.XTemplate('<div class="loading">Loading...</div>'); var cls = this.type + '-' + this.className.replace(/\./g, '-'); this.data = { id: this.memberId ? cls+"-"+this.memberId : cls, Loading Loading @@ -86,8 +82,7 @@ Ext.define('Docs.view.comments.Expander', { list.setStyle('display', 'block'); } else { this.loadingTpl.append(div); this.fireEvent("fetchComments", div.getAttribute('id')); this.loadComments(div); } }, Loading @@ -103,6 +98,17 @@ Ext.define('Docs.view.comments.Expander', { } }, loadComments: function(div) { this.list = new Docs.view.comments.List({ renderTo: div }); var target = [this.type, this.className, this.memberId]; Docs.Comments.load(target, function(comments) { this.list.load(comments); }, this); }, /** * Updates the comment count. * @param {Number} count Loading template/app/view/comments/List.js +16 −2 Original line number Diff line number Diff line Loading @@ -3,9 +3,15 @@ */ Ext.define('Docs.view.comments.List', { extend: 'Ext.view.View', requires: [ 'Docs.Auth' ], itemSelector: "div.comment", emptyText: '<div class="loading">Loading...</div>', deferEmptyText: false, initComponent: function() { this.store = Ext.create('Ext.data.Store', { fields: [ Loading Loading @@ -62,6 +68,14 @@ Ext.define('Docs.view.comments.List', { this.callParent(arguments); }, /** * Loads array of comments into the view. * @param {Object[]} comments */ load: function(comments) { this.store.loadData(comments); }, dateStr: function(date) { try { var now = Math.ceil(Number(new Date()) / 1000); Loading Loading @@ -100,11 +114,11 @@ Ext.define('Docs.view.comments.List', { }, isMod: function() { return Docs.App.getController('Auth').currentUser.mod; return Docs.Auth.isModerator(); }, isAuthor: function(author) { return Docs.App.getController('Auth').currentUser.userName == author; return Docs.Auth.getUser().userName == author; }, target: function(target) { Loading Loading
template/app/Comments.js +19 −0 Original line number Diff line number Diff line Loading @@ -59,6 +59,25 @@ Ext.define('Docs.Comments', { return this.counts.getClassTotal(className); }, /** * Loads the comments of a particular target. * @param {String[]} target An array of `[type, cls, member]` * @param {Function} callback Called when finished. * @param {Object[]} callback.comments An array of comments. * @param {Object} scope */ load: function(target, callback, scope) { this.request("jsonp", { url: '/comments', method: 'GET', params: { startkey: Ext.JSON.encode(target) }, success: callback, scope: scope }); }, /** * Performs request to the comments server. * Loading
template/app/view/comments/Expander.js +16 −10 Original line number Diff line number Diff line Loading @@ -4,6 +4,10 @@ Ext.define('Docs.view.comments.Expander', { alias: "widget.commentsExpander", extend: 'Ext.Component', requires: [ 'Docs.Comments', 'Docs.view.comments.List' ], /** * @cfg {String} type Loading @@ -21,12 +25,6 @@ Ext.define('Docs.view.comments.Expander', { * @cfg {Number} count */ /** * @event fetchComments * Fired when new comments need to be loaded. * @param {String} id ID of the comments expander div. */ initComponent: function() { this.tpl = new Ext.XTemplate( '<div class="comments-div first-child" id="comments-{id}">', Loading @@ -40,8 +38,6 @@ Ext.define('Docs.view.comments.Expander', { } ); this.loadingTpl = new Ext.XTemplate('<div class="loading">Loading...</div>'); var cls = this.type + '-' + this.className.replace(/\./g, '-'); this.data = { id: this.memberId ? cls+"-"+this.memberId : cls, Loading Loading @@ -86,8 +82,7 @@ Ext.define('Docs.view.comments.Expander', { list.setStyle('display', 'block'); } else { this.loadingTpl.append(div); this.fireEvent("fetchComments", div.getAttribute('id')); this.loadComments(div); } }, Loading @@ -103,6 +98,17 @@ Ext.define('Docs.view.comments.Expander', { } }, loadComments: function(div) { this.list = new Docs.view.comments.List({ renderTo: div }); var target = [this.type, this.className, this.memberId]; Docs.Comments.load(target, function(comments) { this.list.load(comments); }, this); }, /** * Updates the comment count. * @param {Number} count Loading
template/app/view/comments/List.js +16 −2 Original line number Diff line number Diff line Loading @@ -3,9 +3,15 @@ */ Ext.define('Docs.view.comments.List', { extend: 'Ext.view.View', requires: [ 'Docs.Auth' ], itemSelector: "div.comment", emptyText: '<div class="loading">Loading...</div>', deferEmptyText: false, initComponent: function() { this.store = Ext.create('Ext.data.Store', { fields: [ Loading Loading @@ -62,6 +68,14 @@ Ext.define('Docs.view.comments.List', { this.callParent(arguments); }, /** * Loads array of comments into the view. * @param {Object[]} comments */ load: function(comments) { this.store.loadData(comments); }, dateStr: function(date) { try { var now = Math.ceil(Number(new Date()) / 1000); Loading Loading @@ -100,11 +114,11 @@ Ext.define('Docs.view.comments.List', { }, isMod: function() { return Docs.App.getController('Auth').currentUser.mod; return Docs.Auth.isModerator(); }, isAuthor: function(author) { return Docs.App.getController('Auth').currentUser.userName == author; return Docs.Auth.getUser().userName == author; }, target: function(target) { Loading