Fixes bug where progress looked weird when creating a new post.

This commit is contained in:
Robin Ward 2013-03-27 17:40:35 -04:00
parent 55884e4b77
commit e0fc7afc41
3 changed files with 21 additions and 16 deletions

View File

@ -337,6 +337,9 @@ Discourse.Composer = Discourse.Model.extend({
currentUser = Discourse.get('currentUser'),
addedToStream = false;
// The post number we'll probably get from the server
var probablePostNumber = this.get('topic.highest_post_number') + 1;
// Build the post object
var createdPost = Discourse.Post.create({
raw: this.get('reply'),
@ -345,7 +348,8 @@ Discourse.Composer = Discourse.Model.extend({
topic_id: this.get('topic.id'),
reply_to_post_number: post ? post.get('post_number') : null,
imageSizes: opts.imageSizes,
post_number: this.get('topic.highest_post_number') + 1,
post_number: probablePostNumber,
index: probablePostNumber,
cooked: $('#wmd-preview').html(),
reply_count: 0,
display_username: currentUser.get('name'),
@ -373,6 +377,7 @@ Discourse.Composer = Discourse.Model.extend({
topic.set('last_posted_at', new Date());
topic.set('highest_post_number', createdPost.get('post_number'));
topic.set('last_poster', Discourse.get('currentUser'));
topic.set('filtered_posts_count', topic.get('filtered_posts_count') + 1);
// Set the topic view for the new post
createdPost.set('topic', topic);
@ -400,6 +405,7 @@ Discourse.Composer = Discourse.Model.extend({
createdPost.save(function(result) {
var addedPost = false,
saving = true;
createdPost.updateFromSave(result);
if (topic) {
// It's no longer a new post
@ -410,6 +416,7 @@ Discourse.Composer = Discourse.Model.extend({
composer.set('composeState', CLOSED);
saving = false;
}
composer.set('reply', '');
composer.set('createdPost', createdPost);
if (addedToStream) {
@ -422,6 +429,7 @@ Discourse.Composer = Discourse.Model.extend({
// If an error occurs
if (topic) {
topic.posts.removeObject(createdPost);
topic.set('filtered_posts_count', topic.get('filtered_posts_count') - 1);
}
promise.reject($.parseJSON(error.responseText).errors[0]);
composer.set('composeState', OPEN);

View File

@ -182,33 +182,31 @@ Discourse.Post = Discourse.Model.extend({
// Update the properties of this post from an obj, ignoring cooked as we should already
// have that rendered.
updateFromSave: function(obj) {
var lookup,
_this = this;
if (!obj) {
return;
}
var post = this;
// Update all the properties
if (!obj) return;
Object.each(obj, function(key, val) {
if (key === 'actions_summary') {
return false;
}
if (key === 'actions_summary') return false;
if (val) {
return _this.set(key, val);
post.set(key, val);
}
});
// Rebuild actions summary
this.set('actions_summary', Em.A());
if (obj.actions_summary) {
lookup = Em.Object.create();
var lookup = Em.Object.create();
obj.actions_summary.each(function(a) {
var actionSummary;
a.post = _this;
a.post = post;
a.actionType = Discourse.get("site").postActionTypeById(a.id);
actionSummary = Discourse.ActionSummary.create(a);
_this.get('actions_summary').pushObject(actionSummary);
return lookup.set(a.actionType.get('name_key'), actionSummary);
post.get('actions_summary').pushObject(actionSummary);
lookup.set(a.actionType.get('name_key'), actionSummary);
});
return this.set('actionByName', lookup);
this.set('actionByName', lookup);
}
},

View File

@ -70,7 +70,6 @@ Ember.DiscourseLocation = Ember.Object.extend({
*/
setURL: function(path) {
path = this.formatURL(path);
if (this.getState() && this.getState().path !== path) {
popstateReady = true;
this.pushState(path);