Merge pull request #4347 from tgxworld/unlist_topic_creation

FEATURE: Add toggle topic visibility button in popup menu.
This commit is contained in:
Guo Xiang Tan 2016-07-28 17:18:34 +08:00 committed by GitHub
commit c449bbe882
7 changed files with 107 additions and 11 deletions

View File

@ -63,6 +63,7 @@ export default Ember.Controller.extend({
isUploading: false, isUploading: false,
topic: null, topic: null,
linkLookup: null, linkLookup: null,
whisperOrUnlistTopic: Ember.computed.or('model.whisper', 'model.unlistTopic'),
@computed('model.replyingToTopic', 'model.creatingPrivateMessage', 'model.targetUsernames') @computed('model.replyingToTopic', 'model.creatingPrivateMessage', 'model.targetUsernames')
focusTarget(replyingToTopic, creatingPM, usernames) { focusTarget(replyingToTopic, creatingPM, usernames) {
@ -109,10 +110,26 @@ export default Ember.Controller.extend({
!creatingPrivateMessage; !creatingPrivateMessage;
}, },
@computed('model.action') @computed('model.whisper', 'model.unlistTopic')
canWhisper(action) { whisperOrUnlistTopicText(whisper, unlistTopic) {
if (whisper) {
return I18n.t("composer.whisper");
} else if (unlistTopic) {
return I18n.t("composer.unlist");
}
},
@computed
isStaffUser() {
const currentUser = this.currentUser; const currentUser = this.currentUser;
return currentUser && currentUser.get('staff') && this.siteSettings.enable_whispers && action === Composer.REPLY; return currentUser && currentUser.get('staff');
},
canUnlistTopic: Em.computed.and('model.creatingTopic', 'isStaffUser'),
@computed('model.action', 'isStaffUser')
canWhisper(action, isStaffUser) {
return isStaffUser && this.siteSettings.enable_whispers && action === Composer.REPLY;
}, },
@computed("popupMenuOptions") @computed("popupMenuOptions")
@ -132,11 +149,20 @@ export default Ember.Controller.extend({
return option; return option;
}, },
@computed("model.composeState") @computed("model.composeState", "model.creatingTopic")
popupMenuOptions(composeState) { popupMenuOptions(composeState) {
if (composeState === 'open') { if (composeState === 'open') {
let options = []; let options = [];
options.push(this._setupPopupMenuOption(() => {
return {
action: 'toggleInvisible',
icon: 'eye-slash',
label: 'composer.toggle_unlisted',
condition: "canUnlistTopic"
};
}));
options.push(this._setupPopupMenuOption(() => { options.push(this._setupPopupMenuOption(() => {
return { return {
action: 'toggleWhisper', action: 'toggleWhisper',
@ -210,6 +236,10 @@ export default Ember.Controller.extend({
this.toggleProperty('model.whisper'); this.toggleProperty('model.whisper');
}, },
toggleInvisible() {
this.toggleProperty('model.unlistTopic');
},
toggleToolbar() { toggleToolbar() {
this.toggleProperty('showToolbar'); this.toggleProperty('showToolbar');
}, },
@ -503,7 +533,6 @@ export default Ember.Controller.extend({
this.set('scopedCategoryId', opts.categoryId); this.set('scopedCategoryId', opts.categoryId);
} }
this.setProperties({ showEditReason: false, editReason: null }); this.setProperties({ showEditReason: false, editReason: null });
// If we want a different draft than the current composer, close it and clear our model. // If we want a different draft than the current composer, close it and clear our model.
@ -545,6 +574,12 @@ export default Ember.Controller.extend({
}).then(resolve, reject); }).then(resolve, reject);
} }
if (composerModel) {
if (composerModel.get('action') !== opts.action) {
composerModel.setProperties({ unlistTopic: false, whisper: false });
}
}
self._setModel(composerModel, opts); self._setModel(composerModel, opts);
resolve(); resolve();
}); });

View File

@ -22,6 +22,7 @@ const CLOSED = 'closed',
_create_serializer = { _create_serializer = {
raw: 'reply', raw: 'reply',
title: 'title', title: 'title',
unlist_topic: 'unlistTopic',
category: 'categoryId', category: 'categoryId',
topic_id: 'topic.id', topic_id: 'topic.id',
is_warning: 'isWarning', is_warning: 'isWarning',
@ -41,6 +42,7 @@ const CLOSED = 'closed',
const Composer = RestModel.extend({ const Composer = RestModel.extend({
_categoryId: null, _categoryId: null,
unlistTopic: false,
archetypes: function() { archetypes: function() {
return this.site.get('archetypes'); return this.site.get('archetypes');
@ -504,6 +506,7 @@ const Composer = RestModel.extend({
reply: null, reply: null,
post: null, post: null,
title: null, title: null,
unlistTopic: false,
editReason: null, editReason: null,
stagedPost: false, stagedPost: false,
typingTime: 0, typingTime: 0,

View File

@ -29,8 +29,8 @@
<div class='reply-to'> <div class='reply-to'>
{{{model.actionTitle}}} {{{model.actionTitle}}}
{{#unless site.mobileView}} {{#unless site.mobileView}}
{{#if model.whisper}} {{#if whisperOrUnlistTopicText}}
<span class='whisper'>({{i18n "composer.whisper"}})</span> <span class='whisper'>({{whisperOrUnlistTopicText}})</span>
{{/if}} {{/if}}
{{/unless}} {{/unless}}
@ -106,8 +106,8 @@
<a href {{action "cancel"}} class='cancel' tabindex="6">{{i18n 'cancel'}}</a> <a href {{action "cancel"}} class='cancel' tabindex="6">{{i18n 'cancel'}}</a>
{{#if site.mobileView}} {{#if site.mobileView}}
{{#if model.whisper}} {{#if whisperOrUnlistTopic}}
<span class='whisper'><i class='fa fa-eye-slash'></i></span> <span class='whisper'><i class='fa fa-eye-slash'></i></span>
{{/if}} {{/if}}
{{/if}} {{/if}}
</div> </div>

View File

@ -554,10 +554,12 @@ class PostsController < ApplicationController
:auto_track, :auto_track,
:typing_duration_msecs, :typing_duration_msecs,
:composer_open_duration_msecs, :composer_open_duration_msecs,
:visible
] ]
# param munging for WordPress # param munging for WordPress
params[:auto_track] = !(params[:auto_track].to_s == "false") if params[:auto_track] params[:auto_track] = !(params[:auto_track].to_s == "false") if params[:auto_track]
params[:visible] = (params[:unlist_topic].to_s == "false") if params[:unlist_topic]
if api_key_valid? if api_key_valid?
# php seems to be sending this incorrectly, don't fight with it # php seems to be sending this incorrectly, don't fight with it

View File

@ -1016,9 +1016,11 @@ en:
more_emoji: "more..." more_emoji: "more..."
options: "Options" options: "Options"
whisper: "whisper" whisper: "whisper"
unlist: "unlisted"
add_warning: "This is an official warning." add_warning: "This is an official warning."
toggle_whisper: "Toggle Whisper" toggle_whisper: "Toggle Whisper"
toggle_unlisted: "Toggle Unlisted"
posting_not_on_topic: "Which topic do you want to reply to?" posting_not_on_topic: "Which topic do you want to reply to?"
saving_draft_tip: "saving..." saving_draft_tip: "saving..."
saved_draft_tip: "saved" saved_draft_tip: "saved"

View File

@ -93,10 +93,13 @@ class TopicCreator
end end
def setup_topic_params def setup_topic_params
@opts[:visible] = true if @opts[:visible].nil?
topic_params = { topic_params = {
title: @opts[:title], title: @opts[:title],
user_id: @user.id, user_id: @user.id,
last_post_user_id: @user.id last_post_user_id: @user.id,
visible: @opts[:visible]
} }
[:subtype, :archetype, :meta_data, :import_mode].each do |key| [:subtype, :archetype, :meta_data, :import_mode].each do |key|

View File

@ -1,6 +1,11 @@
import { acceptance } from "helpers/qunit-helpers"; import { acceptance } from "helpers/qunit-helpers";
acceptance("Composer", { loggedIn: true }); acceptance("Composer", {
loggedIn: true,
settings: {
enable_whispers: true
}
});
test("Tests the Composer controls", () => { test("Tests the Composer controls", () => {
visit("/"); visit("/");
@ -254,6 +259,52 @@ test("Composer can toggle between edit and reply", () => {
}); });
}); });
test("Composer can toggle between reply and createTopic", () => {
visit("/t/this-is-a-test-topic/9");
click('.topic-post:eq(0) button.reply');
click('button.options');
click('.popup-menu .fa-eye-slash');
andThen(() => {
ok(
find('.composer-fields .whisper').text().indexOf(I18n.t("composer.whisper")) > 0,
'it sets the post type to whisper'
);
});
visit("/");
andThen(() => {
ok(exists('#create-topic'), 'the create topic button is visible');
});
click('#create-topic');
andThen(() => {
ok(
find('.composer-fields .whisper').text().indexOf(I18n.t("composer.whisper")) === -1,
"it should reset the state of the composer's model"
);
});
click('button.options');
click('.popup-menu .fa-eye-slash');
andThen(() => {
ok(
find('.composer-fields .whisper').text().indexOf(I18n.t("composer.unlist")) > 0,
'it sets the topic to unlisted'
);
});
visit("/t/this-is-a-test-topic/9");
click('.topic-post:eq(0) button.reply');
andThen(() => {
ok(
find('.composer-fields .whisper').text().indexOf(I18n.t("composer.unlist")) === -1,
"it should reset the state of the composer's model"
);
});
});
test("Composer with dirty reply can toggle to edit", () => { test("Composer with dirty reply can toggle to edit", () => {
visit("/t/this-is-a-test-topic/9"); visit("/t/this-is-a-test-topic/9");