From 38ae87524de0886b470cc9ffefed42aac146b0bd Mon Sep 17 00:00:00 2001 From: James Inman Date: Mon, 9 Sep 2013 23:10:00 +0100 Subject: [PATCH 1/2] Notification cleanup Closes #666. * Adding new error notifications (removed post name, cleaned up statuses) when creating/updating a post * Removing scheduled from the maps and changing the text of publish-on * Made temporary "Scheduled publishing is not supported yet." message display in a proper error container, plus a slight grammar fix. * Removed ; from the start of validation errors on post error, as the previous sentence finishes with a . --- core/client/views/editor.js | 28 +++++++++++++--------------- 1 file changed, 13 insertions(+), 15 deletions(-) diff --git a/core/client/views/editor.js b/core/client/views/editor.js index cdb3945911..925c2d3e14 100644 --- a/core/client/views/editor.js +++ b/core/client/views/editor.js @@ -76,8 +76,13 @@ }, notificationMap: { - 'draft': 'saved as a draft', - 'published': 'published' + 'draft': 'has been saved as a draft', + 'published': 'has been published' + }, + + errorMap: { + 'draft': 'could not be saved as a draft', + 'published': 'could not be published' }, initialize: function () { @@ -119,7 +124,7 @@ status: 'passive' }); }, function (xhr) { - var status = keys[newIndex]; + var status = this.errorMap[newIndex]; // Show a notification about the error self.reportSaveError(xhr, model, status); }); @@ -174,20 +179,17 @@ updatePost: function (status) { var self = this, model = this.model, - prevStatus = model.get('status'), - notificationMap = this.notificationMap; + prevStatus = model.get('status'); // Default to same status if not passed in status = status || prevStatus; - model.trigger('willSave'); - this.savePost({ status: status }).then(function () { Ghost.notifications.addItem({ type: 'success', - message: ['Your post has been ', notificationMap[status], '.'].join(''), + message: ['Your post ', this.notificationMap[status], '.'].join(''), status: 'passive' }); // Refresh publish button and all relevant controls with updated status. @@ -198,7 +200,7 @@ // Set appropriate button status self.setActiveStatus(status, self.statusMap[status], prevStatus); // Show a notification about the error - self.reportSaveError(xhr, model, status); + self.reportSaveError(xhr, model, self.errorMap[status]); }); }, @@ -207,8 +209,6 @@ this.model.unset(item); }, this); - - var saved = this.model.save(_.extend({ title: $('#entry-title').val(), // TODO: The content_raw getter here isn't great, shouldn't rely on currentView. @@ -224,16 +224,14 @@ }, reportSaveError: function (response, model, status) { - var title = model.get('title') || '[Untitled]', - notificationStatus = this.notificationMap[status], - message = 'Your post: ' + title + ' has not been ' + notificationStatus; + var message = 'Your post ' + status + '.'; if (response) { // Get message from response message = Ghost.Views.Utils.getRequestErrorMessage(response); } else if (model.validationError) { // Grab a validation error - message += "; " + model.validationError; + message += " " + model.validationError; } Ghost.notifications.addItem({ From ae01e5eeaeeb9176a563931bfa264ecb751b79e9 Mon Sep 17 00:00:00 2001 From: Hannah Wolfe Date: Tue, 17 Sep 2013 21:35:30 +0100 Subject: [PATCH 2/2] Editor notification cleanup closes #666 - no more split messaging --- core/client/views/editor.js | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/core/client/views/editor.js b/core/client/views/editor.js index 925c2d3e14..ddef6ec5f5 100644 --- a/core/client/views/editor.js +++ b/core/client/views/editor.js @@ -76,13 +76,13 @@ }, notificationMap: { - 'draft': 'has been saved as a draft', - 'published': 'has been published' + 'draft': 'Your post has been saved as a draft.', + 'published': 'Your post has been published.' }, errorMap: { - 'draft': 'could not be saved as a draft', - 'published': 'could not be published' + 'draft': 'Your post could not be saved as a draft.', + 'published': 'Your post could not be published.' }, initialize: function () { @@ -109,22 +109,23 @@ model = self.model, prevStatus = model.get('status'), currentIndex = keys.indexOf(prevStatus), - newIndex; + newIndex, + status; newIndex = currentIndex + 1 > keys.length - 1 ? 0 : currentIndex + 1; + status = keys[newIndex]; - this.setActiveStatus(keys[newIndex], this.statusMap[keys[newIndex]], prevStatus); + this.setActiveStatus(keys[newIndex], this.statusMap[status], prevStatus); this.savePost({ status: keys[newIndex] }).then(function () { Ghost.notifications.addItem({ type: 'success', - message: 'Your post has been ' + self.notificationMap[newIndex] + '.', + message: self.notificationMap[status], status: 'passive' }); }, function (xhr) { - var status = this.errorMap[newIndex]; // Show a notification about the error self.reportSaveError(xhr, model, status); }); @@ -189,7 +190,7 @@ }).then(function () { Ghost.notifications.addItem({ type: 'success', - message: ['Your post ', this.notificationMap[status], '.'].join(''), + message: self.notificationMap[status], status: 'passive' }); // Refresh publish button and all relevant controls with updated status. @@ -200,7 +201,7 @@ // Set appropriate button status self.setActiveStatus(status, self.statusMap[status], prevStatus); // Show a notification about the error - self.reportSaveError(xhr, model, self.errorMap[status]); + self.reportSaveError(xhr, model, status); }); }, @@ -224,11 +225,11 @@ }, reportSaveError: function (response, model, status) { - var message = 'Your post ' + status + '.'; + var message = this.errorMap[status]; if (response) { // Get message from response - message = Ghost.Views.Utils.getRequestErrorMessage(response); + message += " " + Ghost.Views.Utils.getRequestErrorMessage(response); } else if (model.validationError) { // Grab a validation error message += " " + model.validationError;