FIX: Editing a title would not clear it out on your next edit.

This commit is contained in:
Robin Ward 2013-07-05 13:01:51 -04:00
parent 11bb9aafc7
commit d1a0b5dd44
2 changed files with 36 additions and 12 deletions

View File

@ -68,7 +68,6 @@ Discourse.Composer = Discourse.Model.extend({
post = this.get('post');
if (post) {
postDescription = Em.String.i18n('post.' + this.get('action'), {
link: postLink,
replyAvatar: Discourse.Utilities.tinyAvatar(post.get('username')),
@ -80,7 +79,6 @@ Discourse.Composer = Discourse.Model.extend({
postDescription += " " + Em.String.i18n("post.in_reply_to") + " " +
Discourse.Utilities.tinyAvatar(replyUsername) + " " + replyUsername;
}
}
switch (this.get('action')) {
@ -355,7 +353,7 @@ Discourse.Composer = Discourse.Model.extend({
Discourse.Post.load(opts.post.get('id')).then(function(result) {
composer.setProperties({
reply: result.get('raw'),
originalText: composer.get('reply'),
originalText: result.get('raw'),
loading: false
});
});
@ -372,6 +370,20 @@ Discourse.Composer = Discourse.Model.extend({
}
},
/**
Clear any state we have in preparation for a new composition.
@method clearState
**/
clearState: function() {
this.setProperties({
originalText: null,
reply: null,
post: null,
title: null
});
},
// When you edit a post
editPost: function(opts) {
var post = this.get('post'),
@ -398,9 +410,7 @@ Discourse.Composer = Discourse.Model.extend({
return Ember.Deferred.promise(function(promise) {
post.save(function(savedPost) {
composer.set('originalText', '');
composer.set('reply', '');
composer.set('post', null);
composer.clearState();
}, function(error) {
var response = $.parseJSON(error.responseText);
if (response && response.errors) {
@ -463,6 +473,7 @@ Discourse.Composer = Discourse.Model.extend({
saving = true;
createdPost.updateFromJson(result);
if (topic) {
// It's no longer a new post
createdPost.set('newPost', false);
@ -475,11 +486,8 @@ Discourse.Composer = Discourse.Model.extend({
saving = false;
}
composer.setProperties({
reply: '',
createdPost: createdPost,
title: ''
});
composer.clearState();
composer.set('createdPost', createdPost);
if (addedToStream) {
composer.set('composeState', CLOSED);
@ -487,7 +495,6 @@ Discourse.Composer = Discourse.Model.extend({
composer.set('composeState', SAVING);
}
return promise.resolve({ post: result });
}, function(error) {
// If an error occurs

View File

@ -159,3 +159,20 @@ asyncTest('importQuote with no post', function() {
});
});
test('clearState', function() {
var composer = Discourse.Composer.create({
originalText: 'asdf',
reply: 'asdf2',
post: Discourse.Post.create({id: 1}),
title: 'wat'
});
composer.clearState();
blank(composer.get('originalText'));
blank(composer.get('reply'));
blank(composer.get('post'));
blank(composer.get('title'));
});