Fixes bug where progress looked weird when creating a new post.
This commit is contained in:
parent
55884e4b77
commit
e0fc7afc41
|
@ -337,6 +337,9 @@ Discourse.Composer = Discourse.Model.extend({
|
||||||
currentUser = Discourse.get('currentUser'),
|
currentUser = Discourse.get('currentUser'),
|
||||||
addedToStream = false;
|
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
|
// Build the post object
|
||||||
var createdPost = Discourse.Post.create({
|
var createdPost = Discourse.Post.create({
|
||||||
raw: this.get('reply'),
|
raw: this.get('reply'),
|
||||||
|
@ -345,7 +348,8 @@ Discourse.Composer = Discourse.Model.extend({
|
||||||
topic_id: this.get('topic.id'),
|
topic_id: this.get('topic.id'),
|
||||||
reply_to_post_number: post ? post.get('post_number') : null,
|
reply_to_post_number: post ? post.get('post_number') : null,
|
||||||
imageSizes: opts.imageSizes,
|
imageSizes: opts.imageSizes,
|
||||||
post_number: this.get('topic.highest_post_number') + 1,
|
post_number: probablePostNumber,
|
||||||
|
index: probablePostNumber,
|
||||||
cooked: $('#wmd-preview').html(),
|
cooked: $('#wmd-preview').html(),
|
||||||
reply_count: 0,
|
reply_count: 0,
|
||||||
display_username: currentUser.get('name'),
|
display_username: currentUser.get('name'),
|
||||||
|
@ -373,6 +377,7 @@ Discourse.Composer = Discourse.Model.extend({
|
||||||
topic.set('last_posted_at', new Date());
|
topic.set('last_posted_at', new Date());
|
||||||
topic.set('highest_post_number', createdPost.get('post_number'));
|
topic.set('highest_post_number', createdPost.get('post_number'));
|
||||||
topic.set('last_poster', Discourse.get('currentUser'));
|
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
|
// Set the topic view for the new post
|
||||||
createdPost.set('topic', topic);
|
createdPost.set('topic', topic);
|
||||||
|
@ -400,6 +405,7 @@ Discourse.Composer = Discourse.Model.extend({
|
||||||
createdPost.save(function(result) {
|
createdPost.save(function(result) {
|
||||||
var addedPost = false,
|
var addedPost = false,
|
||||||
saving = true;
|
saving = true;
|
||||||
|
|
||||||
createdPost.updateFromSave(result);
|
createdPost.updateFromSave(result);
|
||||||
if (topic) {
|
if (topic) {
|
||||||
// It's no longer a new post
|
// It's no longer a new post
|
||||||
|
@ -410,6 +416,7 @@ Discourse.Composer = Discourse.Model.extend({
|
||||||
composer.set('composeState', CLOSED);
|
composer.set('composeState', CLOSED);
|
||||||
saving = false;
|
saving = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
composer.set('reply', '');
|
composer.set('reply', '');
|
||||||
composer.set('createdPost', createdPost);
|
composer.set('createdPost', createdPost);
|
||||||
if (addedToStream) {
|
if (addedToStream) {
|
||||||
|
@ -422,6 +429,7 @@ Discourse.Composer = Discourse.Model.extend({
|
||||||
// If an error occurs
|
// If an error occurs
|
||||||
if (topic) {
|
if (topic) {
|
||||||
topic.posts.removeObject(createdPost);
|
topic.posts.removeObject(createdPost);
|
||||||
|
topic.set('filtered_posts_count', topic.get('filtered_posts_count') - 1);
|
||||||
}
|
}
|
||||||
promise.reject($.parseJSON(error.responseText).errors[0]);
|
promise.reject($.parseJSON(error.responseText).errors[0]);
|
||||||
composer.set('composeState', OPEN);
|
composer.set('composeState', OPEN);
|
||||||
|
|
|
@ -182,33 +182,31 @@ Discourse.Post = Discourse.Model.extend({
|
||||||
// Update the properties of this post from an obj, ignoring cooked as we should already
|
// Update the properties of this post from an obj, ignoring cooked as we should already
|
||||||
// have that rendered.
|
// have that rendered.
|
||||||
updateFromSave: function(obj) {
|
updateFromSave: function(obj) {
|
||||||
var lookup,
|
|
||||||
_this = this;
|
var post = this;
|
||||||
if (!obj) {
|
|
||||||
return;
|
// Update all the properties
|
||||||
}
|
if (!obj) return;
|
||||||
Object.each(obj, function(key, val) {
|
Object.each(obj, function(key, val) {
|
||||||
if (key === 'actions_summary') {
|
if (key === 'actions_summary') return false;
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if (val) {
|
if (val) {
|
||||||
return _this.set(key, val);
|
post.set(key, val);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// Rebuild actions summary
|
// Rebuild actions summary
|
||||||
this.set('actions_summary', Em.A());
|
this.set('actions_summary', Em.A());
|
||||||
if (obj.actions_summary) {
|
if (obj.actions_summary) {
|
||||||
lookup = Em.Object.create();
|
var lookup = Em.Object.create();
|
||||||
obj.actions_summary.each(function(a) {
|
obj.actions_summary.each(function(a) {
|
||||||
var actionSummary;
|
var actionSummary;
|
||||||
a.post = _this;
|
a.post = post;
|
||||||
a.actionType = Discourse.get("site").postActionTypeById(a.id);
|
a.actionType = Discourse.get("site").postActionTypeById(a.id);
|
||||||
actionSummary = Discourse.ActionSummary.create(a);
|
actionSummary = Discourse.ActionSummary.create(a);
|
||||||
_this.get('actions_summary').pushObject(actionSummary);
|
post.get('actions_summary').pushObject(actionSummary);
|
||||||
return lookup.set(a.actionType.get('name_key'), actionSummary);
|
lookup.set(a.actionType.get('name_key'), actionSummary);
|
||||||
});
|
});
|
||||||
return this.set('actionByName', lookup);
|
this.set('actionByName', lookup);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
|
@ -70,7 +70,6 @@ Ember.DiscourseLocation = Ember.Object.extend({
|
||||||
*/
|
*/
|
||||||
setURL: function(path) {
|
setURL: function(path) {
|
||||||
path = this.formatURL(path);
|
path = this.formatURL(path);
|
||||||
|
|
||||||
if (this.getState() && this.getState().path !== path) {
|
if (this.getState() && this.getState().path !== path) {
|
||||||
popstateReady = true;
|
popstateReady = true;
|
||||||
this.pushState(path);
|
this.pushState(path);
|
||||||
|
|
Loading…
Reference in New Issue