From 7fec884ea0fea56e95584f53348bb47bbaf417c6 Mon Sep 17 00:00:00 2001 From: Fabian Becker Date: Thu, 26 Jun 2014 09:42:29 +0000 Subject: [PATCH] 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 --- core/client/mixins/editor-base-controller.js | 54 ++++++++++++++++++-- core/client/mixins/validation-engine.js | 2 +- 2 files changed, 52 insertions(+), 4 deletions(-) diff --git a/core/client/mixins/editor-base-controller.js b/core/client/mixins/editor-base-controller.js index 37f256f79e..a75438a1f8 100644 --- a/core/client/mixins/editor-base-controller.js +++ b/core/client/mixins/editor-base-controller.js @@ -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 += '
' + errors[0].message; + + this.notifications.showError(message, delay); + }, + actions: { save: function () { var status = this.get('willPublish') ? 'published' : 'draft', + prevStatus = this.get('status'), isNew = this.get('isNew'), self = this; @@ -140,11 +188,11 @@ var EditorControllerMixin = Ember.Mixin.create(MarkerManager, { // for a saved model it would otherwise be false. self.set('isDirty', false); - self.notifications.showSuccess('Post status saved as ' + - model.get('status') + '.', isNew ? true : false); + self.showSaveNotification(prevStatus, model.get('status'), isNew ? true : false); + return model; }).catch(function (errors) { - self.notifications.showErrors(errors); + self.showErrorNotification(prevStatus, self.get('status'), errors); return Ember.RSVP.reject(errors); }); }, diff --git a/core/client/mixins/validation-engine.js b/core/client/mixins/validation-engine.js index b5f0afbd70..c51a619f0c 100644 --- a/core/client/mixins/validation-engine.js +++ b/core/client/mixins/validation-engine.js @@ -51,7 +51,7 @@ var ValidationEngine = Ember.Mixin.create({ if (Ember.isArray(errors)) { // get validation error messages - message += ': ' + errors.mapBy('message').join(' '); + message = errors.mapBy('message').join('
'); } else if (typeof errors === 'object') { // Get messages from server response message += ': ' + getRequestErrorMessage(errors);