mirror of
https://github.com/discourse/discourse.git
synced 2025-02-17 00:35:50 +00:00
FEATURE: Add new API to add a toolbar popup menu button.
This commit is contained in:
parent
b42f28d4c3
commit
5813352439
@ -42,6 +42,12 @@ function loadDraft(store, opts) {
|
||||
}
|
||||
}
|
||||
|
||||
const _popupMenuOptionsCallbacks = [];
|
||||
|
||||
export function addPopupMenuOptionsCallback(callback) {
|
||||
_popupMenuOptionsCallbacks.push(callback);
|
||||
}
|
||||
|
||||
export default Ember.Controller.extend({
|
||||
needs: ['modal', 'topic', 'application'],
|
||||
replyAsNewTopicDraft: Em.computed.equal('model.draftKey', Composer.REPLY_AS_NEW_TOPIC_KEY),
|
||||
@ -56,6 +62,20 @@ export default Ember.Controller.extend({
|
||||
topic: null,
|
||||
linkLookup: null,
|
||||
|
||||
init() {
|
||||
this._super();
|
||||
const self = this
|
||||
|
||||
addPopupMenuOptionsCallback(function() {
|
||||
return {
|
||||
action: 'toggleWhisper',
|
||||
icon: 'eye-slash',
|
||||
label: 'composer.toggle_whisper',
|
||||
condition: "canWhisper"
|
||||
};
|
||||
});
|
||||
},
|
||||
|
||||
showToolbar: Em.computed({
|
||||
get(){
|
||||
const keyValueStore = this.container.lookup('key-value-store:main');
|
||||
@ -92,6 +112,25 @@ export default Ember.Controller.extend({
|
||||
return currentUser && currentUser.get('staff') && this.siteSettings.enable_whispers && action === Composer.REPLY;
|
||||
},
|
||||
|
||||
@computed("model.composeState")
|
||||
popupMenuOptions(composeState) {
|
||||
const self = this;
|
||||
|
||||
if (composeState === 'open') {
|
||||
return _popupMenuOptionsCallbacks.map(callback => {
|
||||
let option = callback();
|
||||
|
||||
if (option.condition) {
|
||||
option.condition = self.get(option.condition);
|
||||
} else {
|
||||
option.condition = true;
|
||||
}
|
||||
|
||||
return option;
|
||||
});
|
||||
}
|
||||
},
|
||||
|
||||
showWarning: function() {
|
||||
if (!Discourse.User.currentProp('staff')) { return false; }
|
||||
|
||||
|
@ -10,6 +10,7 @@ import { onPageChange } from 'discourse/lib/page-tracker';
|
||||
import { preventCloak } from 'discourse/widgets/post-stream';
|
||||
import { h } from 'virtual-dom';
|
||||
import { addFlagProperty } from 'discourse/components/site-header';
|
||||
import { addPopupMenuOptionsCallback } from 'discourse/controllers/composer';
|
||||
|
||||
class PluginApi {
|
||||
constructor(version, container) {
|
||||
@ -224,6 +225,26 @@ class PluginApi {
|
||||
addToolbarCallback(callback);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a new button in the options popup menu.
|
||||
*
|
||||
* Example:
|
||||
*
|
||||
* ```
|
||||
* api.addToolbarPopupMenuOptionsCallback(function(controller) {
|
||||
* return {
|
||||
* action: 'toggleWhisper',
|
||||
* icon: 'eye-slash',
|
||||
* label: 'composer.toggle_whisper',
|
||||
* condition: "canWhisper"
|
||||
* };
|
||||
* });
|
||||
* ```
|
||||
**/
|
||||
addToolbarPopupMenuOptionsCallback(callback) {
|
||||
addPopupMenuOptionsCallback(callback);
|
||||
}
|
||||
|
||||
/**
|
||||
* A hook that is called when the post stream is removed from the DOM.
|
||||
* This advanced hook should be used if you end up wiring up any
|
||||
|
@ -3,9 +3,13 @@
|
||||
|
||||
{{#if currentUser.staff}}
|
||||
{{#popup-menu visible=optionsVisible hide="hideOptions" title="composer.options"}}
|
||||
<li>
|
||||
{{d-button action="toggleWhisper" icon="eye-slash" label="composer.toggle_whisper"}}
|
||||
</li>
|
||||
{{#each popupMenuOptions as |option|}}
|
||||
{{#if option.condition}}
|
||||
<li>
|
||||
{{d-button action=option.action icon=option.icon label=option.label}}
|
||||
</li>
|
||||
{{/if}}
|
||||
{{/each}}
|
||||
{{/popup-menu}}
|
||||
{{/if}}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user