Files
old-csveditor/app/components/Checkboxes.js

60 lines
1.3 KiB
JavaScript
Raw Normal View History

2014-08-20 19:50:48 +02:00
/** @jsx React.DOM */
2014-10-27 15:28:16 +01:00
var React = require('react');
var flux = require('flux-react');
var actions = require('./../actions.js');
2014-08-20 19:50:48 +02:00
var ColoredCheckbox = require('./Checkboxes/ColoredCheckbox.js');
var CheckboxStore = require('../stores/CheckboxStore.js');
var Checkboxes = React.createClass({
stores: [CheckboxStore],
getInitialState: function () {
return {
checkboxes: CheckboxStore.getCheckboxes()
};
},
2014-10-27 15:28:16 +01:00
componentWillMount: function () {
CheckboxStore.addChangeListener(this.update);
},
componentWillUnmount: function () {
CheckboxStore.removeChangeListener(this.update);
},
update: function () {
2014-08-20 19:50:48 +02:00
this.setState({
checkboxes: CheckboxStore.getCheckboxes()
});
},
check: function (color) {
2014-10-27 15:28:16 +01:00
actions.check(color);
2014-08-20 19:50:48 +02:00
},
checkAll: function () {
2014-10-27 15:28:16 +01:00
actions.checkAll();
2014-08-20 19:50:48 +02:00
},
uncheckAll: function () {
2014-10-27 15:28:16 +01:00
actions.uncheckAll();
},
renderCheckbox: function (checkbox, index) {
return <ColoredCheckbox
key={index}
color={checkbox.color}
checked={checkbox.checked}
onChange={this.check}/>
2014-08-20 19:50:48 +02:00
},
render: function() {
2014-10-27 15:28:16 +01:00
var checkboxes = this.state.checkboxes.map(this.renderCheckbox);
2014-08-20 19:50:48 +02:00
return (
<div>
2014-10-27 15:28:16 +01:00
<div>
{checkboxes}
</div>
<div>
<button onClick={this.checkAll}>Check all</button>
<button onClick={this.uncheckAll}>Uncheck all</button>
</div>
2014-08-20 19:50:48 +02:00
</div>
);
}
});
module.exports = Checkboxes;