'use strict'; import React from 'react'; import Router from 'react-router'; import PieceActions from '../../actions/piece_actions'; import PieceStore from '../../stores/piece_store'; 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'; import Piece from './piece'; import CollapsibleParagraph from './../ascribe_collapsible/collapsible_paragraph'; import FurtherDetails from './further_details'; import DetailProperty from './detail_property'; import HistoryIterator from './history_iterator'; 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'; import GlobalNotificationModel from '../../models/global_notification_model'; import GlobalNotificationActions from '../../actions/global_notification_actions'; import Form from '../ascribe_forms/form'; import Property from '../ascribe_forms/property'; import InputTextAreaToggable from '../ascribe_forms/input_textarea_toggable'; import ApiUrls from '../../constants/api_urls'; import AppConstants from '../../constants/application_constants'; import { mergeOptions } from '../../utils/general_utils'; import { getLangText } from '../../utils/lang_utils'; /** * This is the component that implements resource/data specific functionality */ let PieceContainer = React.createClass({ mixins: [Router.Navigation], getInitialState() { return mergeOptions( UserStore.getState(), PieceListStore.getState(), PieceStore.getState(), { showCreateEditionsDialog: false } ); }, componentDidMount() { UserStore.listen(this.onChange); PieceListStore.listen(this.onChange); UserActions.fetchCurrentUser(); 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); UserStore.unlisten(this.onChange); PieceListStore.unlisten(this.onChange); }, onChange(state) { this.setState(state); }, loadPiece() { PieceActions.fetchOne(this.props.params.pieceId); }, 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 (

); } else { return (
); } }, 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); }, render() { if('title' in this.state.piece) { return (

{this.state.piece.title}

{this.state.piece.num_editions > 0 ? : null}
} subheader={
} buttons={ }> {this.getCreateEditionsDialog()} 0}> 0 || this.state.piece.other_data.length > 0} defaultExpanded={true}> { // }
); } else { return (
); } } }); let PersonalNote = React.createClass({ propTypes: { piece: React.PropTypes.object, currentUser: React.PropTypes.object }, showNotification(){ let notification = new GlobalNotificationModel(getLangText('Jury note saved'), 'success'); GlobalNotificationActions.appendGlobalNotification(notification); }, render() { if (this.props.currentUser.username && true || false) { return (

); } return null; } }); export default PieceContainer;