2015-04-24 01:33:29 +08:00
|
|
|
export default Em.Component.extend({
|
|
|
|
tagName: "table",
|
|
|
|
classNames: ["results"],
|
|
|
|
|
|
|
|
options: function() {
|
2015-05-04 22:20:13 +08:00
|
|
|
const voters = this.get("poll.voters"),
|
2015-04-24 01:33:29 +08:00
|
|
|
backgroundColor = this.get("poll.background");
|
|
|
|
|
|
|
|
this.get("poll.options").forEach(option => {
|
2015-05-04 22:20:13 +08:00
|
|
|
const percentage = voters === 0 ? 0 : Math.floor(100 * option.get("votes") / voters),
|
2015-04-24 01:33:29 +08:00
|
|
|
styles = ["width: " + percentage + "%"];
|
|
|
|
|
|
|
|
if (backgroundColor) { styles.push("background: " + backgroundColor); }
|
|
|
|
|
|
|
|
option.setProperties({
|
2015-05-06 23:49:55 +08:00
|
|
|
percentage,
|
2015-04-24 01:33:29 +08:00
|
|
|
title: I18n.t("poll.option_title", { count: option.get("votes") }),
|
2015-05-06 23:49:55 +08:00
|
|
|
style: styles.join(";").htmlSafe()
|
2015-04-24 01:33:29 +08:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
return this.get("poll.options");
|
2015-05-04 22:01:57 +08:00
|
|
|
}.property("poll.voters", "poll.options.[]")
|
2015-04-24 01:33:29 +08:00
|
|
|
|
|
|
|
});
|