From 61361ac91b3240dbb8a8ddd504a619924e2a0709 Mon Sep 17 00:00:00 2001 From: Jason Williams Date: Sun, 24 Aug 2014 19:16:20 +0000 Subject: [PATCH] Show warning dialog if session has ended in editor Closes #3839 - Display a warning modal in the editor routes if the user is logged out due to re-authorization problems. This provides a chance to copy any unsaved content before being sent to the signin page to log back in. --- .../controllers/modals/auth-failed-unsaved.js | 34 +++++++++++++++++++ ghost/admin/routes/application.js | 12 +++++++ .../templates/modals/auth-failed-unsaved.hbs | 8 +++++ 3 files changed, 54 insertions(+) create mode 100644 ghost/admin/controllers/modals/auth-failed-unsaved.js create mode 100644 ghost/admin/templates/modals/auth-failed-unsaved.hbs diff --git a/ghost/admin/controllers/modals/auth-failed-unsaved.js b/ghost/admin/controllers/modals/auth-failed-unsaved.js new file mode 100644 index 0000000000..a144ecd09c --- /dev/null +++ b/ghost/admin/controllers/modals/auth-failed-unsaved.js @@ -0,0 +1,34 @@ +var AuthFailedUnsavedController = Ember.Controller.extend({ + editorController: Ember.computed.alias('model'), + + actions: { + confirmAccept: function () { + var editorController = this.get('editorController'); + + if (editorController) { + editorController.get('model').rollback(); + } + + window.onbeforeunload = null; + + window.location = this.get('ghostPaths').adminRoot + '/signin/'; + }, + + confirmReject: function () { + + } + }, + + confirm: { + accept: { + text: 'Leave', + buttonClass: 'btn btn-red' + }, + reject: { + text: 'Stay', + buttonClass: 'btn btn-default btn-minor' + } + } +}); + +export default AuthFailedUnsavedController; diff --git a/ghost/admin/routes/application.js b/ghost/admin/routes/application.js index f06756bd7f..e98c16f009 100644 --- a/ghost/admin/routes/application.js +++ b/ghost/admin/routes/application.js @@ -13,6 +13,18 @@ var ApplicationRoute = Ember.Route.extend(SimpleAuth.ApplicationRouteMixin, Shor }, actions: { + authorizationFailed: function () { + var currentRoute = this.get('controller').get('currentRouteName'); + + if (currentRoute.split('.')[0] === 'editor') { + this.send('openModal', 'auth-failed-unsaved', this.controllerFor(currentRoute)); + + return; + } + + this._super(); + }, + closePopups: function () { this.get('popover').closePopovers(); this.get('notifications').closeAll(); diff --git a/ghost/admin/templates/modals/auth-failed-unsaved.hbs b/ghost/admin/templates/modals/auth-failed-unsaved.hbs new file mode 100644 index 0000000000..4e2e152e2a --- /dev/null +++ b/ghost/admin/templates/modals/auth-failed-unsaved.hbs @@ -0,0 +1,8 @@ +{{#gh-modal-dialog action="closeModal" showClose=true type="action" style="wide,centered" animation="fade" + title="Post NOT saved." confirm=confirm}} + +

Hey there! Something has gone wrong and you have been logged out. It looks like you have unsaved content that will be lost if you leave this page.

+ +

Copy your content somewhere safe before you go!

+ +{{/gh-modal-dialog}}