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

Implement loading of subscriptions data.

Also toggle the subscription checkbox depending on the status
of subscription in commenting form.
parent cf969192
Loading
Loading
Loading
Loading
+33 −0
Original line number Diff line number Diff line
/**
 * Manages comment subscriptions.
 */
Ext.define('Docs.CommentSubscriptions', {

    /**
     * Initializes CommentSubscriptions with the list of subscriptions from
     * comments_meta request result.
     *
     * @param {String[][]} subscriptions 2D array like:
     *
     *     [
     *         ['class', 'Ext', 'method-foo'],
     *         ['class', 'Ext', 'method-bar']
     *     ]
     */
    constructor: function(subscriptions) {
        this.subscriptions = {};
        Ext.Array.each(subscriptions, function(r) {
            this.subscriptions[r.join("__")] = true;
        }, this);
    },

    /**
     * True if current user has subscribed to a particular target.
     * @param {String[]} target
     * @return {Boolean}
     */
    has: function(target) {
        return this.subscriptions[target.join("__")];
    }

});
+9 −0
Original line number Diff line number Diff line
@@ -6,6 +6,7 @@ Ext.define('Docs.Comments', {
    requires: [
        "Docs.Auth",
        "Docs.CommentCounts",
        "Docs.CommentSubscriptions",
        "Ext.data.JsonP",
        "Ext.Ajax"
    ],
@@ -30,6 +31,7 @@ Ext.define('Docs.Comments', {
                this.enabled = true;
                this.fetchCountsAndSubscriptions(function(counts, subscriptions) {
                    this.counts = new Docs.CommentCounts(counts);
                    this.subscriptions = new Docs.CommentSubscriptions(subscriptions);
                    callback.call(scope);
                }, this);
            }
@@ -66,6 +68,13 @@ Ext.define('Docs.Comments', {
        return this.counts.get(type, cls, member);
    },

    /**
     * @inheritdoc Docs.CommentSubscriptions#has
     */
    hasSubscription: function(target) {
        return this.subscriptions.has(target);
    },

    /**
     * @inheritdoc Docs.CommentCounts#getClassTotal
     */
+1 −0
Original line number Diff line number Diff line
@@ -78,6 +78,7 @@ Ext.define('Docs.view.comments.ListWithForm', {
        this.commentingForm = new Docs.view.comments.Form({
            title: this.newCommentTitle,
            user: Docs.Auth.getUser(),
            userSubscribed: Docs.Comments.hasSubscription(this.target),
            listeners: {
                submit: this.postComment,
                scope: this