discourse/plugins/poll/assets/javascripts/initializers/add-poll-ui-builder.js.es6
Joffrey JAFFEUX 76bc173d47
FEATURE: adds poll_allow_staff_to_create
This setting will bypass poll_minimum_trust_level_to_create if set to true
2017-12-04 18:12:17 +01:00

44 lines
1.2 KiB
JavaScript

import { withPluginApi } from 'discourse/lib/plugin-api';
import computed from 'ember-addons/ember-computed-decorators';
import showModal from 'discourse/lib/show-modal';
function initializePollUIBuilder(api) {
api.modifyClass('controller:composer', {
@computed('siteSettings.poll_enabled',
'siteSettings.poll_minimum_trust_level_to_create',
'siteSettings.poll_allow_staff_to_create')
canBuildPoll(pollEnabled, minimumTrustLevel, allowStaff) {
return pollEnabled &&
this.currentUser &&
(
this.currentUser.admin ||
(this.currentUser.staff && allowStaff) ||
this.currentUser.trust_level >= minimumTrustLevel
);
},
actions: {
showPollBuilder() {
showModal('poll-ui-builder').set('toolbarEvent', this.get('toolbarEvent'));
}
}
});
api.addToolbarPopupMenuOptionsCallback(function() {
return {
action: 'showPollBuilder',
icon: 'bar-chart-o',
label: 'poll.ui_builder.title',
condition: 'canBuildPoll'
};
});
}
export default {
name: 'add-poll-ui-builder',
initialize() {
withPluginApi('0.8.7', initializePollUIBuilder);
}
};