mirror of
https://github.com/ascribe/onion.git
synced 2024-11-15 01:25:17 +01:00
select state is saved in the store
This commit is contained in:
parent
ca97bd9af5
commit
92be6a63e8
@ -31,10 +31,10 @@
|
|||||||
.ascribe-table-header-column > span > .glyphicon {
|
.ascribe-table-header-column > span > .glyphicon {
|
||||||
font-size: .5em;
|
font-size: .5em;
|
||||||
}
|
}
|
||||||
|
/*
|
||||||
.ascribe-table-item:nth-child(even) {
|
.ascribe-table-item:nth-child(even) {
|
||||||
background-color: #F5F5F5;
|
background-color: #F5F5F5;
|
||||||
}
|
}*/
|
||||||
|
|
||||||
/*.ascribe-table-item:hover {
|
/*.ascribe-table-item:hover {
|
||||||
background-color: #EEEEEE;
|
background-color: #EEEEEE;
|
||||||
@ -56,3 +56,7 @@
|
|||||||
background-color: rgba(2, 182, 163, 0.5);
|
background-color: rgba(2, 182, 163, 0.5);
|
||||||
border-color: rgba(2, 182, 163, 0.5);
|
border-color: rgba(2, 182, 163, 0.5);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.ascribe-table-item-selected {
|
||||||
|
background-color: rgba(2, 182, 163, 0.5);
|
||||||
|
}
|
@ -5,7 +5,8 @@ import EditionListFetcher from '../fetchers/edition_list_fetcher.js';
|
|||||||
class EditionListActions {
|
class EditionListActions {
|
||||||
constructor() {
|
constructor() {
|
||||||
this.generateActions(
|
this.generateActions(
|
||||||
'updateEditionList'
|
'updateEditionList',
|
||||||
|
'selectEdition'
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -14,7 +15,7 @@ class EditionListActions {
|
|||||||
.fetch(pieceId)
|
.fetch(pieceId)
|
||||||
.then((res) => {
|
.then((res) => {
|
||||||
this.actions.updateEditionList({
|
this.actions.updateEditionList({
|
||||||
'editionList': res.editions,
|
'editionListOfPiece': res.editions,
|
||||||
pieceId
|
pieceId
|
||||||
});
|
});
|
||||||
})
|
})
|
||||||
|
@ -10,7 +10,9 @@ let TableItem = React.createClass({
|
|||||||
|
|
||||||
propTypes: {
|
propTypes: {
|
||||||
columnList: React.PropTypes.arrayOf(React.PropTypes.instanceOf(TableColumnContentModel)),
|
columnList: React.PropTypes.arrayOf(React.PropTypes.instanceOf(TableColumnContentModel)),
|
||||||
columnContent: React.PropTypes.object
|
columnContent: React.PropTypes.object,
|
||||||
|
onClick: React.PropTypes.func, // See: https://facebook.github.io/react/tips/expose-component-functions.html
|
||||||
|
classNames: React.PropTypes.string
|
||||||
},
|
},
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
@ -30,7 +32,9 @@ let TableItem = React.createClass({
|
|||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="col-xs-12 col-sm-12 col-md-12 col-lg-12 ascribe-table-item">
|
<div
|
||||||
|
className={this.props.classNames + ' col-xs-12 col-sm-12 col-md-12 col-lg-12 ascribe-table-item'}
|
||||||
|
onClick={this.props.onClick}>
|
||||||
<div className="row">
|
<div className="row">
|
||||||
{calcColumnElementContent()}
|
{calcColumnElementContent()}
|
||||||
</div>
|
</div>
|
||||||
|
36
js/components/ascribe_table/table_item_selectable.js
Normal file
36
js/components/ascribe_table/table_item_selectable.js
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
import React from 'react';
|
||||||
|
import classNames from 'classnames';
|
||||||
|
|
||||||
|
import TableColumnContentModel from '../../models/table_column_content_model';
|
||||||
|
|
||||||
|
import TableItem from './table_item';
|
||||||
|
|
||||||
|
// This Component is implemented as recommended here: http://stackoverflow.com/a/25723635/1263876
|
||||||
|
let TableItemSelectable = React.createClass({
|
||||||
|
|
||||||
|
propTypes: {
|
||||||
|
parentId: React.PropTypes.number
|
||||||
|
},
|
||||||
|
|
||||||
|
propTypes: {
|
||||||
|
columnList: React.PropTypes.arrayOf(React.PropTypes.instanceOf(TableColumnContentModel)),
|
||||||
|
columnContent: React.PropTypes.object
|
||||||
|
},
|
||||||
|
|
||||||
|
render() {
|
||||||
|
let tableItemClasses = classNames({
|
||||||
|
'ascribe-table-item-selected': this.props.columnContent.selected
|
||||||
|
});
|
||||||
|
let boundSelectItem = this.props.selectItem.bind(this, this.props.parentId, this.props.columnContent.edition_number);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<TableItem classNames={tableItemClasses}
|
||||||
|
columnList={this.props.columnList}
|
||||||
|
columnContent={this.props.columnContent}
|
||||||
|
onClick={boundSelectItem}>
|
||||||
|
</TableItem>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
export default TableItemSelectable;
|
@ -10,7 +10,7 @@ import EditionListActions from '../../actions/edition_list_actions';
|
|||||||
import GeneralUtils from '../../utils/general_utils';
|
import GeneralUtils from '../../utils/general_utils';
|
||||||
|
|
||||||
import Table from './table';
|
import Table from './table';
|
||||||
import TableItem from './table_item';
|
import TableItemSelectable from './table_item_selectable';
|
||||||
import TableItemText from './table_item_text';
|
import TableItemText from './table_item_text';
|
||||||
import TableItemSubtableButton from './table_item_subtable_button';
|
import TableItemSubtableButton from './table_item_subtable_button';
|
||||||
|
|
||||||
@ -50,6 +50,13 @@ let TableItemSubtable = React.createClass({
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
selectItem(parentId, itemId) {
|
||||||
|
EditionListActions.selectEdition({
|
||||||
|
'pieceId': parentId,
|
||||||
|
'editionId': itemId
|
||||||
|
});
|
||||||
|
},
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
|
|
||||||
let calcColumnElementContent = () => {
|
let calcColumnElementContent = () => {
|
||||||
@ -83,9 +90,11 @@ let TableItemSubtable = React.createClass({
|
|||||||
<Table itemList={this.state.editionList[this.props.columnContent.id]} columnList={columnList}>
|
<Table itemList={this.state.editionList[this.props.columnContent.id]} columnList={columnList}>
|
||||||
{this.state.editionList[this.props.columnContent.id].map((edition, i) => {
|
{this.state.editionList[this.props.columnContent.id].map((edition, i) => {
|
||||||
return (
|
return (
|
||||||
<TableItem
|
<TableItemSelectable
|
||||||
|
selectItem={this.selectItem}
|
||||||
|
parentId={this.props.columnContent.id}
|
||||||
key={i}>
|
key={i}>
|
||||||
</TableItem>
|
</TableItemSelectable>
|
||||||
);
|
);
|
||||||
})}
|
})}
|
||||||
</Table>
|
</Table>
|
||||||
|
@ -7,8 +7,22 @@ class EditionListStore {
|
|||||||
this.bindActions(EditionsListActions);
|
this.bindActions(EditionsListActions);
|
||||||
}
|
}
|
||||||
|
|
||||||
onUpdateEditionList({pieceId, editionList}) {
|
onUpdateEditionList({pieceId, editionListOfPiece}) {
|
||||||
this.editionList[pieceId] = editionList;
|
this.editionList[pieceId] = editionListOfPiece;
|
||||||
|
}
|
||||||
|
|
||||||
|
onSelectEdition({pieceId, editionId}) {
|
||||||
|
|
||||||
|
this.editionList[pieceId].forEach((edition) => {
|
||||||
|
if(edition.edition_number === editionId) {
|
||||||
|
if(edition.selected) {
|
||||||
|
edition.selected = false;
|
||||||
|
} else {
|
||||||
|
edition.selected = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user