mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-26 04:13:30 +03:00
Merge pull request #3058 from halfdan/3012-close-notifications
Close notifications on transition or user action.
This commit is contained in:
commit
3981228043
@ -9,8 +9,8 @@ var DeletePostController = Ember.Controller.extend({
|
||||
|
||||
model.destroyRecord().then(function () {
|
||||
self.get('popover').closePopovers();
|
||||
self.notifications.showSuccess('Your post has been deleted.');
|
||||
self.transitionToRoute('posts.index');
|
||||
self.notifications.showSuccess('Your post has been deleted.', true);
|
||||
}, function () {
|
||||
self.notifications.showError('Your post could not be deleted. Please try again.');
|
||||
});
|
||||
|
@ -31,6 +31,9 @@ var SettingsGeneralController = Ember.ObjectController.extend({
|
||||
var self = this;
|
||||
|
||||
return this.get('model').save().then(function (model) {
|
||||
// @TODO This should call closePassive() to only close passive notifications
|
||||
self.notifications.closeAll();
|
||||
|
||||
self.notifications.showSuccess('Settings successfully saved.');
|
||||
return model;
|
||||
}).catch(this.notifications.showErrors);
|
||||
|
@ -21,10 +21,15 @@ var SettingsUserController = Ember.Controller.extend({
|
||||
|
||||
actions: {
|
||||
save: function () {
|
||||
var self = this;
|
||||
|
||||
alert('@TODO: Saving user...');
|
||||
|
||||
if (this.user.validate().get('isValid')) {
|
||||
this.user.save().then(function (response) {
|
||||
|
||||
// @TODO This should call closePassive() to only close passive notifications
|
||||
self.notifications.closeAll();
|
||||
alert('Done saving' + JSON.stringify(response));
|
||||
}, function () {
|
||||
alert('Error saving.');
|
||||
|
@ -8,6 +8,7 @@ var injectNotificationsInitializer = {
|
||||
|
||||
application.inject('controller', 'notifications', 'notifications:main');
|
||||
application.inject('component', 'notifications', 'notifications:main');
|
||||
application.inject('router', 'notifications', 'notifications:main');
|
||||
application.inject('route', 'notifications', 'notifications:main');
|
||||
}
|
||||
};
|
||||
|
@ -121,6 +121,7 @@ var EditorControllerMixin = Ember.Mixin.create(MarkerManager, {
|
||||
actions: {
|
||||
save: function () {
|
||||
var status = this.get('willPublish') ? 'published' : 'draft',
|
||||
isNew = this.get('isNew'),
|
||||
self = this;
|
||||
|
||||
// ensure an incomplete tag is finalised before save
|
||||
@ -128,7 +129,6 @@ var EditorControllerMixin = Ember.Mixin.create(MarkerManager, {
|
||||
|
||||
// set markdown equal to what's in the editor, minus the image markers.
|
||||
this.set('markdown', this.getMarkdown().withoutMarkers);
|
||||
|
||||
this.set('status', status);
|
||||
|
||||
return this.get('model').save().then(function (model) {
|
||||
@ -137,8 +137,11 @@ var EditorControllerMixin = Ember.Mixin.create(MarkerManager, {
|
||||
// for a saved model it would otherwise be false.
|
||||
self.set('isDirty', false);
|
||||
|
||||
// @TODO This should call closePassive() to only close passive notifications
|
||||
self.notifications.closeAll();
|
||||
|
||||
self.notifications.showSuccess('Post status saved as <strong>' +
|
||||
model.get('status') + '</strong>.');
|
||||
model.get('status') + '</strong>.', isNew ? true : false);
|
||||
return model;
|
||||
}).catch(function (errors) {
|
||||
self.notifications.showErrors(errors);
|
||||
|
@ -6,7 +6,13 @@ var Router = Ember.Router.extend();
|
||||
|
||||
Router.reopen({
|
||||
location: 'trailing-history', // use HTML5 History API instead of hash-tag based URLs
|
||||
rootURL: ghostPaths().subdir + '/ghost/ember/' // admin interface lives under sub-directory /ghost
|
||||
rootURL: ghostPaths().subdir + '/ghost/ember/', // admin interface lives under sub-directory /ghost
|
||||
|
||||
clearNotifications: function () {
|
||||
// @TODO This should call closePassive() to only close passive notifications
|
||||
this.notifications.closeAll();
|
||||
this.notifications.displayDelayed();
|
||||
}.on('didTransition')
|
||||
});
|
||||
|
||||
Router.map(function () {
|
||||
|
@ -16,10 +16,10 @@ var SignoutRoute = AuthenticatedRoute.extend(styleBody, loadingIndicator, {
|
||||
'X-CSRF-Token': this.get('csrf')
|
||||
}
|
||||
}).then(function () {
|
||||
self.notifications.showSuccess('You were successfully signed out.');
|
||||
self.transitionTo('signin');
|
||||
self.notifications.showSuccess('You were successfully signed out.', true);
|
||||
}, function (resp) {
|
||||
self.notifications.showAPIError(resp, 'There was a problem logging out, please try again.');
|
||||
self.notifications.showAPIError(resp, 'There was a problem logging out, please try again.', true);
|
||||
self.transitionTo('posts');
|
||||
});
|
||||
}
|
||||
|
@ -1,4 +1,5 @@
|
||||
var Notifications = Ember.ArrayProxy.extend({
|
||||
delayedNotifications: [],
|
||||
content: Ember.A(),
|
||||
timeout: 3000,
|
||||
pushObject: function (object) {
|
||||
@ -9,43 +10,58 @@ var Notifications = Ember.ArrayProxy.extend({
|
||||
}
|
||||
this._super(object);
|
||||
},
|
||||
showError: function (message) {
|
||||
this.pushObject({
|
||||
handleNotification: function (message, delayed) {
|
||||
if (!delayed) {
|
||||
this.pushObject(message);
|
||||
} else {
|
||||
this.delayedNotifications.push(message);
|
||||
}
|
||||
},
|
||||
showError: function (message, delayed) {
|
||||
this.handleNotification({
|
||||
type: 'error',
|
||||
message: message
|
||||
});
|
||||
}, delayed);
|
||||
},
|
||||
showErrors: function (errors) {
|
||||
for (var i = 0; i < errors.length; i += 1) {
|
||||
this.showError(errors[i].message || errors[i]);
|
||||
}
|
||||
},
|
||||
showAPIError: function (resp, defaultErrorText) {
|
||||
showAPIError: function (resp, defaultErrorText, delayed) {
|
||||
defaultErrorText = defaultErrorText || 'There was a problem on the server, please try again.';
|
||||
|
||||
if (resp && resp.jqXHR && resp.jqXHR.responseJSON && resp.jqXHR.responseJSON.error) {
|
||||
this.showError(resp.jqXHR.responseJSON.error);
|
||||
this.showError(resp.jqXHR.responseJSON.error, delayed);
|
||||
} else {
|
||||
this.showError(defaultErrorText);
|
||||
this.showError(defaultErrorText, delayed);
|
||||
}
|
||||
},
|
||||
showInfo: function (message) {
|
||||
this.pushObject({
|
||||
showInfo: function (message, delayed) {
|
||||
this.handleNotification({
|
||||
type: 'info',
|
||||
message: message
|
||||
});
|
||||
}, delayed);
|
||||
},
|
||||
showSuccess: function (message) {
|
||||
this.pushObject({
|
||||
showSuccess: function (message, delayed) {
|
||||
this.handleNotification({
|
||||
type: 'success',
|
||||
message: message
|
||||
});
|
||||
}, delayed);
|
||||
},
|
||||
showWarn: function (message) {
|
||||
this.pushObject({
|
||||
showWarn: function (message, delayed) {
|
||||
this.handleNotification({
|
||||
type: 'warn',
|
||||
message: message
|
||||
}, delayed);
|
||||
},
|
||||
displayDelayed: function () {
|
||||
var self = this;
|
||||
|
||||
self.delayedNotifications.forEach(function (message) {
|
||||
self.pushObject(message);
|
||||
});
|
||||
self.delayedNotifications = [];
|
||||
},
|
||||
closeAll: function () {
|
||||
this.clear();
|
||||
|
Loading…
Reference in New Issue
Block a user