1
0
mirror of https://github.com/ascribe/onion.git synced 2024-11-15 09:35:10 +01:00
onion/js/components/ascribe_detail/piece.js

148 lines
5.1 KiB
JavaScript
Raw Normal View History

2015-07-08 22:54:07 +02:00
'use strict';
import React from 'react';
import Row from 'react-bootstrap/lib/Row';
import Col from 'react-bootstrap/lib/Col';
import CollapsibleParagraph from './../ascribe_collapsible/collapsible_paragraph';
import DetailProperty from './detail_property';
2015-07-08 22:54:07 +02:00
import FurtherDetails from './further_details';
2015-07-13 18:13:16 +02:00
import UserActions from '../../actions/user_actions';
import UserStore from '../../stores/user_store';
2015-07-08 22:54:07 +02:00
2015-07-13 18:13:16 +02:00
import PieceActions from '../../actions/piece_actions';
2015-07-08 22:54:07 +02:00
import MediaContainer from './media_container';
2015-07-13 17:09:44 +02:00
import EditionDetailProperty from './detail_property';
2015-07-08 22:54:07 +02:00
import AclButtonList from './../ascribe_buttons/acl_button_list';
2015-07-13 17:09:44 +02:00
import CreateEditionsForm from '../ascribe_forms/create_editions_form';
import CreateEditionsButton from '../ascribe_buttons/create_editions_button';
import { getLangText } from '../../utils/lang_utils';
2015-07-13 17:09:44 +02:00
import { mergeOptions } from '../../utils/general_utils';
2015-07-08 22:54:07 +02:00
/**
* This is the component that implements display-specific functionality
*/
let Piece = React.createClass({
propTypes: {
piece: React.PropTypes.object,
loadPiece: React.PropTypes.func
},
getInitialState() {
2015-07-13 17:09:44 +02:00
return mergeOptions(
UserStore.getState(),
{
showCreateEditionsDialog: false
}
);
},
componentDidMount() {
UserStore.listen(this.onChange);
UserActions.fetchCurrentUser();
},
componentWillUnmount() {
UserStore.unlisten(this.onChange);
},
onChange(state) {
this.setState(state);
},
2015-07-08 22:54:07 +02:00
2015-07-13 17:09:44 +02:00
toggleCreateEditionsDialog() {
this.setState({
showCreateEditionsDialog: !this.state.showCreateEditionsDialog
});
},
2015-07-13 18:13:16 +02:00
handleEditionCreationSuccess() {
PieceActions.updateProperty({key: 'num_editions', value: 0});
this.toggleCreateEditionsDialog();
},
2015-07-13 17:09:44 +02:00
getCreateEditionsDialog() {
if(this.props.piece.num_editions < 1 && this.state.showCreateEditionsDialog) {
return (
<div style={{marginTop: '1em'}}>
<CreateEditionsForm
pieceId={this.props.piece.id}
handleSuccess={this.handleEditionCreationSuccess} />
<hr/>
</div>
);
} else {
return (<hr/>);
}
},
2015-07-08 22:54:07 +02:00
2015-07-13 18:13:16 +02:00
handlePollingSuccess(pieceId, numEditions) {
PieceActions.updateProperty({
key: 'num_editions',
value: numEditions
});
},
2015-07-13 17:09:44 +02:00
render() {
2015-07-08 22:54:07 +02:00
return (
<Row>
<Col md={6}>
<MediaContainer
content={this.props.piece}/>
</Col>
<Col md={6} className="ascribe-edition-details">
2015-07-13 17:09:44 +02:00
<div className="ascribe-detail-header">
<EditionDetailProperty label="TITLE" value={<div className="ascribe-detail-title">{this.props.piece.title}</div>} />
<EditionDetailProperty label="BY" value={this.props.piece.artist_name} />
<EditionDetailProperty label="DATE" value={ this.props.piece.date_created.slice(0, 4) } />
{this.props.piece.num_editions > 0 ? <EditionDetailProperty label="NUMBER OF EDITIONS" value={ this.props.piece.num_editions } /> : null}
<hr/>
</div>
<div className="ascribe-detail-header">
<DetailProperty label={getLangText('REGISTREE')} value={ this.props.piece.user_registered } />
</div>
<AclButtonList
className="text-center ascribe-button-list"
availableAcls={this.props.piece.acl}
2015-07-13 23:57:16 +02:00
editions={this.props.piece}
handleSuccess={this.props.loadPiece}>
2015-07-13 17:09:44 +02:00
<CreateEditionsButton
label={getLangText('CREATE EDITIONS')}
2015-07-13 18:13:16 +02:00
className="btn-sm"
2015-07-13 17:09:44 +02:00
piece={this.props.piece}
2015-07-13 18:13:16 +02:00
toggleCreateEditionsDialog={this.toggleCreateEditionsDialog}
onPollingSuccess={this.handlePollingSuccess}/>
2015-07-13 17:09:44 +02:00
</AclButtonList>
{this.getCreateEditionsDialog()}
2015-07-08 22:54:07 +02:00
<CollapsibleParagraph
title="Further Details"
2015-07-13 20:16:08 +02:00
show={this.props.piece.acl.acl_edit
2015-07-08 22:54:07 +02:00
|| Object.keys(this.props.piece.extra_data).length > 0
|| this.props.piece.other_data !== null}
defaultExpanded={true}>
2015-07-08 22:54:07 +02:00
<FurtherDetails
2015-07-13 20:16:08 +02:00
editable={this.props.piece.acl.acl_edit}
pieceId={this.props.piece.id}
extraData={this.props.piece.extra_data}
otherData={this.props.piece.other_data}
handleSuccess={this.props.loadPiece}/>
2015-07-08 22:54:07 +02:00
</CollapsibleParagraph>
</Col>
</Row>
);
}
});
export default Piece;