first proof of concept, security still missing
This commit is contained in:
parent
43f40c9825
commit
a4e9ee4552
|
@ -1,5 +1,5 @@
|
||||||
{{#if topic.accepted_answer}}
|
{{#if topic.accepted_answer}}
|
||||||
<p class="solved">
|
<p class="solved">
|
||||||
<i class='fa-check-square fa accepted'></i> Solved by <a data-user-card="{{topic.accepted_answer.username}}">{{topic.accepted_answer.username}}</a> in <a href="{{acceptedAnswerPath}}">post #{{topic.accepted_answer.post_number}}</a>
|
{{{topic.acceptedAnswerHtml}}}
|
||||||
</p>
|
</p>
|
||||||
{{/if}}
|
{{/if}}
|
||||||
|
|
|
@ -2,16 +2,31 @@ import PostMenuView from 'discourse/views/post-menu';
|
||||||
import PostView from 'discourse/views/post';
|
import PostView from 'discourse/views/post';
|
||||||
import { Button } from 'discourse/views/post-menu';
|
import { Button } from 'discourse/views/post-menu';
|
||||||
import Topic from 'discourse/models/topic';
|
import Topic from 'discourse/models/topic';
|
||||||
|
import User from 'discourse/models/user';
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
name: 'extend-for-solved-button',
|
name: 'extend-for-solved-button',
|
||||||
initialize: function() {
|
initialize: function() {
|
||||||
|
|
||||||
Topic.reopen({
|
Topic.reopen({
|
||||||
|
|
||||||
// keeping this here cause there is complex localization
|
// keeping this here cause there is complex localization
|
||||||
acceptedAnswerHtml: function(){
|
acceptedAnswerHtml: function(){
|
||||||
return I18n.t("")
|
var username = this.get('accepted_answer.username');
|
||||||
}.property('accepted_answer')
|
var postNumber = this.get('accepted_answer.post_number');
|
||||||
|
|
||||||
|
if (!username || !postNumber) {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
|
return I18n.t("accepted_answer.accepted_html", {
|
||||||
|
username_lower: username.toLowerCase(),
|
||||||
|
username: username,
|
||||||
|
post_path: this.get('url') + "/" + postNumber,
|
||||||
|
post_number: postNumber,
|
||||||
|
user_path: User.create({username: username}).get('path')
|
||||||
|
});
|
||||||
|
}.property('accepted_answer', 'id')
|
||||||
});
|
});
|
||||||
|
|
||||||
PostView.reopen({
|
PostView.reopen({
|
||||||
|
@ -35,7 +50,8 @@ export default {
|
||||||
clickUnacceptAnswer: function(){
|
clickUnacceptAnswer: function(){
|
||||||
this.set('post.can_accept_answer', true);
|
this.set('post.can_accept_answer', true);
|
||||||
this.set('post.can_unaccept_answer', false);
|
this.set('post.can_unaccept_answer', false);
|
||||||
this.set('post.topic.has_accepted_answer', false);
|
this.set('post.accepted_answer', false);
|
||||||
|
this.set('post.topic.accepted_answer', undefined);
|
||||||
|
|
||||||
Discourse.ajax("/solution/unaccept", {
|
Discourse.ajax("/solution/unaccept", {
|
||||||
type: 'POST',
|
type: 'POST',
|
||||||
|
|
|
@ -0,0 +1,6 @@
|
||||||
|
en:
|
||||||
|
js:
|
||||||
|
accepted_answer:
|
||||||
|
accept_answer: "Accept answer"
|
||||||
|
unaccept_answer: "Unaccept answer"
|
||||||
|
accepted_html: "<i class='fa-check-square fa accepted'></i> Solved by <a href data-user-card='{{username_lower}}'>{{username}}</a> in <a href='{{post_path}}'>post #{{post_number}}</a>"
|
|
@ -22,8 +22,8 @@ after_initialize do
|
||||||
|
|
||||||
post = Post.find(params[:id].to_i)
|
post = Post.find(params[:id].to_i)
|
||||||
|
|
||||||
accepted_id = post.topic.custom_fields["has_accepted_answer"].to_i
|
accepted_id = post.topic.custom_fields["accepted_answer_post_id"].to_i
|
||||||
if accepted_id
|
if accepted_id > 0
|
||||||
if p2 = Post.find_by(id: accepted_id)
|
if p2 = Post.find_by(id: accepted_id)
|
||||||
p2.custom_fields["is_accepted_answer"] = nil
|
p2.custom_fields["is_accepted_answer"] = nil
|
||||||
p2.save!
|
p2.save!
|
||||||
|
|
Loading…
Reference in New Issue