FIX: quote whote post should insert at cursor position

This commit is contained in:
Régis Hanol
2015-02-02 19:08:28 +01:00
parent f15b0d205f
commit 0a252d7785
4 changed files with 28 additions and 75 deletions

View File

@@ -39,7 +39,34 @@ export default DiscourseController.extend({
// Import a quote from the post
importQuote: function() {
this.get('model').importQuote();
var postStream = this.get('topic.postStream'),
postId = this.get('model.post.id');
// If there is no current post, use the first post id from the stream
if (!postId && postStream) {
postId = postStream.get('firstPostId');
}
// If we're editing a post, fetch the reply when importing a quote
if (this.get('model.editingPost')) {
var replyToPostNumber = this.get('model.post.reply_to_post_number');
if (replyToPostNumber) {
var replyPost = postStream.get('posts').findBy('post_number', replyToPostNumber);
if (replyPost) {
postId = replyPost.get('id');
}
}
}
if (postId) {
this.set('model.loading', true);
var composer = this;
return Discourse.Post.load(postId).then(function(post) {
var quote = Discourse.Quote.build(post, post.get("raw"))
composer.appendBlockAtCursor(quote);
composer.set('model.loading', false);
});
}
},
cancel: function() {

View File

@@ -328,36 +328,6 @@ Discourse.Composer = Discourse.Model.extend({
Discourse.KeyValueStore.set({ key: 'composer.showPreview', value: this.get('showPreview') });
},
importQuote: function() {
var postStream = this.get('topic.postStream'),
postId = this.get('post.id');
if (!postId && postStream) {
postId = postStream.get('firstPostId');
}
// If we're editing a post, fetch the reply when importing a quote
if (this.get('editingPost')) {
var replyToPostNumber = this.get('post.reply_to_post_number');
if (replyToPostNumber) {
var replyPost = postStream.get('posts').findBy('post_number', replyToPostNumber);
if (replyPost) {
postId = replyPost.get('id');
}
}
}
// If there is no current post, use the post id from the stream
if (postId) {
this.set('loading', true);
var composer = this;
return Discourse.Post.load(postId).then(function(post) {
composer.appendText(Discourse.Quote.build(post, post.get('raw')));
composer.set('loading', false);
});
}
},
/*
Open a composer

View File

@@ -4,7 +4,6 @@ window.PagedownCustom = {
id: 'wmd-quote-post',
description: I18n.t("composer.quote_post_title"),
execute: function() {
// AWFUL but I can't figure out how to call a controller method from outside our app
return Discourse.__container__.lookup('controller:composer').send('importQuote');
}
}