2018-06-15 12:42:20 -04:00
|
|
|
import { withPluginApi } from "discourse/lib/plugin-api";
|
|
|
|
import showModal from "discourse/lib/show-modal";
|
2020-08-06 11:57:06 -04:00
|
|
|
import discourseComputed from "discourse-common/utils/decorators";
|
2016-06-13 06:21:14 -04:00
|
|
|
|
|
|
|
function initializePollUIBuilder(api) {
|
2018-06-15 12:42:20 -04:00
|
|
|
api.modifyClass("controller:composer", {
|
2019-11-13 11:57:42 -05:00
|
|
|
@discourseComputed(
|
2018-06-15 12:42:20 -04:00
|
|
|
"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() {
|
2019-05-27 05:06:11 -04:00
|
|
|
showModal("poll-ui-builder").set("toolbarEvent", this.toolbarEvent);
|
2016-06-13 06:21:14 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2019-01-10 05:06:01 -05:00
|
|
|
api.addToolbarPopupMenuOptionsCallback(() => {
|
2016-06-13 06:21:14 -04:00
|
|
|
return {
|
2018-06-15 12:42:20 -04:00
|
|
|
action: "showPollBuilder",
|
2018-11-26 16:49:57 -05:00
|
|
|
icon: "chart-bar",
|
2018-06-15 12:42:20 -04:00
|
|
|
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
|
|
|
}
|
|
|
|
};
|