Skip to content

Commit

Permalink
FIX: Editing a title would not clear it out on your next edit.
Browse files Browse the repository at this point in the history
  • Loading branch information
eviltrout committed Jul 5, 2013
1 parent 11bb9aa commit d1a0b5d
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 12 deletions.
31 changes: 19 additions & 12 deletions app/assets/javascripts/discourse/models/composer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')),
Expand All @@ -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')) {
Expand Down Expand Up @@ -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
});
});
Expand All @@ -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'),
Expand All @@ -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) {
Expand Down Expand Up @@ -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);
Expand All @@ -475,19 +486,15 @@ 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);
} else if (saving) {
composer.set('composeState', SAVING);
}


return promise.resolve({ post: result });
}, function(error) {
// If an error occurs
Expand Down
17 changes: 17 additions & 0 deletions test/javascripts/models/composer_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'));

});

0 comments on commit d1a0b5d

Please sign in to comment.