mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-11-28 05:37:34 +03:00
Implement Notifications for Ember
closes #2417 - Adds Notification(s)Component - Render notifications in application.hbs - Adds handleError in application route
This commit is contained in:
parent
8ff2e929ae
commit
9da6f15d33
@ -1,6 +1,7 @@
|
||||
import Resolver from 'ember/resolver';
|
||||
import initFixtures from 'ghost/fixtures/init';
|
||||
import {currentUser, injectCurrentUser} from 'ghost/initializers/current-user';
|
||||
import {registerNotifications, injectNotifications} from 'ghost/initializers/notifications';
|
||||
import 'ghost/utils/link-view';
|
||||
|
||||
var App = Ember.Application.extend({
|
||||
@ -20,5 +21,7 @@ initFixtures();
|
||||
|
||||
App.initializer(currentUser);
|
||||
App.initializer(injectCurrentUser);
|
||||
App.initializer(registerNotifications);
|
||||
App.initializer(injectNotifications);
|
||||
|
||||
export default App;
|
||||
|
21
ghost/admin/components/ghost-notification.js
Normal file
21
ghost/admin/components/ghost-notification.js
Normal file
@ -0,0 +1,21 @@
|
||||
var NotificationComponent = Ember.Component.extend({
|
||||
classNames: ['js-bb-notification'],
|
||||
|
||||
didInsertElement: function () {
|
||||
var self = this;
|
||||
|
||||
self.$().on('animationend webkitAnimationEnd oanimationend MSAnimationEnd', function (event) {
|
||||
/* jshint unused: false */
|
||||
self.notifications.removeObject(self.get('message'));
|
||||
});
|
||||
},
|
||||
|
||||
actions: {
|
||||
closeNotification: function () {
|
||||
var self = this;
|
||||
self.notifications.removeObject(self.get('message'));
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
export default NotificationComponent;
|
7
ghost/admin/components/ghost-notifications.js
Normal file
7
ghost/admin/components/ghost-notifications.js
Normal file
@ -0,0 +1,7 @@
|
||||
var NotificationsComponent = Ember.Component.extend({
|
||||
tagName: 'aside',
|
||||
classNames: 'notifications',
|
||||
messages: Ember.computed.alias('notifications')
|
||||
});
|
||||
|
||||
export default NotificationsComponent;
|
21
ghost/admin/initializers/notifications.js
Normal file
21
ghost/admin/initializers/notifications.js
Normal file
@ -0,0 +1,21 @@
|
||||
import Notifications from 'ghost/utils/notifications';
|
||||
|
||||
var registerNotifications = {
|
||||
name: 'registerNotifications',
|
||||
|
||||
initialize: function (container, application) {
|
||||
application.register('notifications:main', Notifications);
|
||||
}
|
||||
};
|
||||
|
||||
var injectNotifications = {
|
||||
name: 'injectNotifications',
|
||||
|
||||
initialize: function (container, application) {
|
||||
application.inject('controller', 'notifications', 'notifications:main');
|
||||
application.inject('component', 'notifications', 'notifications:main');
|
||||
application.inject('route', 'notifications', 'notifications:main');
|
||||
}
|
||||
};
|
||||
|
||||
export {registerNotifications, injectNotifications};
|
@ -18,6 +18,17 @@ var ApplicationRoute = Ember.Route.extend({
|
||||
outlet: 'modal',
|
||||
parentView: 'application'
|
||||
});
|
||||
},
|
||||
|
||||
handleErrors: function (errors) {
|
||||
this.notifications.clear();
|
||||
errors.forEach(function (errorObj) {
|
||||
this.notifications.showError(errorObj.message || errorObj);
|
||||
|
||||
if (errorObj.hasOwnProperty('el')) {
|
||||
errorObj.el.addClass('input-error');
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
|
@ -23,7 +23,9 @@ var SigninRoute = Ember.Route.extend(styleBody, {
|
||||
}
|
||||
);
|
||||
} else {
|
||||
window.alert('Must enter email + passwort. Todo: Must show as notification'); // Todo Show notification
|
||||
this.notifications.clear();
|
||||
|
||||
this.notifications.showError('Must enter email + password');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -3,7 +3,8 @@
|
||||
{{/unless}}
|
||||
|
||||
<main role="main" id="main">
|
||||
{{ghost-notifications}}
|
||||
|
||||
{{outlet}}
|
||||
</main>
|
||||
|
||||
{{outlet modal}}
|
4
ghost/admin/templates/components/ghost-notification.hbs
Normal file
4
ghost/admin/templates/components/ghost-notification.hbs
Normal file
@ -0,0 +1,4 @@
|
||||
<section {{bind-attr class=":js-notification message.typeClass"}}>
|
||||
{{message.message}}
|
||||
<a class="close" {{action "closeNotification"}}><span class="hidden">Close</span></a>
|
||||
</section>
|
3
ghost/admin/templates/components/ghost-notifications.hbs
Normal file
3
ghost/admin/templates/components/ghost-notifications.hbs
Normal file
@ -0,0 +1,3 @@
|
||||
{{#each messages}}
|
||||
{{ghost-notification message=this}}
|
||||
{{/each}}
|
38
ghost/admin/utils/notifications.js
Normal file
38
ghost/admin/utils/notifications.js
Normal file
@ -0,0 +1,38 @@
|
||||
var Notifications = Ember.ArrayProxy.extend({
|
||||
content: Ember.A(),
|
||||
timeout: 3000,
|
||||
pushObject: function (object) {
|
||||
object.typeClass = 'notification-' + object.type;
|
||||
// This should be somewhere else.
|
||||
if (object.type === 'success') {
|
||||
object.typeClass = object.typeClass + " notification-passive";
|
||||
}
|
||||
this._super(object);
|
||||
},
|
||||
showError: function (message) {
|
||||
this.pushObject({
|
||||
type: 'error',
|
||||
message: message
|
||||
});
|
||||
},
|
||||
showInfo: function (message) {
|
||||
this.pushObject({
|
||||
type: 'info',
|
||||
message: message
|
||||
});
|
||||
},
|
||||
showSuccess: function (message) {
|
||||
this.pushObject({
|
||||
type: 'success',
|
||||
message: message
|
||||
});
|
||||
},
|
||||
showWarn: function (message) {
|
||||
this.pushObject({
|
||||
type: 'warn',
|
||||
message: message
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
export default Notifications;
|
Loading…
Reference in New Issue
Block a user