FIX: Flash messages were broken

This commit is contained in:
Robin Ward 2016-11-18 12:58:55 -05:00
parent 06254d3163
commit 7bd88b706a
3 changed files with 28 additions and 17 deletions

View File

@ -6,6 +6,12 @@ export default Ember.Component.extend({
$('#modal-alert').hide(); $('#modal-alert').hide();
$('#discourse-modal').modal('show'); $('#discourse-modal').modal('show');
Ember.run.scheduleOnce('afterRender', this, this._afterFirstRender); 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() { _afterFirstRender() {
@ -23,5 +29,12 @@ export default Ember.Component.extend({
} }
this.appEvents.trigger('modal:body-shown', this.getProperties('title')); 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();
},
}); });

View File

@ -1,7 +1,5 @@
export default Ember.Mixin.create({ export default Ember.Mixin.create({
flashMessage: null, flash(text, messageClass) {
this.appEvents.trigger('modal-body:flash', { text, messageClass });
flash(message, messageClass) {
this.set('flashMessage', Em.Object.create({ message, messageClass }));
} }
}); });

View File

@ -1,4 +1,3 @@
import { observes } from "ember-addons/ember-computed-decorators";
import deprecated from 'discourse-common/lib/deprecated'; import deprecated from 'discourse-common/lib/deprecated';
export default Ember.View.extend({ export default Ember.View.extend({
@ -12,6 +11,13 @@ export default Ember.View.extend({
$('#modal-alert').hide(); $('#modal-alert').hide();
$('#discourse-modal').modal('show'); $('#discourse-modal').modal('show');
Ember.run.scheduleOnce('afterRender', this, this._afterFirstRender); 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() { _afterFirstRender() {
@ -25,16 +31,10 @@ export default Ember.View.extend({
} }
}, },
@observes("controller.flashMessage") _flash(msg) {
flashMessageChanged() { $('#modal-alert').hide()
const flashMessage = this.get('controller.flashMessage'); .removeClass('alert-error', 'alert-success')
if (flashMessage) { .addClass(`alert alert-${msg.messageClass || 'success'}`).html(msg.text || '')
const messageClass = flashMessage.get('messageClass') || 'success'; .fadeIn();
$('#modal-alert').hide()
.removeClass('alert-error', 'alert-success')
.addClass("alert alert-" + messageClass).html(flashMessage.get('message'))
.fadeIn();
}
} }
}); });