discourse/plugins/poll/assets/javascripts/initializers/add-poll-ui-builder.js.es6
Jarek Radosz cd4f251891
FEATURE: Poll breakdown 2.0 (#10345)
The poll breakdown modal replaces the grouped pie charts feature.

Includes:

* MODAL: Untangle `onSelectPanel`
Previously modal-tab component would call on click the onSelectPanel callback with itself (modal-tab) as `this` which severely limited its usefulness. Now showModal binds the callback to its controller.

"The PR includes a fix/change to d-modal (b7f6ec6) that hasn't been extracted to a separate PR because it's not currently possible to test a change like this in abstract, i.e. with dynamically created controllers/components in tests. The percentage/count toggle test for the poll breakdown feature is essentially a test for that d-modal modification."
2020-08-06 17:57:06 +02:00

46 lines
1.2 KiB
JavaScript

import { withPluginApi } from "discourse/lib/plugin-api";
import showModal from "discourse/lib/show-modal";
import discourseComputed from "discourse-common/utils/decorators";
function initializePollUIBuilder(api) {
api.modifyClass("controller:composer", {
@discourseComputed(
"siteSettings.poll_enabled",
"siteSettings.poll_minimum_trust_level_to_create",
"model.topic.pm_with_non_human_user"
)
canBuildPoll(pollEnabled, minimumTrustLevel, pmWithNonHumanUser) {
return (
pollEnabled &&
(pmWithNonHumanUser ||
(this.currentUser &&
(this.currentUser.staff ||
this.currentUser.trust_level >= minimumTrustLevel)))
);
},
actions: {
showPollBuilder() {
showModal("poll-ui-builder").set("toolbarEvent", this.toolbarEvent);
}
}
});
api.addToolbarPopupMenuOptionsCallback(() => {
return {
action: "showPollBuilder",
icon: "chart-bar",
label: "poll.ui_builder.title",
condition: "canBuildPoll"
};
});
}
export default {
name: "add-poll-ui-builder",
initialize() {
withPluginApi("0.8.7", initializePollUIBuilder);
}
};