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