mirror of
https://github.com/flarum/core.git
synced 2025-07-25 18:51:40 +02:00
Move alerts to their own controller
This commit is contained in:
17
ember/app/controllers/alerts.js
Normal file
17
ember/app/controllers/alerts.js
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
import Ember from 'ember';
|
||||||
|
|
||||||
|
export default Ember.Controller.extend({
|
||||||
|
alerts: [],
|
||||||
|
|
||||||
|
actions: {
|
||||||
|
alert: function(message) {
|
||||||
|
this.get('alerts').pushObject(message);
|
||||||
|
},
|
||||||
|
dismissAlert: function(message) {
|
||||||
|
this.get('alerts').removeObject(message);
|
||||||
|
},
|
||||||
|
clearAlerts: function() {
|
||||||
|
this.get('alerts').clear();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
@@ -15,20 +15,9 @@ export default Ember.Controller.extend({
|
|||||||
searchQuery: '',
|
searchQuery: '',
|
||||||
searchActive: false,
|
searchActive: false,
|
||||||
|
|
||||||
alerts: [],
|
|
||||||
|
|
||||||
actions: {
|
actions: {
|
||||||
search: function(query) {
|
search: function(query) {
|
||||||
this.transitionToRoute('index', {queryParams: {searchQuery: query, sort: query ? 'relevance' : 'recent'}});
|
this.transitionToRoute('index', {queryParams: {searchQuery: query, sort: query ? 'relevance' : 'recent'}});
|
||||||
},
|
|
||||||
alert: function(message) {
|
|
||||||
this.get('alerts').pushObject(message);
|
|
||||||
},
|
|
||||||
dismissAlert: function(message) {
|
|
||||||
this.get('alerts').removeObject(message);
|
|
||||||
},
|
|
||||||
clearAlerts: function() {
|
|
||||||
this.get('alerts').clear();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@@ -4,8 +4,8 @@ import ComposerReply from '../components/discussions/composer-reply';
|
|||||||
import ActionButton from '../components/ui/controls/action-button';
|
import ActionButton from '../components/ui/controls/action-button';
|
||||||
import AlertMessage from '../components/alert-message';
|
import AlertMessage from '../components/alert-message';
|
||||||
|
|
||||||
export default Ember.ObjectController.extend(Ember.Evented, {
|
export default Ember.Controller.extend(Ember.Evented, {
|
||||||
needs: ['application', 'composer'],
|
needs: ['application', 'alerts', 'composer'],
|
||||||
|
|
||||||
queryParams: ['start'],
|
queryParams: ['start'],
|
||||||
start: '1',
|
start: '1',
|
||||||
@@ -25,7 +25,7 @@ export default Ember.ObjectController.extend(Ember.Evented, {
|
|||||||
var stream = this.get('stream');
|
var stream = this.get('stream');
|
||||||
|
|
||||||
composer.set('content.loading', true);
|
composer.set('content.loading', true);
|
||||||
controller.get('controllers.application').send('clearAlerts');
|
controller.get('controllers.alerts').send('clearAlerts');
|
||||||
|
|
||||||
var post = this.store.createRecord('post', {
|
var post = this.store.createRecord('post', {
|
||||||
content: data.content,
|
content: data.content,
|
||||||
@@ -59,7 +59,7 @@ export default Ember.ObjectController.extend(Ember.Evented, {
|
|||||||
message: 'Your reply was posted.'
|
message: 'Your reply was posted.'
|
||||||
});
|
});
|
||||||
message.on('populateControls', function(controls) {
|
message.on('populateControls', function(controls) {
|
||||||
controls.pushObjectWithTag(ActionButton.extend({
|
controls.pushObjectWithTag(ActionButton.create({
|
||||||
label: 'View',
|
label: 'View',
|
||||||
action: function() {
|
action: function() {
|
||||||
controller.transitionToRoute('discussion', post.get('discussion'), {queryParams: {start: post.get('number')}});
|
controller.transitionToRoute('discussion', post.get('discussion'), {queryParams: {start: post.get('number')}});
|
||||||
@@ -67,7 +67,7 @@ export default Ember.ObjectController.extend(Ember.Evented, {
|
|||||||
}
|
}
|
||||||
}), 'view');
|
}), 'view');
|
||||||
});
|
});
|
||||||
controller.get('controllers.application').send('alert', message);
|
controller.get('controllers.alerts').send('alert', message);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
function(reason) {
|
function(reason) {
|
||||||
@@ -77,7 +77,7 @@ export default Ember.ObjectController.extend(Ember.Evented, {
|
|||||||
type: 'warning',
|
type: 'warning',
|
||||||
message: reason.errors[i]
|
message: reason.errors[i]
|
||||||
});
|
});
|
||||||
controller.get('controllers.application').send('alert', message);
|
controller.get('controllers.alerts').send('alert', message);
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.finally(function() {
|
.finally(function() {
|
||||||
@@ -93,7 +93,7 @@ export default Ember.ObjectController.extend(Ember.Evented, {
|
|||||||
|
|
||||||
// If the composer is already set up for this discussion, then we
|
// If the composer is already set up for this discussion, then we
|
||||||
// don't need to change its content - we can just show it.
|
// don't need to change its content - we can just show it.
|
||||||
if (!(composer.get('content') instanceof ComposerReply) || composer.get('content.discussion') != discussion) {
|
if (!(composer.get('content') instanceof ComposerReply) || composer.get('content.discussion') !== discussion) {
|
||||||
composer.switchContent(ComposerReply.create({
|
composer.switchContent(ComposerReply.create({
|
||||||
user: controller.get('session.user'),
|
user: controller.get('session.user'),
|
||||||
discussion: discussion,
|
discussion: discussion,
|
||||||
|
@@ -7,7 +7,7 @@ import ComposerDiscussion from '../components/discussions/composer-discussion';
|
|||||||
import AlertMessage from '../components/alert-message';
|
import AlertMessage from '../components/alert-message';
|
||||||
|
|
||||||
export default Ember.Controller.extend(Ember.Evented, PaneableMixin, {
|
export default Ember.Controller.extend(Ember.Evented, PaneableMixin, {
|
||||||
needs: ['application', 'composer', 'index/index', 'discussion'],
|
needs: ['application', 'composer', 'alerts', 'index/index', 'discussion'],
|
||||||
|
|
||||||
index: Ember.computed.alias('controllers.index/index'),
|
index: Ember.computed.alias('controllers.index/index'),
|
||||||
|
|
||||||
@@ -19,7 +19,7 @@ export default Ember.Controller.extend(Ember.Evented, PaneableMixin, {
|
|||||||
var stream = this.get('stream');
|
var stream = this.get('stream');
|
||||||
|
|
||||||
composer.set('content.loading', true);
|
composer.set('content.loading', true);
|
||||||
controller.get('controllers.application').send('clearAlerts');
|
controller.get('controllers.alerts').send('clearAlerts');
|
||||||
|
|
||||||
var discussion = this.store.createRecord('discussion', {
|
var discussion = this.store.createRecord('discussion', {
|
||||||
title: data.title,
|
title: data.title,
|
||||||
@@ -38,7 +38,7 @@ export default Ember.Controller.extend(Ember.Evented, PaneableMixin, {
|
|||||||
type: 'warning',
|
type: 'warning',
|
||||||
message: reason.errors[i]
|
message: reason.errors[i]
|
||||||
});
|
});
|
||||||
controller.get('controllers.application').send('alert', message);
|
controller.get('controllers.alerts').send('alert', message);
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.finally(function() {
|
.finally(function() {
|
||||||
|
7
ember/app/initializers/inject-components.js
Normal file
7
ember/app/initializers/inject-components.js
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
export default {
|
||||||
|
name: 'inject-components',
|
||||||
|
initialize: function(container, application) {
|
||||||
|
application.inject('component', 'alerts', 'controller:alerts')
|
||||||
|
application.inject('component', 'composer', 'controller:composer')
|
||||||
|
}
|
||||||
|
};
|
7
ember/app/templates/alerts.hbs
Normal file
7
ember/app/templates/alerts.hbs
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
<div class="alerts">
|
||||||
|
{{#each alert in alerts}}
|
||||||
|
<div class="alert-wrapper">
|
||||||
|
{{view alert dismiss="dismissAlert"}}
|
||||||
|
</div>
|
||||||
|
{{/each}}
|
||||||
|
</div>
|
@@ -47,12 +47,8 @@
|
|||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{{outlet "modal"}}
|
<div id="modal" class="modal fade">
|
||||||
|
{{outlet "modal"}}
|
||||||
<div class="alerts">
|
|
||||||
{{#each alert in alerts}}
|
|
||||||
<div class="alert-wrapper">
|
|
||||||
{{view alert dismiss="dismissAlert"}}
|
|
||||||
</div>
|
|
||||||
{{/each}}
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
{{render "alerts"}}
|
||||||
|
@@ -1,6 +1,6 @@
|
|||||||
<header class="hero discussion-hero">
|
<header class="hero discussion-hero">
|
||||||
<div class="container">
|
<div class="container">
|
||||||
<h2>{{title}}</h2>
|
<h2>{{model.title}}</h2>
|
||||||
</div>
|
</div>
|
||||||
</header>
|
</header>
|
||||||
|
|
||||||
@@ -13,6 +13,5 @@
|
|||||||
viewName="streamContent"
|
viewName="streamContent"
|
||||||
stream=stream
|
stream=stream
|
||||||
class="discussion-posts posts"
|
class="discussion-posts posts"
|
||||||
component="discussions/post-wrapper"
|
|
||||||
updateStart="updateStart"}}
|
updateStart="updateStart"}}
|
||||||
</div>
|
</div>
|
||||||
|
Reference in New Issue
Block a user