2016-06-13 18:21:14 +08:00
|
|
|
import { withPluginApi } from 'discourse/lib/plugin-api';
|
2017-12-04 21:47:11 +08:00
|
|
|
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', {
|
2017-12-05 01:12:17 +08:00
|
|
|
@computed('siteSettings.poll_enabled',
|
|
|
|
'siteSettings.poll_minimum_trust_level_to_create',
|
|
|
|
'siteSettings.poll_allow_staff_to_create')
|
|
|
|
canBuildPoll(pollEnabled, minimumTrustLevel, allowStaff) {
|
2017-12-04 21:47:11 +08:00
|
|
|
return pollEnabled &&
|
|
|
|
this.currentUser &&
|
|
|
|
(
|
|
|
|
this.currentUser.admin ||
|
2017-12-05 01:12:17 +08:00
|
|
|
(this.currentUser.staff && allowStaff) ||
|
|
|
|
this.currentUser.trust_level >= minimumTrustLevel
|
2017-12-04 21:47:11 +08:00
|
|
|
);
|
|
|
|
},
|
|
|
|
|
2016-06-13 18:21:14 +08:00
|
|
|
actions: {
|
|
|
|
showPollBuilder() {
|
2017-12-04 21:47:11 +08:00
|
|
|
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',
|
2017-12-04 21:47:11 +08:00
|
|
|
label: 'poll.ui_builder.title',
|
|
|
|
condition: 'canBuildPoll'
|
2016-06-13 18:21:14 +08:00
|
|
|
};
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
export default {
|
2017-12-04 21:47:11 +08:00
|
|
|
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
|
|
|
}
|
|
|
|
};
|