From 634a09571100baecc70f16820dcfd6ff4841da80 Mon Sep 17 00:00:00 2001 From: Felix Rieseberg Date: Fri, 21 Nov 2014 17:42:03 -0800 Subject: [PATCH] Ensure Post Image Uploader Reset Closes #4431 - The PSM does not reset on a transition from editor (existing post) to editor (new post). If the existing post had a cover image, the image uploader would not be reset during the transition and appear slightly broken in the editor for the new post. - In this PR: A reference to the uploader is saved, allowing the route for editor/new to instruct the PSM controller to have the uploader reset. --- ghost/admin/assets/lib/uploader.js | 8 ++++++++ ghost/admin/components/gh-uploader.js | 4 ++-- ghost/admin/controllers/post-settings-menu.js | 8 ++++++++ ghost/admin/routes/editor/new.js | 3 +++ ghost/admin/templates/post-settings-menu.hbs | 2 +- 5 files changed, 22 insertions(+), 3 deletions(-) diff --git a/ghost/admin/assets/lib/uploader.js b/ghost/admin/assets/lib/uploader.js index b0c847df2f..6c41db7518 100644 --- a/ghost/admin/assets/lib/uploader.js +++ b/ghost/admin/assets/lib/uploader.js @@ -237,6 +237,13 @@ UploadUi = function ($dropzone, settings) { } else { this.initWithImage(); } + }, + + reset: function () { + $dropzone.find('.js-url').remove(); + $dropzone.find('.js-fileupload').removeClass('right'); + this.removeExtras(); + this.initWithDropzone(); } }); }; @@ -253,6 +260,7 @@ upload = function (options) { ui; ui = new UploadUi($dropzone, settings); + this.uploaderUi = ui; ui.init(); }); }; diff --git a/ghost/admin/components/gh-uploader.js b/ghost/admin/components/gh-uploader.js index eb7282e0df..c1bbfa9cf9 100644 --- a/ghost/admin/components/gh-uploader.js +++ b/ghost/admin/components/gh-uploader.js @@ -7,10 +7,10 @@ var PostImageUploader = Ember.Component.extend({ var $this = this.$(), self = this; - uploader.call($this, { + this.set('uploaderReference', uploader.call($this, { editor: true, fileStorage: this.get('config.fileStorage') - }); + })); $this.on('uploadsuccess', function (event, result) { if (result && result !== '' && result !== 'http://') { diff --git a/ghost/admin/controllers/post-settings-menu.js b/ghost/admin/controllers/post-settings-menu.js index 7a4036c68b..59e73343f2 100644 --- a/ghost/admin/controllers/post-settings-menu.js +++ b/ghost/admin/controllers/post-settings-menu.js @@ -451,6 +451,14 @@ var PostSettingsMenuController = Ember.ObjectController.extend({ closeSubview: function () { this.set('isViewingSubview', false); + }, + + resetUploader: function () { + var uploader = this.get('uploaderReference'); + + if (uploader && uploader[0]) { + uploader[0].uploaderUi.reset(); + } } } }); diff --git a/ghost/admin/routes/editor/new.js b/ghost/admin/routes/editor/new.js index 96da4d70a6..f5e4b0494f 100644 --- a/ghost/admin/routes/editor/new.js +++ b/ghost/admin/routes/editor/new.js @@ -18,6 +18,9 @@ var EditorNewRoute = AuthenticatedRoute.extend(base, { // from previous posts psm.removeObserver('titleScratch', psm, 'titleObserver'); + // Ensure that the PSM Image Uploader resets + psm.send('resetUploader'); + this._super(controller, model); } }); diff --git a/ghost/admin/templates/post-settings-menu.hbs b/ghost/admin/templates/post-settings-menu.hbs index 34cab541fa..156224eafe 100644 --- a/ghost/admin/templates/post-settings-menu.hbs +++ b/ghost/admin/templates/post-settings-menu.hbs @@ -7,7 +7,7 @@
- {{gh-uploader uploaded="setCoverImage" canceled="clearCoverImage" image=image tagName="section"}} + {{gh-uploader uploaded="setCoverImage" canceled="clearCoverImage" image=image uploaderReference=uploaderReference tagName="section"}}