Commit 6bf8ce04 authored by Rene Saarsoo's avatar Rene Saarsoo
Browse files

Update replies counter when replies added/removed.

parent 93dbe590
Loading
Loading
Loading
Loading
+18 −1
Original line number Diff line number Diff line
@@ -30,7 +30,11 @@ Ext.define('Docs.view.comments.List', {

    initComponent: function() {
        this.store = Ext.create('Ext.data.Store', {
            model: "Docs.model.Comment"
            model: "Docs.model.Comment",
            listeners: {
                update: this.fireChangeEvent,
                scope: this
            }
        });

        this.tpl = Docs.view.comments.Template.create({showTarget: this.showTarget});
@@ -183,6 +187,19 @@ Ext.define('Docs.view.comments.List', {

        var processedComments = this.store.getProxy().getReader().readRecords(comments).records;
        this.store.loadData(processedComments, append);
        this.fireChangeEvent();
    },

    fireChangeEvent: function() {
        /**
         * @event countChange
         * Fired when nr of comments in list changes.
         * @param {Number} count
         */
        var isNotDeleted = function(c) {
            return !c.get("deleted");
        };
        this.fireEvent("countChange", this.getStore().queryBy(isNotDeleted).getCount());
    }

});
+6 −0
Original line number Diff line number Diff line
@@ -33,6 +33,12 @@ Ext.define('Docs.view.comments.ListWithForm', {
            })
        ];

        /**
         * @event countChange
         * @inheritdoc Docs.view.comments.List#countChange
         */
        this.relayEvents(this.list, ["countChange"]);

        this.callParent(arguments);
    },

+8 −2
Original line number Diff line number Diff line
@@ -108,7 +108,11 @@ Ext.define('Docs.view.comments.RepliesExpander', {
            target: this.target,
            parentId: this.parentId,
            newCommentTitle: "<b>Reply to comment</b>",
            renderTo: this.getEl()
            renderTo: this.getEl(),
            listeners: {
                countChange: this.setCount,
                scope: this
            }
        });

        Docs.Comments.loadReplies(this.parentId, function(comments) {
@@ -122,7 +126,9 @@ Ext.define('Docs.view.comments.RepliesExpander', {
     */
    setCount: function(count) {
        this.count = count;
        if (!this.expanded) {
            this.refreshRepliesButton();
        }
    }

});