diff --git a/js/components/ascribe_accordion_list/accordion_list_item_table_editions.js b/js/components/ascribe_accordion_list/accordion_list_item_table_editions.js index c975500e..9b843372 100644 --- a/js/components/ascribe_accordion_list/accordion_list_item_table_editions.js +++ b/js/components/ascribe_accordion_list/accordion_list_item_table_editions.js @@ -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 }; }, '', - , TableItemCheckbox, diff --git a/js/components/ascribe_accordion_list/accordion_list_item_table_select_all_editions_toggle.js b/js/components/ascribe_accordion_list/accordion_list_item_table_select_all_editions_checkbox.js similarity index 56% rename from js/components/ascribe_accordion_list/accordion_list_item_table_select_all_editions_toggle.js rename to js/components/ascribe_accordion_list/accordion_list_item_table_select_all_editions_checkbox.js index 0fe71c35..26433497 100644 --- a/js/components/ascribe_accordion_list/accordion_list_item_table_select_all_editions_toggle.js +++ b/js/components/ascribe_accordion_list/accordion_list_item_table_select_all_editions_checkbox.js @@ -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 ( ); } }); -export default AccordionListItemTableSelectAllEditionsToggle; \ No newline at end of file +export default AccordionListItemTableSelectAllEditionsCheckbox; \ No newline at end of file diff --git a/js/stores/edition_list_store.js b/js/stores/edition_list_store.js index 67993ff9..092e498e 100644 --- a/js/stores/edition_list_store.js +++ b/js/stores/edition_list_store.js @@ -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 {