FEATURE: add new 'convert to staff message' in post wrench menu
This commit is contained in:
parent
ffc136e9ac
commit
18f8038015
|
@ -79,6 +79,27 @@ export default ObjectController.extend(ModalFunctionality, {
|
|||
}
|
||||
}.property("viewMode", "wiki_changes"),
|
||||
|
||||
post_type_diff: function () {
|
||||
var viewMode = this.get("viewMode");
|
||||
var changes = this.get("post_type_changes");
|
||||
if (changes === null) { return; }
|
||||
|
||||
var moderator = Discourse.Site.currentProp('post_types.moderator_action');
|
||||
|
||||
if (viewMode === "inline") {
|
||||
var diff = changes["current_post_type"] === moderator ?
|
||||
'<i class="fa fa-shield fa-2x"></i>' :
|
||||
'<span class="fa-stack"><i class="fa fa-shield fa-stack-2x"></i><i class="fa fa-ban fa-stack-2x"></i></span>';
|
||||
return "<div class='inline-diff'>" + diff + "</div>";
|
||||
} else {
|
||||
var prev = changes["previous_post_type"] === moderator ? '<i class="fa fa-shield fa-2x"></i>' : " ";
|
||||
var curr = changes["current_post_type"] === moderator ?
|
||||
'<i class="fa fa-shield fa-2x"></i>' :
|
||||
'<span class="fa-stack"><i class="fa fa-shield fa-stack-2x"></i><i class="fa fa-ban fa-stack-2x"></i></span>';
|
||||
return "<div class='span8'>" + prev + "</div><div class='span8 offset1'>" + curr + "</div>";
|
||||
}
|
||||
}.property("viewMode", "post_type_changes"),
|
||||
|
||||
title_diff: function() {
|
||||
var viewMode = this.get("viewMode");
|
||||
if(viewMode === "side_by_side_markdown") {
|
||||
|
|
|
@ -379,7 +379,20 @@ export default ObjectController.extend(Discourse.SelectedPostsCount, {
|
|||
},
|
||||
|
||||
toggleWiki: function(post) {
|
||||
// the request to the server is made in an observer in the post class
|
||||
post.toggleProperty('wiki');
|
||||
},
|
||||
|
||||
togglePostType: function (post) {
|
||||
// the request to the server is made in an observer in the post class
|
||||
var regular = Discourse.Site.currentProp('post_types.regular'),
|
||||
moderator = Discourse.Site.currentProp('post_types.moderator_action');
|
||||
|
||||
if (post.get("post_type") === moderator) {
|
||||
post.set("post_type", regular);
|
||||
} else {
|
||||
post.set("post_type", moderator);
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
|
|
|
@ -76,23 +76,30 @@ Discourse.Post = Discourse.Model.extend({
|
|||
}.observes('bookmarked'),
|
||||
|
||||
wikiChanged: function() {
|
||||
var self = this;
|
||||
var data = { wiki: this.get("wiki") };
|
||||
this._updatePost("wiki", data);
|
||||
}.observes('wiki'),
|
||||
|
||||
Discourse.ajax('/posts/' + this.get('id') + '/wiki', {
|
||||
type: 'PUT',
|
||||
data: {
|
||||
wiki: this.get('wiki') ? true : false
|
||||
}
|
||||
postTypeChanged: function () {
|
||||
var data = { post_type: this.get("post_type") };
|
||||
this._updatePost("post_type", data);
|
||||
}.observes("post_type"),
|
||||
|
||||
_updatePost: function (field, data) {
|
||||
var self = this;
|
||||
Discourse.ajax("/posts/" + this.get("id") + "/" + field, {
|
||||
type: "PUT",
|
||||
data: data
|
||||
}).then(function () {
|
||||
self.incrementProperty('version');
|
||||
self.incrementProperty("version");
|
||||
}, function (error) {
|
||||
if (error && error.responseText) {
|
||||
bootbox.alert($.parseJSON(error.responseText).errors[0]);
|
||||
} else {
|
||||
bootbox.alert(I18n.t('generic_error'));
|
||||
bootbox.alert(I18n.t("generic_error"));
|
||||
}
|
||||
});
|
||||
}.observes('wiki'),
|
||||
},
|
||||
|
||||
internalLinks: function() {
|
||||
if (this.blank('link_counts')) return null;
|
||||
|
|
|
@ -40,6 +40,11 @@
|
|||
{{{wiki_diff}}}
|
||||
</div>
|
||||
{{/if}}
|
||||
{{#if post_type_changes}}
|
||||
<div class="row">
|
||||
{{{post_type_diff}}}
|
||||
</div>
|
||||
{{/if}}
|
||||
{{{body_diff}}}
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
@ -275,8 +275,24 @@ export default Discourse.View.extend({
|
|||
|
||||
renderAdminPopup: function(post, buffer) {
|
||||
if (!Discourse.User.currentProp('canManageTopic')) { return; }
|
||||
var wikiText = post.get('wiki') ? I18n.t('post.controls.unwiki') : I18n.t('post.controls.wiki');
|
||||
buffer.push('<div class="post-admin-menu"><h3>' + I18n.t('admin_title') + '</h3><ul><li class="btn btn-admin" data-action="toggleWiki"><i class="fa fa-pencil-square-o"></i>' + wikiText +'</li></ul></div>');
|
||||
|
||||
var isWiki = post.get('wiki'),
|
||||
wikiIcon = '<i class="fa fa-pencil-square-o"></i>',
|
||||
wikiText = isWiki ? I18n.t('post.controls.unwiki') : I18n.t('post.controls.wiki');
|
||||
|
||||
var isModerator = post.get('post_type') === Discourse.Site.currentProp('post_types.moderator_action'),
|
||||
postTypeIcon = '<i class="fa fa-shield"></i>',
|
||||
postTypeText = isModerator ? I18n.t('post.controls.revert_to_regular') : I18n.t('post.controls.convert_to_moderator');
|
||||
|
||||
var html = '<div class="post-admin-menu">' +
|
||||
'<h3>' + I18n.t('admin_title') + '</h3>' +
|
||||
'<ul>' +
|
||||
'<li class="btn btn-admin" data-action="toggleWiki">' + wikiIcon + wikiText + '</li>' +
|
||||
'<li class="btn btn-admin" data-action="togglePostType">' + postTypeIcon + postTypeText + '</li>' +
|
||||
'</ul>' +
|
||||
'</div>';
|
||||
|
||||
buffer.push(html);
|
||||
},
|
||||
|
||||
clickAdmin: function() {
|
||||
|
@ -289,6 +305,10 @@ export default Discourse.View.extend({
|
|||
this.get('controller').send('toggleWiki', this.get('post'));
|
||||
},
|
||||
|
||||
clickTogglePostType: function () {
|
||||
this.get("controller").send("togglePostType", this.get("post"));
|
||||
},
|
||||
|
||||
buttonForShowMoreActions: function() {
|
||||
return new Button('showMoreActions', 'show_more', 'ellipsis-h');
|
||||
},
|
||||
|
|
|
@ -241,6 +241,17 @@ class PostsController < ApplicationController
|
|||
render nothing: true
|
||||
end
|
||||
|
||||
def post_type
|
||||
guardian.ensure_can_change_post_type!
|
||||
|
||||
post = find_post_from_params
|
||||
post.post_type = params[:post_type].to_i
|
||||
post.version += 1
|
||||
post.save
|
||||
|
||||
render nothing: true
|
||||
end
|
||||
|
||||
def flagged_posts
|
||||
params.permit(:offset, :limit)
|
||||
guardian.ensure_can_see_flagged_posts!
|
||||
|
|
|
@ -525,7 +525,7 @@ class Post < ActiveRecord::Base
|
|||
end
|
||||
|
||||
def save_revision
|
||||
modifications = changes.extract!(:raw, :cooked, :edit_reason, :user_id, :wiki)
|
||||
modifications = changes.extract!(:raw, :cooked, :edit_reason, :user_id, :wiki, :post_type)
|
||||
# make sure cooked is always present (oneboxes might not change the cooked post)
|
||||
modifications["cooked"] = [self.cooked, self.cooked] unless modifications["cooked"].present?
|
||||
PostRevision.create!(
|
||||
|
|
|
@ -39,6 +39,17 @@ class PostRevision < ActiveRecord::Base
|
|||
}
|
||||
end
|
||||
|
||||
def post_type_changes
|
||||
prev = lookup("post_type", 0)
|
||||
cur = lookup("post_type", 1)
|
||||
return if prev == cur
|
||||
|
||||
{
|
||||
previous_post_type: prev,
|
||||
current_post_type: cur,
|
||||
}
|
||||
end
|
||||
|
||||
def title_changes
|
||||
prev = "<div>#{CGI::escapeHTML(previous("title"))}</div>"
|
||||
cur = "<div>#{CGI::escapeHTML(current("title"))}</div>"
|
||||
|
|
|
@ -11,7 +11,8 @@ class PostRevisionSerializer < ApplicationSerializer
|
|||
:title_changes,
|
||||
:category_changes,
|
||||
:user_changes,
|
||||
:wiki_changes
|
||||
:wiki_changes,
|
||||
:post_type_changes
|
||||
|
||||
def include_title_changes?
|
||||
object.has_topic_data?
|
||||
|
|
|
@ -1105,6 +1105,8 @@ en:
|
|||
admin: "post admin actions"
|
||||
wiki: "Wiki post"
|
||||
unwiki: "Unwiki post"
|
||||
revert_to_regular: "Regular post"
|
||||
convert_to_moderator: "Staff post"
|
||||
|
||||
actions:
|
||||
flag: 'Flag'
|
||||
|
|
|
@ -263,6 +263,7 @@ Discourse::Application.routes.draw do
|
|||
resources :posts do
|
||||
put "bookmark"
|
||||
put "wiki"
|
||||
put "post_type"
|
||||
get "replies"
|
||||
get "revisions/:revision" => "posts#revisions"
|
||||
put "recover"
|
||||
|
|
|
@ -165,6 +165,10 @@ module PostGuardian
|
|||
is_staff? || @user.has_trust_level?(TrustLevel[4])
|
||||
end
|
||||
|
||||
def can_change_post_type?
|
||||
is_staff?
|
||||
end
|
||||
|
||||
def can_see_flagged_posts?
|
||||
is_staff?
|
||||
end
|
||||
|
|
|
@ -70,4 +70,12 @@ describe PostRevision do
|
|||
changes[:current_wiki].should be_true
|
||||
end
|
||||
|
||||
it "can find post_type changes" do
|
||||
r = create_rev("post_type" => [1, 2])
|
||||
|
||||
changes = r.post_type_changes
|
||||
changes[:previous_post_type].should == 1
|
||||
changes[:current_post_type].should == 2
|
||||
end
|
||||
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue