0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-02-10 23:36:14 -05:00

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.
This commit is contained in:
Felix Rieseberg 2014-11-21 17:42:03 -08:00
parent a2e670cb0b
commit ce9d590f34
5 changed files with 22 additions and 3 deletions

View file

@ -237,6 +237,13 @@ UploadUi = function ($dropzone, settings) {
} else { } else {
this.initWithImage(); 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;
ui = new UploadUi($dropzone, settings); ui = new UploadUi($dropzone, settings);
this.uploaderUi = ui;
ui.init(); ui.init();
}); });
}; };

View file

@ -7,10 +7,10 @@ var PostImageUploader = Ember.Component.extend({
var $this = this.$(), var $this = this.$(),
self = this; self = this;
uploader.call($this, { this.set('uploaderReference', uploader.call($this, {
editor: true, editor: true,
fileStorage: this.get('config.fileStorage') fileStorage: this.get('config.fileStorage')
}); }));
$this.on('uploadsuccess', function (event, result) { $this.on('uploadsuccess', function (event, result) {
if (result && result !== '' && result !== 'http://') { if (result && result !== '' && result !== 'http://') {

View file

@ -451,6 +451,14 @@ var PostSettingsMenuController = Ember.ObjectController.extend({
closeSubview: function () { closeSubview: function () {
this.set('isViewingSubview', false); this.set('isViewingSubview', false);
},
resetUploader: function () {
var uploader = this.get('uploaderReference');
if (uploader && uploader[0]) {
uploader[0].uploaderUi.reset();
}
} }
} }
}); });

View file

@ -18,6 +18,9 @@ var EditorNewRoute = AuthenticatedRoute.extend(base, {
// from previous posts // from previous posts
psm.removeObserver('titleScratch', psm, 'titleObserver'); psm.removeObserver('titleScratch', psm, 'titleObserver');
// Ensure that the PSM Image Uploader resets
psm.send('resetUploader');
this._super(controller, model); this._super(controller, model);
} }
}); });

View file

@ -7,7 +7,7 @@
<button class="close icon-x settings-menu-header-action" {{action "closeSettingsMenu"}}><span class="hidden">Close</span></button> <button class="close icon-x settings-menu-header-action" {{action "closeSettingsMenu"}}><span class="hidden">Close</span></button>
</div> </div>
<div class="settings-menu-content"> <div class="settings-menu-content">
{{gh-uploader uploaded="setCoverImage" canceled="clearCoverImage" image=image tagName="section"}} {{gh-uploader uploaded="setCoverImage" canceled="clearCoverImage" image=image uploaderReference=uploaderReference tagName="section"}}
<form> <form>
<div class="form-group"> <div class="form-group">
<label for="url">Post URL</label> <label for="url">Post URL</label>