2015-07-08 22:54:07 +02:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
import React from 'react';
|
2015-07-14 16:29:01 +02:00
|
|
|
import Router from 'react-router';
|
2015-07-08 22:54:07 +02:00
|
|
|
|
|
|
|
import Row from 'react-bootstrap/lib/Row';
|
|
|
|
import Col from 'react-bootstrap/lib/Col';
|
|
|
|
|
2015-07-10 20:00:35 +02:00
|
|
|
import DetailProperty from './detail_property';
|
|
|
|
|
|
|
|
import UserActions from '../../actions/user_actions';
|
|
|
|
import UserStore from '../../stores/user_store';
|
2015-07-08 22:54:07 +02:00
|
|
|
|
2015-07-14 16:29:01 +02:00
|
|
|
import PieceListActions from '../../actions/piece_list_actions';
|
|
|
|
import PieceListStore from '../../stores/piece_list_store';
|
|
|
|
|
|
|
|
import EditionListActions from '../../actions/edition_list_actions';
|
|
|
|
|
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
|
|
|
|
2015-07-10 20:00:35 +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';
|
2015-07-14 16:29:01 +02:00
|
|
|
import DeleteButton from '../ascribe_buttons/delete_button';
|
2015-07-10 20:00:35 +02:00
|
|
|
|
2015-07-14 13:58:33 +02:00
|
|
|
import GlobalNotificationModel from '../../models/global_notification_model';
|
|
|
|
import GlobalNotificationActions from '../../actions/global_notification_actions';
|
|
|
|
|
2015-07-10 20:00:35 +02:00
|
|
|
import { getLangText } from '../../utils/lang_utils';
|
2015-07-13 17:09:44 +02:00
|
|
|
import { mergeOptions } from '../../utils/general_utils';
|
2015-07-10 20:00:35 +02:00
|
|
|
|
2015-07-15 15:00:39 +02:00
|
|
|
|
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,
|
2015-07-15 15:00:39 +02:00
|
|
|
loadPiece: React.PropTypes.func,
|
|
|
|
children: React.PropTypes.object
|
2015-07-08 22:54:07 +02:00
|
|
|
},
|
|
|
|
|
2015-07-14 16:29:01 +02:00
|
|
|
mixins: [Router.Navigation],
|
|
|
|
|
2015-07-10 20:00:35 +02:00
|
|
|
getInitialState() {
|
2015-07-13 17:09:44 +02:00
|
|
|
return mergeOptions(
|
|
|
|
UserStore.getState(),
|
2015-07-14 16:29:01 +02:00
|
|
|
PieceListStore.getState(),
|
2015-07-13 17:09:44 +02:00
|
|
|
{
|
|
|
|
showCreateEditionsDialog: false
|
|
|
|
}
|
|
|
|
);
|
2015-07-10 20:00:35 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
componentDidMount() {
|
|
|
|
UserStore.listen(this.onChange);
|
2015-07-14 16:29:01 +02:00
|
|
|
PieceListStore.listen(this.onChange);
|
2015-07-10 20:00:35 +02:00
|
|
|
UserActions.fetchCurrentUser();
|
|
|
|
},
|
|
|
|
|
|
|
|
componentWillUnmount() {
|
|
|
|
UserStore.unlisten(this.onChange);
|
2015-07-14 16:29:01 +02:00
|
|
|
PieceListStore.unlisten(this.onChange);
|
2015-07-10 20:00:35 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
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});
|
2015-07-16 11:39:05 +02:00
|
|
|
PieceListActions.fetchPieceList(this.state.page, this.state.pageSize, this.state.search, this.state.orderBy, this.state.orderAsc);
|
2015-07-13 18:13:16 +02:00
|
|
|
this.toggleCreateEditionsDialog();
|
|
|
|
},
|
|
|
|
|
2015-07-14 16:29:01 +02:00
|
|
|
handleDeleteSuccess(response) {
|
|
|
|
PieceListActions.fetchPieceList(this.state.page, this.state.pageSize, this.state.search, this.state.orderBy, this.state.orderAsc);
|
|
|
|
|
|
|
|
// since we're deleting a piece, we just need to close
|
|
|
|
// all editions dialogs and not reload them
|
|
|
|
EditionListActions.closeAllEditionLists();
|
|
|
|
EditionListActions.clearAllEditionSelections();
|
|
|
|
|
|
|
|
let notification = new GlobalNotificationModel(response.notification, 'success');
|
|
|
|
GlobalNotificationActions.appendGlobalNotification(notification);
|
|
|
|
|
|
|
|
this.transitionTo('pieces');
|
|
|
|
},
|
|
|
|
|
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) {
|
2015-07-29 15:24:30 +02:00
|
|
|
|
|
|
|
// we need to refresh the num_editions property of the actual piece we're looking at
|
2015-07-13 18:13:16 +02:00
|
|
|
PieceActions.updateProperty({
|
|
|
|
key: 'num_editions',
|
|
|
|
value: numEditions
|
|
|
|
});
|
2015-07-14 13:58:33 +02:00
|
|
|
|
2015-07-29 15:24:30 +02:00
|
|
|
// as well as its representation in the collection
|
|
|
|
// btw.: It's not sufficient to just set num_editions to numEditions, since a single accordion
|
|
|
|
// list item also uses the firstEdition property which we can only get from the server in that case.
|
|
|
|
// Therefore we need to at least refetch the changed piece from the server or on our case simply all
|
|
|
|
PieceListActions.fetchPieceList(this.state.page, this.state.pageSize, this.state.search, this.state.orderBy, this.state.orderAsc);
|
|
|
|
|
2015-07-14 13:58:33 +02:00
|
|
|
let notification = new GlobalNotificationModel('Editions successfully created', 'success', 10000);
|
|
|
|
GlobalNotificationActions.appendGlobalNotification(notification);
|
2015-07-13 18:13:16 +02:00
|
|
|
},
|
|
|
|
|
2015-07-13 17:09:44 +02:00
|
|
|
render() {
|
2015-07-08 22:54:07 +02:00
|
|
|
return (
|
|
|
|
<Row>
|
|
|
|
<Col md={6}>
|
|
|
|
<MediaContainer
|
2015-07-15 11:47:14 +02:00
|
|
|
content={this.props.piece}/>
|
2015-07-08 22:54:07 +02:00
|
|
|
</Col>
|
|
|
|
<Col md={6} className="ascribe-edition-details">
|
2015-07-13 17:09:44 +02:00
|
|
|
<div className="ascribe-detail-header">
|
2015-07-27 18:19:55 +02:00
|
|
|
<h1 className="ascribe-detail-title">{this.props.piece.title}</h1>
|
|
|
|
<hr/>
|
2015-07-13 17:09:44 +02:00
|
|
|
<EditionDetailProperty label="BY" value={this.props.piece.artist_name} />
|
|
|
|
<EditionDetailProperty label="DATE" value={ this.props.piece.date_created.slice(0, 4) } />
|
2015-07-15 12:23:02 +02:00
|
|
|
{this.props.piece.num_editions > 0 ? <EditionDetailProperty label="EDITIONS" value={ this.props.piece.num_editions } /> : null}
|
2015-07-13 17:09:44 +02:00
|
|
|
<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
|
2015-07-13 18:52:55 +02:00
|
|
|
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-14 16:29:01 +02:00
|
|
|
<DeleteButton
|
|
|
|
handleSuccess={this.handleDeleteSuccess}
|
|
|
|
piece={this.props.piece}/>
|
2015-07-13 17:09:44 +02:00
|
|
|
</AclButtonList>
|
|
|
|
|
|
|
|
{this.getCreateEditionsDialog()}
|
2015-07-15 15:00:39 +02:00
|
|
|
{this.props.children}
|
2015-07-13 17:09:44 +02:00
|
|
|
|
2015-07-08 22:54:07 +02:00
|
|
|
</Col>
|
|
|
|
</Row>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
export default Piece;
|