Files
old-csveditor/app/stores/CheckboxStore.js

60 lines
1.1 KiB
JavaScript
Raw Normal View History

2014-10-27 15:28:16 +01:00
var flux = require('flux-react');
var actions = require('./../actions.js');
2014-08-20 19:50:48 +02:00
2014-10-27 15:28:16 +01:00
var CheckboxStore = flux.createStore({
getInitialState: function () {
return {
checkboxes: [{
color: 'red',
checked: false
}, {
color: 'blue',
checked: false
}, {
color: 'green',
checked: false
}]
};
},
actions: [
actions.checkAll,
actions.uncheckAll,
actions.check
],
checkAll: function () {
this.state.checkboxes.forEach(function (checkbox) {
checkbox.checked = true;
});
this.emitChange();
},
uncheckAll: function () {
this.state.checkboxes.forEach(function (checkbox) {
checkbox.checked = false;
2014-08-20 19:50:48 +02:00
});
2014-10-27 15:28:16 +01:00
this.emitChange();
2014-08-20 19:50:48 +02:00
},
2014-10-27 15:28:16 +01:00
check: function (color) {
this.state.checkboxes.forEach(function (checkbox) {
if (checkbox.color === color) {
checkbox.checked = !checkbox.checked;
2014-08-20 19:50:48 +02:00
}
});
2014-10-27 15:28:16 +01:00
this.emitChange();
2014-08-20 19:50:48 +02:00
},
2014-10-27 15:28:16 +01:00
exports: {
getCheckboxes: function () {
return this.checkboxes;
},
getColors: function () {
return this.checkboxes.map(function (checkbox) {
if (checkbox.checked) {
return checkbox.color;
} else {
return 'black';
2014-08-20 19:50:48 +02:00
}
});
}
}
});
module.exports = CheckboxStore;