'use strict'; import React from 'react'; import Moment from 'moment'; import Glyphicon from 'react-bootstrap/lib/Glyphicon'; import OverlayTrigger from 'react-bootstrap/lib/OverlayTrigger'; import Tooltip from 'react-bootstrap/lib/Tooltip'; import EditionListActions from '../../actions/edition_list_actions'; import GlobalNotificationModel from '../../models/global_notification_model'; import GlobalNotificationActions from '../../actions/global_notification_actions'; import PieceListActions from '../../actions/piece_list_actions'; import PieceListStore from '../../stores/piece_list_store'; import AccordionListItemPiece from './accordion_list_item_piece'; import AccordionListItemEditionWidget from './accordion_list_item_edition_widget'; import CreateEditionsForm from '../ascribe_forms/create_editions_form'; import AclProxy from '../acl_proxy'; import { getLangText } from '../../utils/lang_utils'; import { mergeOptions } from '../../utils/general_utils'; let AccordionListItemWallet = React.createClass({ propTypes: { content: React.PropTypes.object.isRequired, whitelabel: React.PropTypes.object.isRequired, children: React.PropTypes.oneOfType([ React.PropTypes.arrayOf(React.PropTypes.element), React.PropTypes.element ]), className: React.PropTypes.string, thumbnailPlaceholder: React.PropTypes.func }, getInitialState() { return mergeOptions( PieceListStore.getState(), { showCreateEditionsDialog: false } ); }, componentDidMount() { PieceListStore.listen(this.onChange); }, componentWillUnmount() { PieceListStore.unlisten(this.onChange); }, onChange(state) { this.setState(state); }, getGlyphicon() { if (this.props.content.notifications && this.props.content.notifications.length) { return ( {getLangText('You have actions pending')}}> ); } else { return null; } }, toggleCreateEditionsDialog() { this.setState({ showCreateEditionsDialog: !this.state.showCreateEditionsDialog }); }, handleEditionCreationSuccess() { PieceListActions.updatePropertyForPiece({pieceId: this.props.content.id, key: 'num_editions', value: 0}); this.toggleCreateEditionsDialog(); }, onPollingSuccess(pieceId) { const { filterBy, orderAsc, orderBy, page, pageSize, search } = this.state; PieceListActions.fetchPieceList({ page, pageSize, search, orderBy, orderAsc, filterBy }); EditionListActions.toggleEditionList(pieceId); const notification = new GlobalNotificationModel(getLangText('Editions successfully created'), 'success', 10000); GlobalNotificationActions.appendGlobalNotification(notification); }, getCreateEditionsDialog() { if (this.props.content.num_editions < 1 && this.state.showCreateEditionsDialog) { return (
); } }, getLicences() { const { content, whitelabel } = this.props; // convert this to acl_view_licences later if (whitelabel.name === 'Creative Commons France') { return ( , {getLangText('%s license', content.license_type.code)} ); } }, render() { const { children, className, content, thumbnailPlaceholder } = this.props; return ( {Moment(content.date_created, 'YYYY-MM-DD').year()} {this.getLicences()} } buttons={
} badge={this.getGlyphicon()} thumbnailPlaceholder={thumbnailPlaceholder}> {this.getCreateEditionsDialog()} {/* this.props.children is AccordionListItemTableEditions */} {children}
); } }); export default AccordionListItemWallet;