Loading template/app/CommentCounts.js 0 → 100644 +86 −0 Original line number Diff line number Diff line /** * */ Ext.define('Docs.CommentCounts', { singleton: true, requires: ["Docs.Comments"], constructor: function() { this.loadCallbacks = []; }, /** * Fetches all comment counts. */ fetch: function() { Docs.Comments.request("jsonp", { url: '/comments_meta', method: 'GET', success: function(response) { this.load(response.comments); this.fireLoadCallbacks(); }, scope: this }); }, load: function(counts) { this.counts = {}; Ext.Array.each(counts, function(r) { this.counts[r._id] = r.value; }, this); }, /** * Returns comments count for a specific item. * @param {String} type * @param {String} cls * @param {String} member * @return {Number} */ get: function(type, cls, member) { var key = [type||"", cls||"", member||""].join("__"); return this.counts[key]; }, /** * Returns the total number of comments on a class itself + * comments on all its members. * @param {String} className * @return {Number} */ getClassTotal: function(className) { if (!this.totals) { this.totals = {}; Ext.Object.each(this.counts, function(key, count) { var parts = key.split("__"); if (parts[0] === "class") { this.totals[parts[1]] = (this.totals[parts[1]] || 0) + count; } }, this); } return this.totals[className]; }, /** * Calls the given function after comment counts have been loaded. * @param {Function} callback * @param {Object} scope */ afterLoaded: function(callback, scope) { if (this.counts) { callback.call(scope); } else { this.loadCallbacks.push(Ext.Function.bind(callback, scope)); } }, fireLoadCallbacks: function() { Ext.Array.forEach(this.loadCallbacks, function(cb) { cb(); }); this.loadCallbacks = []; } }); template/app/controller/Auth.js +3 −1 Original line number Diff line number Diff line Loading @@ -7,7 +7,8 @@ Ext.define('Docs.controller.Auth', { extend: 'Ext.app.Controller', requires: [ 'Docs.Auth' 'Docs.Auth', 'Docs.CommentCounts' ], refs: [ Loading @@ -25,6 +26,7 @@ Ext.define('Docs.controller.Auth', { else { this.setLoggedOut(); } Docs.CommentCounts.fetch(); }, this); this.control({ Loading template/app/view/cls/Index.js +20 −1 Original line number Diff line number Diff line Loading @@ -5,7 +5,8 @@ Ext.define('Docs.view.cls.Index', { extend: 'Ext.container.Container', alias: 'widget.classindex', requires: [ 'Docs.ContentGrabber' 'Docs.ContentGrabber', 'Docs.CommentCounts' ], mixins: ['Docs.view.Scrolling'], cls: 'class-categories iScroll', Loading @@ -25,9 +26,27 @@ Ext.define('Docs.view.cls.Index', { categories: Docs.ContentGrabber.get("categories-content") }; this.commentCountTpl = Ext.create('Ext.Template', '<span class="toggleMemberComments">{0}</span>' ); this.callParent(arguments); }, afterRender: function() { this.callParent(arguments); Docs.CommentCounts.afterLoaded(function() { this.getEl().select("a.docClass").each(function(a) { var className = a.getHTML(); var count = Docs.CommentCounts.getClassTotal(className); if (count) { this.commentCountTpl.append(a, [count]); } }, this); }, this); }, /** * Returns tab config for classes page if at least one class. * @return {Object} Loading Loading
template/app/CommentCounts.js 0 → 100644 +86 −0 Original line number Diff line number Diff line /** * */ Ext.define('Docs.CommentCounts', { singleton: true, requires: ["Docs.Comments"], constructor: function() { this.loadCallbacks = []; }, /** * Fetches all comment counts. */ fetch: function() { Docs.Comments.request("jsonp", { url: '/comments_meta', method: 'GET', success: function(response) { this.load(response.comments); this.fireLoadCallbacks(); }, scope: this }); }, load: function(counts) { this.counts = {}; Ext.Array.each(counts, function(r) { this.counts[r._id] = r.value; }, this); }, /** * Returns comments count for a specific item. * @param {String} type * @param {String} cls * @param {String} member * @return {Number} */ get: function(type, cls, member) { var key = [type||"", cls||"", member||""].join("__"); return this.counts[key]; }, /** * Returns the total number of comments on a class itself + * comments on all its members. * @param {String} className * @return {Number} */ getClassTotal: function(className) { if (!this.totals) { this.totals = {}; Ext.Object.each(this.counts, function(key, count) { var parts = key.split("__"); if (parts[0] === "class") { this.totals[parts[1]] = (this.totals[parts[1]] || 0) + count; } }, this); } return this.totals[className]; }, /** * Calls the given function after comment counts have been loaded. * @param {Function} callback * @param {Object} scope */ afterLoaded: function(callback, scope) { if (this.counts) { callback.call(scope); } else { this.loadCallbacks.push(Ext.Function.bind(callback, scope)); } }, fireLoadCallbacks: function() { Ext.Array.forEach(this.loadCallbacks, function(cb) { cb(); }); this.loadCallbacks = []; } });
template/app/controller/Auth.js +3 −1 Original line number Diff line number Diff line Loading @@ -7,7 +7,8 @@ Ext.define('Docs.controller.Auth', { extend: 'Ext.app.Controller', requires: [ 'Docs.Auth' 'Docs.Auth', 'Docs.CommentCounts' ], refs: [ Loading @@ -25,6 +26,7 @@ Ext.define('Docs.controller.Auth', { else { this.setLoggedOut(); } Docs.CommentCounts.fetch(); }, this); this.control({ Loading
template/app/view/cls/Index.js +20 −1 Original line number Diff line number Diff line Loading @@ -5,7 +5,8 @@ Ext.define('Docs.view.cls.Index', { extend: 'Ext.container.Container', alias: 'widget.classindex', requires: [ 'Docs.ContentGrabber' 'Docs.ContentGrabber', 'Docs.CommentCounts' ], mixins: ['Docs.view.Scrolling'], cls: 'class-categories iScroll', Loading @@ -25,9 +26,27 @@ Ext.define('Docs.view.cls.Index', { categories: Docs.ContentGrabber.get("categories-content") }; this.commentCountTpl = Ext.create('Ext.Template', '<span class="toggleMemberComments">{0}</span>' ); this.callParent(arguments); }, afterRender: function() { this.callParent(arguments); Docs.CommentCounts.afterLoaded(function() { this.getEl().select("a.docClass").each(function(a) { var className = a.getHTML(); var count = Docs.CommentCounts.getClassTotal(className); if (count) { this.commentCountTpl.append(a, [count]); } }, this); }, this); }, /** * Returns tab config for classes page if at least one class. * @return {Object} Loading