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