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

View File

@ -3,7 +3,7 @@
import React from 'react'; import React from 'react';
let AccordionListItemTableSelectAllEditionsToggle = React.createClass({ let AccordionListItemTableSelectAllEditionsCheckbox = React.createClass({
propTypes: { propTypes: {
onChange: React.PropTypes.func.isRequired, onChange: React.PropTypes.func.isRequired,
@ -11,13 +11,18 @@ let AccordionListItemTableSelectAllEditionsToggle = React.createClass({
numOfAllEditions: React.PropTypes.number.isRequired numOfAllEditions: React.PropTypes.number.isRequired
}, },
onChange() {
let checked = this.props.numOfAllEditions === this.props.numOfSelectedEditions;
this.props.onChange(checked);
},
render() { render() {
return ( return (
<input type="checkbox" <input type="checkbox"
onChange={this.props.onChange} onChange={this.onChange}
checked={this.props.numOfAllEditions === this.props.numOfSelectedEditions} /> 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; this.editionList[pieceId].orderAsc = orderAsc;
} }
onSelectEdition({pieceId, editionId}) { onSelectEdition({pieceId, editionId, toValue}) {
this.editionList[pieceId].forEach((edition) => { 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) { if(edition.selected) {
edition.selected = false; edition.selected = false;
} else { } else {