From b7f6ec60c5a7185b504048e0fa169f2c23865db0 Mon Sep 17 00:00:00 2001 From: Jarek Radosz Date: Sat, 4 Jul 2020 14:09:55 +0200 Subject: [PATCH] MODAL: Untangle `onSelectPanel` Previously modal-tab component would call on click the onSelectPanel callback with itself (modal-tab) as `this` which severely limited its usefulness. Now showModal binds the callback to its controller. --- .../javascripts/discourse/app/components/modal-tab.js | 6 +++++- app/assets/javascripts/discourse/app/lib/show-modal.js | 5 ++++- .../javascripts/discourse/app/mixins/modal-functionality.js | 4 ---- 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/app/assets/javascripts/discourse/app/components/modal-tab.js b/app/assets/javascripts/discourse/app/components/modal-tab.js index 3211fbbdd25..a798e22d6d9 100644 --- a/app/assets/javascripts/discourse/app/components/modal-tab.js +++ b/app/assets/javascripts/discourse/app/components/modal-tab.js @@ -20,6 +20,10 @@ export default Component.extend({ }, click() { - this.onSelectPanel(this.panel); + this.set("selectedPanel", this.panel); + + if (this.onSelectPanel) { + this.onSelectPanel(this.panel); + } } }); diff --git a/app/assets/javascripts/discourse/app/lib/show-modal.js b/app/assets/javascripts/discourse/app/lib/show-modal.js index 37c6b8efe3f..6a6fb17a71b 100644 --- a/app/assets/javascripts/discourse/app/lib/show-modal.js +++ b/app/assets/javascripts/discourse/app/lib/show-modal.js @@ -50,7 +50,10 @@ export default function(name, opts) { }); if (controller.actions.onSelectPanel) { - modalController.set("onSelectPanel", controller.actions.onSelectPanel); + modalController.set( + "onSelectPanel", + controller.actions.onSelectPanel.bind(controller) + ); } modalController.set( diff --git a/app/assets/javascripts/discourse/app/mixins/modal-functionality.js b/app/assets/javascripts/discourse/app/mixins/modal-functionality.js index 70b5bd010c0..ac40b161b56 100644 --- a/app/assets/javascripts/discourse/app/mixins/modal-functionality.js +++ b/app/assets/javascripts/discourse/app/mixins/modal-functionality.js @@ -18,10 +18,6 @@ export default Mixin.create({ closeModal() { this.modal.send("closeModal"); this.set("panels", []); - }, - - onSelectPanel(panel) { - this.set("selectedPanel", panel); } } });