mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-01-20 22:42:53 -05:00
Show correct post notificatons based on status.
closes #2850 - Add messageMap from old admin - Add two methods to pick the correct notification based on prev status and current status
This commit is contained in:
parent
9c4f427340
commit
7fec884ea0
2 changed files with 52 additions and 4 deletions
|
@ -118,9 +118,57 @@ var EditorControllerMixin = Ember.Mixin.create(MarkerManager, {
|
||||||
'==============================';
|
'==============================';
|
||||||
},
|
},
|
||||||
|
|
||||||
|
//TODO: This has to be moved to the I18n localization file.
|
||||||
|
//This structure is supposed to be close to the i18n-localization which will be used soon.
|
||||||
|
messageMap: {
|
||||||
|
errors: {
|
||||||
|
post: {
|
||||||
|
published: {
|
||||||
|
'published': 'Your post could not be updated.',
|
||||||
|
'draft': 'Your post could not be saved as a draft.'
|
||||||
|
},
|
||||||
|
draft: {
|
||||||
|
'published': 'Your post could not be published.',
|
||||||
|
'draft': 'Your post could not be saved as a draft.'
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
success: {
|
||||||
|
post: {
|
||||||
|
published: {
|
||||||
|
'published': 'Your post has been updated.',
|
||||||
|
'draft': 'Your post has been saved as a draft.'
|
||||||
|
},
|
||||||
|
draft: {
|
||||||
|
'published': 'Your post has been published.',
|
||||||
|
'draft': 'Your post has been saved as a draft.'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
showSaveNotification: function (prevStatus, status, delay) {
|
||||||
|
var message = this.messageMap.success.post[prevStatus][status];
|
||||||
|
this.notifications.closeAll();
|
||||||
|
|
||||||
|
this.notifications.showSuccess(message, delay);
|
||||||
|
},
|
||||||
|
|
||||||
|
showErrorNotification: function (prevStatus, status, errors, delay) {
|
||||||
|
var message = this.messageMap.errors.post[prevStatus][status];
|
||||||
|
this.notifications.closeAll();
|
||||||
|
|
||||||
|
message += '<br />' + errors[0].message;
|
||||||
|
|
||||||
|
this.notifications.showError(message, delay);
|
||||||
|
},
|
||||||
|
|
||||||
actions: {
|
actions: {
|
||||||
save: function () {
|
save: function () {
|
||||||
var status = this.get('willPublish') ? 'published' : 'draft',
|
var status = this.get('willPublish') ? 'published' : 'draft',
|
||||||
|
prevStatus = this.get('status'),
|
||||||
isNew = this.get('isNew'),
|
isNew = this.get('isNew'),
|
||||||
self = this;
|
self = this;
|
||||||
|
|
||||||
|
@ -140,11 +188,11 @@ var EditorControllerMixin = Ember.Mixin.create(MarkerManager, {
|
||||||
// for a saved model it would otherwise be false.
|
// for a saved model it would otherwise be false.
|
||||||
self.set('isDirty', false);
|
self.set('isDirty', false);
|
||||||
|
|
||||||
self.notifications.showSuccess('Post status saved as <strong>' +
|
self.showSaveNotification(prevStatus, model.get('status'), isNew ? true : false);
|
||||||
model.get('status') + '</strong>.', isNew ? true : false);
|
|
||||||
return model;
|
return model;
|
||||||
}).catch(function (errors) {
|
}).catch(function (errors) {
|
||||||
self.notifications.showErrors(errors);
|
self.showErrorNotification(prevStatus, self.get('status'), errors);
|
||||||
return Ember.RSVP.reject(errors);
|
return Ember.RSVP.reject(errors);
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
|
@ -51,7 +51,7 @@ var ValidationEngine = Ember.Mixin.create({
|
||||||
|
|
||||||
if (Ember.isArray(errors)) {
|
if (Ember.isArray(errors)) {
|
||||||
// get validation error messages
|
// get validation error messages
|
||||||
message += ': ' + errors.mapBy('message').join(' ');
|
message = errors.mapBy('message').join('<br />');
|
||||||
} else if (typeof errors === 'object') {
|
} else if (typeof errors === 'object') {
|
||||||
// Get messages from server response
|
// Get messages from server response
|
||||||
message += ': ' + getRequestErrorMessage(errors);
|
message += ': ' + getRequestErrorMessage(errors);
|
||||||
|
|
Loading…
Add table
Reference in a new issue