discourse/plugins/poll/assets/javascripts/initializers/add-poll-ui-builder.js.es6

44 lines
1.2 KiB
Plaintext
Raw Normal View History

2016-06-13 18:21:14 +08:00
import { withPluginApi } from 'discourse/lib/plugin-api';
import computed from 'ember-addons/ember-computed-decorators';
2016-06-13 18:21:14 +08:00
import showModal from 'discourse/lib/show-modal';
function initializePollUIBuilder(api) {
2017-06-14 03:52:08 +08:00
api.modifyClass('controller:composer', {
@computed('siteSettings.poll_enabled', 'siteSettings.poll_minimum_trust_level_to_create', 'model.topic.pm_with_non_human_user')
canBuildPoll(pollEnabled, minimumTrustLevel, pmWithNonHumanUser) {
return pollEnabled &&
(
pmWithNonHumanUser ||
this.currentUser &&
(
this.currentUser.staff ||
this.currentUser.trust_level >= minimumTrustLevel
)
);
},
2016-06-13 18:21:14 +08:00
actions: {
showPollBuilder() {
showModal('poll-ui-builder').set('toolbarEvent', this.get('toolbarEvent'));
2016-06-13 18:21:14 +08:00
}
}
});
api.addToolbarPopupMenuOptionsCallback(function() {
return {
action: 'showPollBuilder',
icon: 'bar-chart-o',
label: 'poll.ui_builder.title',
condition: 'canBuildPoll'
2016-06-13 18:21:14 +08:00
};
});
}
export default {
name: 'add-poll-ui-builder',
2016-06-13 18:21:14 +08:00
initialize() {
2017-06-14 03:52:08 +08:00
withPluginApi('0.8.7', initializePollUIBuilder);
2016-06-13 18:21:14 +08:00
}
};