DEV: Call onClose for closing modals.

DEV: Call onClose for closing modals.

From d657ce844b6658060adad0a1a7565a03dcfd87f2 Mon Sep 17 00:00:00 2001
From: Dan Ungureanu <dan@ungureanu.me>
Date: Tue, 20 Nov 2018 18:02:07 +0200
Subject: [PATCH] DEV: Call onClose for closing modals.


diff --git a/app/assets/javascripts/discourse/lib/show-modal.js.es6 b/app/assets/javascripts/discourse/lib/show-modal.js.es6
index 8b865ce..675a0e3 100644
--- a/app/assets/javascripts/discourse/lib/show-modal.js.es6
+++ b/app/assets/javascripts/discourse/lib/show-modal.js.es6
@@ -39,6 +39,7 @@ export default function(name, opts) {
   modalController.set("modalClass", opts.modalClass);
 
   const controllerName = opts.admin ? `modals/${name}` : name;
+  modalController.set("name", controllerName);
 
   let controller = container.lookup("controller:" + controllerName);
   const templateName = opts.templateName || Ember.String.dasherize(name);
diff --git a/app/assets/javascripts/discourse/routes/application.js.es6 b/app/assets/javascripts/discourse/routes/application.js.es6
index a161f09..0577786 100644
--- a/app/assets/javascripts/discourse/routes/application.js.es6
+++ b/app/assets/javascripts/discourse/routes/application.js.es6
@@ -144,6 +144,13 @@ const ApplicationRoute = Discourse.Route.extend(OpenComposer, {
     // Close the current modal, and destroy its state.
     closeModal() {
       this.render("hide-modal", { into: "modal", outlet: "modalBody" });
+
+      const route = getOwner(this).lookup("route:application");
+      const name = route.controllerFor("modal").get("name");
+      const controller = getOwner(this).lookup(`controller:${name}`);
+      if (controller && controller.onClose) {
+        controller.onClose();
+      }
     },
 
     /**

GitHub

1 Like