From 6bf8ce0441b9b35bde79feffc13ec7da475e202f Mon Sep 17 00:00:00 2001 From: Rene Saarsoo Date: Thu, 8 Nov 2012 11:41:33 +0200 Subject: [PATCH] Update replies counter when replies added/removed. --- template/app/view/comments/List.js | 19 ++++++++++++++++++- template/app/view/comments/ListWithForm.js | 6 ++++++ template/app/view/comments/RepliesExpander.js | 10 ++++++++-- 3 files changed, 32 insertions(+), 3 deletions(-) diff --git a/template/app/view/comments/List.js b/template/app/view/comments/List.js index 68efeead..b9fc89ca 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 0e78981b..a6f7984b 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 964758e8..eeec97f6 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(); + } } }); -- GitLab