FIX: Refresh header if topic details are updated

This commit is contained in:
Robin Ward 2016-12-19 12:25:28 -05:00
parent e03d5e2140
commit 05e99a68ce
2 changed files with 21 additions and 22 deletions

View File

@ -404,7 +404,6 @@ export default Ember.Controller.extend({
save(force) { save(force) {
const composer = this.get('model'); const composer = this.get('model');
const self = this;
// Clear the warning state if we're not showing the checkbox anymore // Clear the warning state if we're not showing the checkbox anymore
if (!this.get('showWarning')) { if (!this.get('showWarning')) {
@ -437,10 +436,10 @@ export default Ember.Controller.extend({
buttons.push({ buttons.push({
"label": I18n.t("composer.reply_here") + "<br/><div class='topic-title overflow-ellipsis'>" + currentTopic.get('fancyTitle') + "</div>", "label": I18n.t("composer.reply_here") + "<br/><div class='topic-title overflow-ellipsis'>" + currentTopic.get('fancyTitle') + "</div>",
"class": "btn btn-reply-here", "class": "btn btn-reply-here",
"callback": function() { callback: () => {
composer.set('topic', currentTopic); composer.set('topic', currentTopic);
composer.set('post', null); composer.set('post', null);
self.save(true); this.save(true);
} }
}); });
} }
@ -448,9 +447,7 @@ export default Ember.Controller.extend({
buttons.push({ buttons.push({
"label": I18n.t("composer.reply_original") + "<br/><div class='topic-title overflow-ellipsis'>" + this.get('model.topic.fancyTitle') + "</div>", "label": I18n.t("composer.reply_original") + "<br/><div class='topic-title overflow-ellipsis'>" + this.get('model.topic.fancyTitle') + "</div>",
"class": "btn-primary btn-reply-on-original", "class": "btn-primary btn-reply-on-original",
"callback": function() { callback: () => this.save(true)
self.save(true);
}
}); });
bootbox.dialog(message, buttons, { "classes": "reply-where-modal" }); bootbox.dialog(message, buttons, { "classes": "reply-where-modal" });
@ -471,29 +468,32 @@ export default Ember.Controller.extend({
} }
}); });
const promise = composer.save({ imageSizes, editReason: this.get("editReason")}).then(function(result) { const promise = composer.save({ imageSizes, editReason: this.get("editReason")}).then(result=> {
if (result.responseJson.action === "enqueued") { if (result.responseJson.action === "enqueued") {
self.send('postWasEnqueued', result.responseJson); this.send('postWasEnqueued', result.responseJson);
self.destroyDraft(); this.destroyDraft();
self.close(); this.close();
self.appEvents.trigger('post-stream:refresh'); this.appEvents.trigger('post-stream:refresh');
return result; return result;
} }
// If user "created a new topic/post" or "replied as a new topic" successfully, remove the draft. // If user "created a new topic/post" or "replied as a new topic" successfully, remove the draft.
if (result.responseJson.action === "create_post" || self.get('replyAsNewTopicDraft')) { if (result.responseJson.action === "create_post" || this.get('replyAsNewTopicDraft')) {
self.destroyDraft(); this.destroyDraft();
} }
if (self.get('model.action') === 'edit') { if (this.get('model.action') === 'edit') {
self.appEvents.trigger('post-stream:refresh', { id: parseInt(result.responseJson.id) }); this.appEvents.trigger('post-stream:refresh', { id: parseInt(result.responseJson.id) });
if (result.responseJson.post.post_number === 1) {
this.appEvents.trigger('header:show-topic', composer.get('topic'));
}
} else { } else {
self.appEvents.trigger('post-stream:refresh'); this.appEvents.trigger('post-stream:refresh');
} }
if (result.responseJson.action === "create_post") { if (result.responseJson.action === "create_post") {
self.appEvents.trigger('post:highlight', result.payload.post_number); this.appEvents.trigger('post:highlight', result.payload.post_number);
} }
self.close(); this.close();
const currentUser = Discourse.User.current(); const currentUser = Discourse.User.current();
if (composer.get('creatingTopic')) { if (composer.get('creatingTopic')) {
@ -510,9 +510,9 @@ export default Ember.Controller.extend({
} }
} }
}).catch(function(error) { }).catch(error => {
composer.set('disableDrafts', false); composer.set('disableDrafts', false);
self.appEvents.one('composer:will-open', () => bootbox.alert(error)); this.appEvents.one('composer:will-open', () => bootbox.alert(error));
}); });
if (this.get('application.currentRouteName').split('.')[0] === 'topic' && if (this.get('application.currentRouteName').split('.')[0] === 'topic' &&

View File

@ -552,8 +552,7 @@ const Composer = RestModel.extend({
post.get('post_number') === 1 && post.get('post_number') === 1 &&
this.get('topic.details.can_edit')) { this.get('topic.details.can_edit')) {
const topicProps = this.getProperties(Object.keys(_edit_topic_serializer)); const topicProps = this.getProperties(Object.keys(_edit_topic_serializer));
promise = Topic.update(this.get('topic'), topicProps);
promise = Topic.update(this.get('topic'), topicProps);
} else { } else {
promise = Ember.RSVP.resolve(); promise = Ember.RSVP.resolve();
} }