2015-07-08 22:54:07 +02:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
import React from 'react';
|
2015-08-11 17:12:12 +02:00
|
|
|
import Router from 'react-router';
|
2015-07-08 22:54:07 +02:00
|
|
|
|
|
|
|
import PieceActions from '../../actions/piece_actions';
|
|
|
|
import PieceStore from '../../stores/piece_store';
|
|
|
|
|
2015-08-11 17:12:12 +02:00
|
|
|
import PieceListActions from '../../actions/piece_list_actions';
|
|
|
|
import PieceListStore from '../../stores/piece_list_store';
|
|
|
|
|
|
|
|
import UserActions from '../../actions/user_actions';
|
|
|
|
import UserStore from '../../stores/user_store';
|
|
|
|
|
|
|
|
import EditionListActions from '../../actions/edition_list_actions';
|
|
|
|
|
2015-07-08 22:54:07 +02:00
|
|
|
import Piece from './piece';
|
2015-07-15 11:39:08 +02:00
|
|
|
import CollapsibleParagraph from './../ascribe_collapsible/collapsible_paragraph';
|
|
|
|
import FurtherDetails from './further_details';
|
2015-07-08 22:54:07 +02:00
|
|
|
|
2015-08-11 17:12:12 +02:00
|
|
|
import DetailProperty from './detail_property';
|
2015-08-20 15:50:30 +02:00
|
|
|
import HistoryIterator from './history_iterator';
|
2015-08-11 17:12:12 +02:00
|
|
|
|
|
|
|
import AclButtonList from './../ascribe_buttons/acl_button_list';
|
|
|
|
import CreateEditionsForm from '../ascribe_forms/create_editions_form';
|
|
|
|
import CreateEditionsButton from '../ascribe_buttons/create_editions_button';
|
|
|
|
import DeleteButton from '../ascribe_buttons/delete_button';
|
|
|
|
|
2015-08-27 13:43:26 +02:00
|
|
|
import ListRequestActions from '../ascribe_forms/list_form_request_actions';
|
2015-08-21 16:49:04 +02:00
|
|
|
|
2015-08-11 17:12:12 +02:00
|
|
|
import GlobalNotificationModel from '../../models/global_notification_model';
|
|
|
|
import GlobalNotificationActions from '../../actions/global_notification_actions';
|
|
|
|
|
2015-08-21 15:04:38 +02:00
|
|
|
import Note from './note';
|
2015-08-20 14:01:02 +02:00
|
|
|
|
|
|
|
import ApiUrls from '../../constants/api_urls';
|
2015-07-13 15:21:09 +02:00
|
|
|
import AppConstants from '../../constants/application_constants';
|
2015-08-11 17:12:12 +02:00
|
|
|
import { mergeOptions } from '../../utils/general_utils';
|
|
|
|
import { getLangText } from '../../utils/lang_utils';
|
2015-07-13 15:21:09 +02:00
|
|
|
|
2015-07-08 22:54:07 +02:00
|
|
|
/**
|
|
|
|
* This is the component that implements resource/data specific functionality
|
|
|
|
*/
|
|
|
|
let PieceContainer = React.createClass({
|
|
|
|
|
2015-08-11 17:12:12 +02:00
|
|
|
mixins: [Router.Navigation],
|
|
|
|
|
|
|
|
getInitialState() {
|
|
|
|
return mergeOptions(
|
|
|
|
UserStore.getState(),
|
|
|
|
PieceListStore.getState(),
|
|
|
|
PieceStore.getState(),
|
|
|
|
{
|
|
|
|
showCreateEditionsDialog: false
|
|
|
|
}
|
|
|
|
);
|
2015-07-08 22:54:07 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
componentDidMount() {
|
2015-08-11 17:12:12 +02:00
|
|
|
UserStore.listen(this.onChange);
|
|
|
|
PieceListStore.listen(this.onChange);
|
|
|
|
UserActions.fetchCurrentUser();
|
2015-07-08 22:54:07 +02:00
|
|
|
PieceStore.listen(this.onChange);
|
|
|
|
PieceActions.fetchOne(this.props.params.pieceId);
|
|
|
|
},
|
|
|
|
|
|
|
|
componentWillUnmount() {
|
|
|
|
// Every time we're leaving the piece detail page,
|
|
|
|
// just reset the piece that is saved in the piece store
|
|
|
|
// as it will otherwise display wrong/old data once the user loads
|
|
|
|
// the piece detail a second time
|
|
|
|
PieceActions.updatePiece({});
|
|
|
|
PieceStore.unlisten(this.onChange);
|
2015-08-11 17:12:12 +02:00
|
|
|
UserStore.unlisten(this.onChange);
|
|
|
|
PieceListStore.unlisten(this.onChange);
|
2015-07-08 22:54:07 +02:00
|
|
|
},
|
|
|
|
|
2015-08-11 17:12:12 +02:00
|
|
|
onChange(state) {
|
2015-08-26 16:44:24 +02:00
|
|
|
/*
|
|
|
|
|
|
|
|
ATTENTION:
|
|
|
|
THIS IS JUST A TEMPORARY USABILITY FIX THAT ESSENTIALLY REMOVES THE LOAN BUTTON
|
|
|
|
FROM THE PIECE DETAIL PAGE SO THAT USERS DO NOT CONFUSE A PIECE WITH AN EDITION.
|
|
|
|
|
|
|
|
IT SHOULD BE REMOVED AND REPLACED WITH A BETTER SOLUTION ASAP!
|
|
|
|
|
2015-08-28 14:27:02 +02:00
|
|
|
ALSO, WE ENABLED THE LOAN BUTTON FOR IKONOTV TO LET THEM LOAN ON A PIECE LEVEL
|
|
|
|
|
2015-08-26 16:44:24 +02:00
|
|
|
*/
|
2015-08-28 14:07:29 +02:00
|
|
|
if(state && state.piece && state.piece.acl && typeof state.piece.acl.acl_loan !== 'undefined') {
|
2015-08-26 16:44:24 +02:00
|
|
|
|
|
|
|
let pieceState = mergeOptions({}, state.piece);
|
|
|
|
pieceState.acl.acl_loan = false;
|
|
|
|
|
|
|
|
this.setState({
|
|
|
|
piece: pieceState
|
|
|
|
});
|
|
|
|
|
|
|
|
} else {
|
|
|
|
this.setState(state);
|
|
|
|
}
|
2015-08-11 17:12:12 +02:00
|
|
|
},
|
2015-07-08 22:54:07 +02:00
|
|
|
|
|
|
|
loadPiece() {
|
|
|
|
PieceActions.fetchOne(this.props.params.pieceId);
|
|
|
|
},
|
|
|
|
|
2015-08-11 17:12:12 +02:00
|
|
|
|
|
|
|
toggleCreateEditionsDialog() {
|
|
|
|
this.setState({
|
|
|
|
showCreateEditionsDialog: !this.state.showCreateEditionsDialog
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
handleEditionCreationSuccess() {
|
|
|
|
PieceActions.updateProperty({key: 'num_editions', value: 0});
|
|
|
|
PieceListActions.fetchPieceList(this.state.page, this.state.pageSize, this.state.search,
|
|
|
|
this.state.orderBy, this.state.orderAsc, this.state.filterBy);
|
|
|
|
this.toggleCreateEditionsDialog();
|
|
|
|
},
|
|
|
|
|
|
|
|
handleDeleteSuccess(response) {
|
|
|
|
PieceListActions.fetchPieceList(this.state.page, this.state.pageSize, this.state.search,
|
|
|
|
this.state.orderBy, this.state.orderAsc, this.state.filterBy);
|
|
|
|
|
|
|
|
// 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');
|
|
|
|
},
|
|
|
|
|
|
|
|
getCreateEditionsDialog() {
|
|
|
|
if(this.state.piece.num_editions < 1 && this.state.showCreateEditionsDialog) {
|
|
|
|
return (
|
|
|
|
<div style={{marginTop: '1em'}}>
|
|
|
|
<CreateEditionsForm
|
|
|
|
pieceId={this.state.piece.id}
|
|
|
|
handleSuccess={this.handleEditionCreationSuccess} />
|
|
|
|
<hr/>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
return (<hr/>);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
handlePollingSuccess(pieceId, numEditions) {
|
|
|
|
|
|
|
|
// we need to refresh the num_editions property of the actual piece we're looking at
|
|
|
|
PieceActions.updateProperty({
|
|
|
|
key: 'num_editions',
|
|
|
|
value: numEditions
|
|
|
|
});
|
|
|
|
|
|
|
|
// 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, this.state.filterBy);
|
|
|
|
|
|
|
|
let notification = new GlobalNotificationModel('Editions successfully created', 'success', 10000);
|
|
|
|
GlobalNotificationActions.appendGlobalNotification(notification);
|
|
|
|
},
|
|
|
|
|
2015-08-21 15:04:38 +02:00
|
|
|
getId() {
|
|
|
|
return {'id': this.state.piece.id};
|
|
|
|
},
|
|
|
|
|
2015-08-21 16:49:04 +02:00
|
|
|
getActions(){
|
2015-08-24 10:48:40 +02:00
|
|
|
if (this.state.piece &&
|
|
|
|
this.state.piece.request_action &&
|
|
|
|
this.state.piece.request_action.length > 0) {
|
2015-08-21 16:49:04 +02:00
|
|
|
return (
|
2015-08-27 13:43:26 +02:00
|
|
|
<ListRequestActions
|
|
|
|
pieceOrEditions={this.state.piece}
|
2015-08-21 16:49:04 +02:00
|
|
|
currentUser={this.state.currentUser}
|
2015-08-27 13:43:26 +02:00
|
|
|
handleSuccess={this.loadPiece}
|
|
|
|
requestActions={this.state.piece.request_action}/>
|
|
|
|
);
|
2015-08-21 16:49:04 +02:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
return (
|
|
|
|
<AclButtonList
|
|
|
|
className="text-center ascribe-button-list"
|
|
|
|
availableAcls={this.state.piece.acl}
|
|
|
|
editions={this.state.piece}
|
|
|
|
handleSuccess={this.loadPiece}>
|
|
|
|
<CreateEditionsButton
|
|
|
|
label={getLangText('CREATE EDITIONS')}
|
|
|
|
className="btn-sm"
|
|
|
|
piece={this.state.piece}
|
|
|
|
toggleCreateEditionsDialog={this.toggleCreateEditionsDialog}
|
|
|
|
onPollingSuccess={this.handlePollingSuccess}/>
|
|
|
|
<DeleteButton
|
|
|
|
handleSuccess={this.handleDeleteSuccess}
|
|
|
|
piece={this.state.piece}/>
|
|
|
|
</AclButtonList>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
},
|
2015-08-28 12:33:00 +02:00
|
|
|
|
2015-07-08 22:54:07 +02:00
|
|
|
render() {
|
|
|
|
if('title' in this.state.piece) {
|
|
|
|
return (
|
|
|
|
<Piece
|
|
|
|
piece={this.state.piece}
|
2015-08-11 17:12:12 +02:00
|
|
|
loadPiece={this.loadPiece}
|
|
|
|
header={
|
|
|
|
<div className="ascribe-detail-header">
|
2015-08-17 20:52:36 +02:00
|
|
|
<hr style={{marginTop: 0}}/>
|
2015-08-13 14:16:44 +02:00
|
|
|
<h1 className="ascribe-detail-title">{this.state.piece.title}</h1>
|
2015-08-11 17:12:12 +02:00
|
|
|
<DetailProperty label="BY" value={this.state.piece.artist_name} />
|
|
|
|
<DetailProperty label="DATE" value={ this.state.piece.date_created.slice(0, 4) } />
|
|
|
|
{this.state.piece.num_editions > 0 ? <DetailProperty label="EDITIONS" value={ this.state.piece.num_editions } /> : null}
|
|
|
|
<hr/>
|
|
|
|
</div>
|
|
|
|
}
|
|
|
|
subheader={
|
|
|
|
<div className="ascribe-detail-header">
|
|
|
|
<DetailProperty label={getLangText('REGISTREE')} value={ this.state.piece.user_registered } />
|
2015-08-20 14:01:02 +02:00
|
|
|
<DetailProperty label={getLangText('ID')} value={ this.state.piece.bitcoin_id } ellipsis={true} />
|
2015-08-11 17:12:12 +02:00
|
|
|
</div>
|
|
|
|
}
|
2015-08-21 16:49:04 +02:00
|
|
|
buttons={this.getActions()}>
|
2015-08-11 17:12:12 +02:00
|
|
|
{this.getCreateEditionsDialog()}
|
2015-08-20 15:50:30 +02:00
|
|
|
|
|
|
|
<CollapsibleParagraph
|
|
|
|
title={getLangText('Loan History')}
|
|
|
|
show={this.state.piece.loan_history && this.state.piece.loan_history.length > 0}>
|
|
|
|
<HistoryIterator
|
|
|
|
history={this.state.piece.loan_history} />
|
|
|
|
</CollapsibleParagraph>
|
2015-08-21 15:04:38 +02:00
|
|
|
<CollapsibleParagraph
|
2015-08-21 16:38:18 +02:00
|
|
|
title={getLangText('Notes')}
|
2015-08-21 15:04:38 +02:00
|
|
|
show={(this.state.currentUser.username && true || false) ||
|
|
|
|
(this.state.piece.public_note)}>
|
|
|
|
<Note
|
|
|
|
id={this.getId}
|
|
|
|
label={getLangText('Personal note (private)')}
|
|
|
|
defaultValue={this.state.piece.private_note ? this.state.piece.private_note : null}
|
2015-08-21 16:38:18 +02:00
|
|
|
placeholder={getLangText('Enter your comments ...')}
|
2015-08-21 15:04:38 +02:00
|
|
|
editable={true}
|
2015-08-21 16:38:18 +02:00
|
|
|
successMessage={getLangText('Private note saved')}
|
2015-08-21 15:04:38 +02:00
|
|
|
url={ApiUrls.note_private_piece}
|
|
|
|
currentUser={this.state.currentUser}/>
|
|
|
|
</CollapsibleParagraph>
|
2015-07-15 11:39:08 +02:00
|
|
|
<CollapsibleParagraph
|
2015-08-21 16:38:18 +02:00
|
|
|
title={getLangText('Further Details')}
|
2015-07-15 11:39:08 +02:00
|
|
|
show={this.state.piece.acl.acl_edit
|
|
|
|
|| Object.keys(this.state.piece.extra_data).length > 0
|
2015-08-20 11:32:11 +02:00
|
|
|
|| this.state.piece.other_data.length > 0}
|
2015-07-15 11:39:08 +02:00
|
|
|
defaultExpanded={true}>
|
|
|
|
<FurtherDetails
|
|
|
|
editable={this.state.piece.acl.acl_edit}
|
|
|
|
pieceId={this.state.piece.id}
|
|
|
|
extraData={this.state.piece.extra_data}
|
|
|
|
otherData={this.state.piece.other_data}
|
|
|
|
handleSuccess={this.loadPiece}/>
|
|
|
|
</CollapsibleParagraph>
|
2015-08-21 15:04:38 +02:00
|
|
|
|
2015-07-15 11:39:08 +02:00
|
|
|
</Piece>
|
2015-07-08 22:54:07 +02:00
|
|
|
);
|
|
|
|
} else {
|
|
|
|
return (
|
2015-07-13 15:00:12 +02:00
|
|
|
<div className="fullpage-spinner">
|
2015-07-13 15:21:09 +02:00
|
|
|
<img src={AppConstants.baseUrl + 'static/img/ascribe_animated_medium.gif'} />
|
2015-07-13 15:00:12 +02:00
|
|
|
</div>
|
2015-07-08 22:54:07 +02:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
export default PieceContainer;
|