2016-04-22 05:30:54 +08:00
|
|
|
import React from 'react';
|
2016-04-23 05:19:20 +08:00
|
|
|
import { Button } from '../shared/Button.jsx';
|
2016-04-22 05:30:54 +08:00
|
|
|
|
2016-04-23 05:19:20 +08:00
|
|
|
export let Polling = React.createClass({
|
2016-03-12 07:09:59 +08:00
|
|
|
//#TODO Move this to parent later?
|
|
|
|
mixins: [ReactMeteorData],
|
|
|
|
getMeteorData() {
|
|
|
|
let poll;
|
|
|
|
poll = BBB.getCurrentPoll(getInSession('userId'));
|
|
|
|
return {
|
2016-04-23 07:19:17 +08:00
|
|
|
poll: poll,
|
2016-03-12 07:09:59 +08:00
|
|
|
};
|
|
|
|
},
|
2016-04-23 07:19:17 +08:00
|
|
|
|
|
|
|
componentDidMount: function () {
|
2016-03-12 07:09:59 +08:00
|
|
|
return scaleWhiteboard();
|
|
|
|
},
|
|
|
|
|
2016-04-23 07:19:17 +08:00
|
|
|
componentWillUnmount: function () {
|
2016-03-12 07:09:59 +08:00
|
|
|
setTimeout(scaleWhiteboard, 0);
|
|
|
|
},
|
|
|
|
|
|
|
|
getStyledAnswers(poll) {
|
2016-04-23 07:19:17 +08:00
|
|
|
let number, buttonStyle, answers;
|
|
|
|
if (poll != null) {
|
2016-03-12 07:09:59 +08:00
|
|
|
number = poll.poll_info.poll.answers.length;
|
|
|
|
buttonStyle = {
|
|
|
|
width: 'calc(75%/' + number + ')',
|
|
|
|
marginLeft: 'calc(25%/' + number * 2 + ')',
|
2016-04-23 07:19:17 +08:00
|
|
|
marginRight: 'calc(25%/ ' + number * 2 + ')',
|
2016-03-12 07:09:59 +08:00
|
|
|
};
|
|
|
|
answers = poll.poll_info.poll.answers;
|
2016-04-23 07:19:17 +08:00
|
|
|
for (j = 0; j < number; j++) {
|
2016-03-12 07:09:59 +08:00
|
|
|
answers[j].style = buttonStyle;
|
|
|
|
}
|
2016-04-23 07:19:17 +08:00
|
|
|
|
|
|
|
return answers;
|
2016-03-12 07:09:59 +08:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2016-04-23 07:19:17 +08:00
|
|
|
handleClick: function (label, answer) {
|
2016-03-12 07:09:59 +08:00
|
|
|
return BBB.sendPollResponseMessage(label, answer);
|
|
|
|
},
|
|
|
|
|
2016-04-23 07:19:17 +08:00
|
|
|
render() {
|
2016-03-12 07:09:59 +08:00
|
|
|
return (
|
2016-04-23 07:19:17 +08:00
|
|
|
<div className="polling">
|
2016-04-21 00:08:23 +08:00
|
|
|
{this.data.poll ? this.getStyledAnswers(this.data.poll).map((question) =>
|
2016-03-13 08:27:29 +08:00
|
|
|
<Button onClick={this.handleClick.bind(null, question.key, question.id)} btn_class=" pollButtons" rel="tooltip" data_placement="top"
|
|
|
|
label={question.key} style={question.style} key={question.id}/>
|
2016-04-23 07:19:17 +08:00
|
|
|
) : null }
|
2016-03-12 07:09:59 +08:00
|
|
|
</div>
|
2016-04-23 07:19:17 +08:00
|
|
|
);
|
|
|
|
},
|
2016-03-12 07:09:59 +08:00
|
|
|
});
|