mirror of
https://github.com/discourse/discourse.git
synced 2025-02-19 18:11:18 +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({
|
export default Ember.Controller.extend({
|
||||||
needs: ['modal', 'topic', 'application'],
|
needs: ['modal', 'topic', 'application'],
|
||||||
replyAsNewTopicDraft: Em.computed.equal('model.draftKey', Composer.REPLY_AS_NEW_TOPIC_KEY),
|
replyAsNewTopicDraft: Em.computed.equal('model.draftKey', Composer.REPLY_AS_NEW_TOPIC_KEY),
|
||||||
@ -56,6 +62,20 @@ export default Ember.Controller.extend({
|
|||||||
topic: null,
|
topic: null,
|
||||||
linkLookup: 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({
|
showToolbar: Em.computed({
|
||||||
get(){
|
get(){
|
||||||
const keyValueStore = this.container.lookup('key-value-store:main');
|
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;
|
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() {
|
showWarning: function() {
|
||||||
if (!Discourse.User.currentProp('staff')) { return false; }
|
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 { preventCloak } from 'discourse/widgets/post-stream';
|
||||||
import { h } from 'virtual-dom';
|
import { h } from 'virtual-dom';
|
||||||
import { addFlagProperty } from 'discourse/components/site-header';
|
import { addFlagProperty } from 'discourse/components/site-header';
|
||||||
|
import { addPopupMenuOptionsCallback } from 'discourse/controllers/composer';
|
||||||
|
|
||||||
class PluginApi {
|
class PluginApi {
|
||||||
constructor(version, container) {
|
constructor(version, container) {
|
||||||
@ -224,6 +225,26 @@ class PluginApi {
|
|||||||
addToolbarCallback(callback);
|
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.
|
* 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
|
* This advanced hook should be used if you end up wiring up any
|
||||||
|
@ -3,9 +3,13 @@
|
|||||||
|
|
||||||
{{#if currentUser.staff}}
|
{{#if currentUser.staff}}
|
||||||
{{#popup-menu visible=optionsVisible hide="hideOptions" title="composer.options"}}
|
{{#popup-menu visible=optionsVisible hide="hideOptions" title="composer.options"}}
|
||||||
<li>
|
{{#each popupMenuOptions as |option|}}
|
||||||
{{d-button action="toggleWhisper" icon="eye-slash" label="composer.toggle_whisper"}}
|
{{#if option.condition}}
|
||||||
</li>
|
<li>
|
||||||
|
{{d-button action=option.action icon=option.icon label=option.label}}
|
||||||
|
</li>
|
||||||
|
{{/if}}
|
||||||
|
{{/each}}
|
||||||
{{/popup-menu}}
|
{{/popup-menu}}
|
||||||
{{/if}}
|
{{/if}}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user