From 9db46085ad8f32037a4153d918a174afb49ad599 Mon Sep 17 00:00:00 2001 From: Artur Arseniev Date: Sun, 2 Sep 2018 17:42:49 +0200 Subject: [PATCH] Re-render buttons on change of any of its properties --- src/panels/view/ButtonView.js | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/panels/view/ButtonView.js b/src/panels/view/ButtonView.js index b948620f4..b75cef5c9 100644 --- a/src/panels/view/ButtonView.js +++ b/src/panels/view/ButtonView.js @@ -22,6 +22,7 @@ module.exports = Backbone.View.extend({ this.disableCls = pfx + 'active'; this.btnsVisCls = pfx + 'visible'; this.className = pfx + 'btn' + (cls ? ' ' + cls : ''); + this.listenTo(this.model, 'change', this.render); this.listenTo(this.model, 'change:active updateActive', this.updateActive); this.listenTo(this.model, 'checkActive', this.checkActive); this.listenTo(this.model, 'change:bntsVis', this.updateBtnsVis); @@ -113,8 +114,8 @@ module.exports = Backbone.View.extend({ * @return void * */ checkActive() { - if (this.model.get('active')) this.$el.addClass(this.activeCls); - else this.$el.removeClass(this.activeCls); + const { model, $el, activeCls } = this; + model.get('active') ? $el.addClass(activeCls) : $el.removeClass(activeCls); }, /** @@ -151,10 +152,12 @@ module.exports = Backbone.View.extend({ render() { const label = this.model.get('label'); - const $el = this.$el; + const { $el } = this; + $el.empty(); this.updateAttributes(); $el.attr('class', this.className); label && $el.append(label); + this.checkActive(); return this; }