1
0
mirror of https://github.com/ascribe/onion.git synced 2024-12-22 17:33:14 +01:00

fix minor checkbox bug

This commit is contained in:
Tim Daubenschütz 2015-06-08 14:13:35 +02:00
parent b2241c0551
commit 98d26f5ed7
3 changed files with 21 additions and 12 deletions

View File

@ -9,7 +9,7 @@ import PieceListActions from '../../actions/piece_list_actions';
import AccordionListItemTable from './accordion_list_item_table';
import AccordionListItemTableToggle from './accordion_list_item_table_toggle';
import AccordionListItemTableSelectAllEditionsToggle from './accordion_list_item_table_select_all_editions_toggle';
import AccordionListItemTableSelectAllEditionsCheckbox from './accordion_list_item_table_select_all_editions_checkbox';
import { ColumnModel, TransitionModel } from '../ascribe_table/models/table_models';
@ -46,14 +46,14 @@ let AccordionListItemTableEditions = React.createClass({
this.setState(state);
},
selectItem(pieceId, editionId) {
EditionListActions.selectEdition({pieceId, editionId});
selectItem(pieceId, editionId, toValue) {
EditionListActions.selectEdition({pieceId, editionId, toValue});
},
selectAllItems() {
toggleAllItems(checked) {
this.state.editionList[this.props.parentId]
.forEach((edition) => {
this.selectItem(this.props.parentId, edition.id);
this.selectItem(this.props.parentId, edition.id, !checked);
});
},
@ -100,8 +100,8 @@ let AccordionListItemTableEditions = React.createClass({
'selected': item.selected
}; },
'',
<AccordionListItemTableSelectAllEditionsToggle
onChange={this.selectAllItems}
<AccordionListItemTableSelectAllEditionsCheckbox
onChange={this.toggleAllItems}
numOfSelectedEditions={selectedEditionsCount}
numOfAllEditions={allEditionsCount}/>,
TableItemCheckbox,

View File

@ -3,7 +3,7 @@
import React from 'react';
let AccordionListItemTableSelectAllEditionsToggle = React.createClass({
let AccordionListItemTableSelectAllEditionsCheckbox = React.createClass({
propTypes: {
onChange: React.PropTypes.func.isRequired,
@ -11,13 +11,18 @@ let AccordionListItemTableSelectAllEditionsToggle = React.createClass({
numOfAllEditions: React.PropTypes.number.isRequired
},
onChange() {
let checked = this.props.numOfAllEditions === this.props.numOfSelectedEditions;
this.props.onChange(checked);
},
render() {
return (
<input type="checkbox"
onChange={this.props.onChange}
onChange={this.onChange}
checked={this.props.numOfAllEditions === this.props.numOfSelectedEditions} />
);
}
});
export default AccordionListItemTableSelectAllEditionsToggle;
export default AccordionListItemTableSelectAllEditionsCheckbox;

View File

@ -31,9 +31,13 @@ class EditionListStore {
this.editionList[pieceId].orderAsc = orderAsc;
}
onSelectEdition({pieceId, editionId}) {
onSelectEdition({pieceId, editionId, toValue}) {
this.editionList[pieceId].forEach((edition) => {
if(edition.id === editionId) {
// http://stackoverflow.com/a/519157/1263876
if(typeof toValue !== 'undefined' && edition.id === editionId) {
edition.selected = toValue;
} else if(edition.id === editionId) {
if(edition.selected) {
edition.selected = false;
} else {