diff --git a/template/app/view/comments/List.js b/template/app/view/comments/List.js index 68efeead878a990b708d92deaf8c609b0bed2e18..b9fc89ca01a94415360591c7cba90f21614a5c86 100644 --- a/template/app/view/comments/List.js +++ b/template/app/view/comments/List.js @@ -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()); } }); diff --git a/template/app/view/comments/ListWithForm.js b/template/app/view/comments/ListWithForm.js index 0e78981b875504891f6cc30ae89a5b03597b46e1..a6f7984ba8c73d5f8c45ae6fb3729fe79619edb4 100644 --- a/template/app/view/comments/ListWithForm.js +++ b/template/app/view/comments/ListWithForm.js @@ -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); }, diff --git a/template/app/view/comments/RepliesExpander.js b/template/app/view/comments/RepliesExpander.js index 964758e8eeb2005cde398166cf272ccd47ea2503..eeec97f693885ab4024e75788c40b74ba77d5141 100644 --- a/template/app/view/comments/RepliesExpander.js +++ b/template/app/view/comments/RepliesExpander.js @@ -108,7 +108,11 @@ Ext.define('Docs.view.comments.RepliesExpander', { target: this.target, parentId: this.parentId, newCommentTitle: "Reply to comment", - 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; - this.refreshRepliesButton(); + if (!this.expanded) { + this.refreshRepliesButton(); + } } });