Commit cf969192 authored by Rene Saarsoo's avatar Rene Saarsoo
Browse files

Move the actual fetching of comments out of CommentCounts class.

parent 29f33c4b
Loading
Loading
Loading
Loading
+4 −27
Original line number Diff line number Diff line
@@ -4,34 +4,11 @@
Ext.define('Docs.CommentCounts', {

    /**
     * Initialized CommentCounts with the main Comments class instance
     * which is used to perform queries.
     * @param {Docs.Comments} comments
     * Initializes CommentCounts with the list of counts from
     * comments_meta request result.
     * @param {Object[]} counts Objects with `_id` and `value` fields.
     */
    constructor: function(comments) {
        this.comments = comments;
        this.loadCallbacks = [];
    },

    /**
     * Fetches all comment counts.
     *
     * @param {Function} callback Called after done.
     * @param {Object} scope
     */
    fetch: function(callback, scope) {
        this.comments.request("jsonp", {
            url: '/comments_meta',
            method: 'GET',
            success: function(response) {
                this.load(response.comments);
                callback.call(scope);
            },
            scope: this
        });
    },

    load: function(counts) {
    constructor: function(counts) {
        this.counts = {};
        Ext.Array.each(counts, function(r) {
            this.counts[r._id] = r.value;
+16 −2
Original line number Diff line number Diff line
@@ -28,8 +28,10 @@ Ext.define('Docs.Comments', {
        Docs.Auth.init(function(success) {
            if (success) {
                this.enabled = true;
                this.counts = new Docs.CommentCounts(this);
                this.counts.fetch(callback, scope);
                this.fetchCountsAndSubscriptions(function(counts, subscriptions) {
                    this.counts = new Docs.CommentCounts(counts);
                    callback.call(scope);
                }, this);
            }
            else {
                callback.call(scope);
@@ -37,6 +39,18 @@ Ext.define('Docs.Comments', {
        }, this);
    },

    // Fetches comment counts and subscriptions.
    fetchCountsAndSubscriptions: function(callback, scope) {
        this.request("jsonp", {
            url: '/comments_meta',
            method: 'GET',
            success: function(response) {
                callback.call(scope, response.comments, response.subscriptions);
            },
            scope: this
        });
    },

    /**
     * True when comments system is enabled.
     * @return {Boolean}