diff --git a/app/assets/javascripts/discourse/components/d-modal-body.js.es6 b/app/assets/javascripts/discourse/components/d-modal-body.js.es6 index fa2d8fa168c..638db7d8858 100644 --- a/app/assets/javascripts/discourse/components/d-modal-body.js.es6 +++ b/app/assets/javascripts/discourse/components/d-modal-body.js.es6 @@ -6,6 +6,12 @@ export default Ember.Component.extend({ $('#modal-alert').hide(); $('#discourse-modal').modal('show'); Ember.run.scheduleOnce('afterRender', this, this._afterFirstRender); + this.appEvents.on('modal-body:flash', msg => this._flash(msg)); + }, + + willDestroyElement() { + this._super(); + this.appEvents.off('modal-body:flash'); }, _afterFirstRender() { @@ -23,5 +29,12 @@ export default Ember.Component.extend({ } this.appEvents.trigger('modal:body-shown', this.getProperties('title')); - } + }, + + _flash(msg) { + $('#modal-alert').hide() + .removeClass('alert-error', 'alert-success') + .addClass(`alert alert-${msg.messageClass || 'success'}`).html(msg.text || '') + .fadeIn(); + }, }); diff --git a/app/assets/javascripts/discourse/mixins/modal-functionality.js.es6 b/app/assets/javascripts/discourse/mixins/modal-functionality.js.es6 index 7394488fcb8..23bc790e153 100644 --- a/app/assets/javascripts/discourse/mixins/modal-functionality.js.es6 +++ b/app/assets/javascripts/discourse/mixins/modal-functionality.js.es6 @@ -1,7 +1,5 @@ export default Ember.Mixin.create({ - flashMessage: null, - - flash(message, messageClass) { - this.set('flashMessage', Em.Object.create({ message, messageClass })); + flash(text, messageClass) { + this.appEvents.trigger('modal-body:flash', { text, messageClass }); } }); diff --git a/app/assets/javascripts/discourse/views/modal-body.js.es6 b/app/assets/javascripts/discourse/views/modal-body.js.es6 index 84191664210..e7e1f865baa 100644 --- a/app/assets/javascripts/discourse/views/modal-body.js.es6 +++ b/app/assets/javascripts/discourse/views/modal-body.js.es6 @@ -1,4 +1,3 @@ -import { observes } from "ember-addons/ember-computed-decorators"; import deprecated from 'discourse-common/lib/deprecated'; export default Ember.View.extend({ @@ -12,6 +11,13 @@ export default Ember.View.extend({ $('#modal-alert').hide(); $('#discourse-modal').modal('show'); Ember.run.scheduleOnce('afterRender', this, this._afterFirstRender); + + this.appEvents.on('modal-body:flash', msg => this._flash(msg)); + }, + + willDestroyElement() { + this._super(); + this.appEvents.off('modal-body:flash'); }, _afterFirstRender() { @@ -25,16 +31,10 @@ export default Ember.View.extend({ } }, - @observes("controller.flashMessage") - flashMessageChanged() { - const flashMessage = this.get('controller.flashMessage'); - if (flashMessage) { - const messageClass = flashMessage.get('messageClass') || 'success'; - $('#modal-alert').hide() - .removeClass('alert-error', 'alert-success') - .addClass("alert alert-" + messageClass).html(flashMessage.get('message')) - .fadeIn(); - } + _flash(msg) { + $('#modal-alert').hide() + .removeClass('alert-error', 'alert-success') + .addClass(`alert alert-${msg.messageClass || 'success'}`).html(msg.text || '') + .fadeIn(); } - });