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); }) + "\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() { slackRatio: function() {
return Discourse.Capabilities.currentProp('slackRatio'); return Discourse.Capabilities.currentProp('slackRatio');
}.property(), }.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 Recover a deleted post

View File

@ -74,6 +74,13 @@
</div> </div>
{{/unless}} {{/unless}}
<div class='cooked'>{{{cooked}}}</div> <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"}} {{view Discourse.PostMenuView postBinding="this" postViewBinding="view"}}
</div> </div>
{{view Discourse.RepliesView content=replies postView=view}} {{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'), }.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 // If the cooked content changed, add the quote controls
cookedChanged: function() { cookedChanged: function() {
var self = this; var self = this;

View File

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

View File

@ -891,6 +891,7 @@ en:
reply_as_new_topic: "Reply as new Topic" reply_as_new_topic: "Reply as new Topic"
continue_discussion: "Continuing the discussion from {{postLink}}:" continue_discussion: "Continuing the discussion from {{postLink}}:"
follow_quote: "go to the quoted post" follow_quote: "go to the quoted post"
show_full: "Show Full Post"
deleted_by_author: deleted_by_author:
one: "(post withdrawn by author, will be automatically deleted in %{count} hour unless flagged)" 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)" 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+/} 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" get "raw/:topic_id(/:post_number)" => "posts#markdown"
resources :invites resources :invites