Interface for expanding OP contents

This commit is contained in:
Robin Ward 2014-04-01 17:45:16 -04:00
parent f5c7ccb4e6
commit 50fb048b99
7 changed files with 46 additions and 1 deletions

View file

@ -216,10 +216,24 @@ Discourse.TopicController = Discourse.ObjectController.extend(Discourse.Selected
}) + "\n\n" + q);
});
});
}
},
expandFirstPost: function(post) {
var self = this;
this.set('loadingExpanded', true);
post.expand().then(function() {
self.set('firstPostExpanded', true);
}).finally(function() {
self.set('loadingExpanded', false);
});
}
},
showExpandButton: function() {
var post = this.get('post');
return post.get('post_number') === 1 && post.get('topic.expandable_first_post');
}.property(),
slackRatio: function() {
return Discourse.Capabilities.currentProp('slackRatio');
}.property(),

View file

@ -176,6 +176,17 @@ Discourse.Post = Discourse.Model.extend({
}
},
/**
Expands the first post's content, if embedded and shortened.
@method expandFirstPost
**/
expand: function() {
var self = this;
return Discourse.ajax("/posts/" + this.get('id') + "/expand-embed").then(function(result) {
self.set('cooked', result.cooked);
});
},
/**
Recover a deleted post

View file

@ -74,6 +74,13 @@
</div>
{{/unless}}
<div class='cooked'>{{{cooked}}}</div>
{{#if view.showExpandButton}}
{{#if controller.loadingExpanded}}
<button class="btn" disabled>{{i18n loading}}</button>
{{else}}
<button {{action expandFirstPost this}} class='btn'>{{i18n post.show_full}}</button>
{{/if}}
{{/if}}
{{view Discourse.PostMenuView postBinding="this" postViewBinding="view"}}
</div>
{{view Discourse.RepliesView content=replies postView=view}}

View file

@ -27,6 +27,13 @@ Discourse.PostView = Discourse.GroupedView.extend(Ember.Evented, {
}
}.property('post.primary_group_name'),
showExpandButton: function() {
if (this.get('controller.firstPostExpanded')) { return false; }
var post = this.get('post');
return post.get('post_number') === 1 && post.get('topic.expandable_first_post');
}.property('post.post_number', 'controller.firstPostExpanded'),
// If the cooked content changed, add the quote controls
cookedChanged: function() {
var self = this;

View file

@ -143,6 +143,10 @@ class PostsController < ApplicationController
render nothing: true
end
def expand_embed
render json: {cooked: "NEW COOKED CONTENT"}
end
def recover
post = find_post_from_params
guardian.ensure_can_recover_post!(post)

View file

@ -891,6 +891,7 @@ en:
reply_as_new_topic: "Reply as new Topic"
continue_discussion: "Continuing the discussion from {{postLink}}:"
follow_quote: "go to the quoted post"
show_full: "Show Full Post"
deleted_by_author:
one: "(post withdrawn by author, will be automatically deleted in %{count} hour unless flagged)"
other: "(post withdrawn by author, will be automatically deleted in %{count} hours unless flagged)"

View file

@ -335,6 +335,7 @@ Discourse::Application.routes.draw do
post "t/:topic_id/notifications" => "topics#set_notifications" , constraints: {topic_id: /\d+/}
get "/posts/:id/expand-embed" => "posts#expand_embed"
get "raw/:topic_id(/:post_number)" => "posts#markdown"
resources :invites