diff --git a/js/actions/edition_list_actions.js b/js/actions/edition_list_actions.js index f04b63c8..5c5303b0 100644 --- a/js/actions/edition_list_actions.js +++ b/js/actions/edition_list_actions.js @@ -44,7 +44,7 @@ class EditionListActions { }) .catch((err) => { reject(err); - console.log(err); + //console.log(err); }); }); diff --git a/js/actions/piece_list_actions.js b/js/actions/piece_list_actions.js index 188935f7..f0d3e5f1 100644 --- a/js/actions/piece_list_actions.js +++ b/js/actions/piece_list_actions.js @@ -9,7 +9,8 @@ class PieceListActions { this.generateActions( 'updatePieceList', 'updatePieceListRequestActions', - 'addFirstEditionToPiece' + 'addFirstEditionToPiece', + 'updatePropertyForPiece' ); } diff --git a/js/components/ascribe_accordion_list/accordion_list_item.js b/js/components/ascribe_accordion_list/accordion_list_item.js index b3e31265..03d14425 100644 --- a/js/components/ascribe_accordion_list/accordion_list_item.js +++ b/js/components/ascribe_accordion_list/accordion_list_item.js @@ -3,13 +3,18 @@ import React from 'react'; import Router from 'react-router'; -import PieceListActions from '../../actions/piece_list_actions'; - import Glyphicon from 'react-bootstrap/lib/Glyphicon'; import OverlayTrigger from 'react-bootstrap/lib/OverlayTrigger'; import Tooltip from 'react-bootstrap/lib/Tooltip'; import AccordionListItemEditionWidget from './accordion_list_item_edition_widget'; +import AccordionListItemCreateEditions from './accordion_list_item_create_editions'; + +import PieceListActions from '../../actions/piece_list_actions'; +import EditionListActions from '../../actions/edition_list_actions'; + +import GlobalNotificationModel from '../../models/global_notification_model'; +import GlobalNotificationActions from '../../actions/global_notification_actions'; import { getLangText } from '../../utils/lang_utils'; @@ -24,8 +29,15 @@ let AccordionListItem = React.createClass({ mixins: [Router.Navigation], + getInitialState() { + return { + showCreateEditionsDialog: false, + creatingEditions: false + }; + }, + componentDidMount() { - if(this.props.content.num_editions !== 0) { + if(this.props.content.num_editions > 0) { PieceListActions.fetchFirstEditionForPiece(this.props.content.id); } }, @@ -45,10 +57,57 @@ let AccordionListItem = React.createClass({ return null; }, + toggleCreateEditionsDialog() { + this.setState({ + showCreateEditionsDialog: !this.state.showCreateEditionsDialog + }); + }, + + handleEditionCreationSuccess(response) { + let notification = new GlobalNotificationModel(response.notification, 'success', 10000); + GlobalNotificationActions.appendGlobalNotification(notification); + PieceListActions.updatePropertyForPiece({pieceId: this.props.content.id, key: 'num_editions', value: 0}); + + this.setState({ + creatingEditions: true + }); + + this.toggleCreateEditionsDialog(); + + // start polling until editions are defined + let pollingIntervalIndex = setInterval(() => { + EditionListActions.fetchEditionList(this.props.content.id) + .then((res) => { + + clearInterval(this.state.pollingIntervalIndex); + + this.setState({ + creatingEditions: false + }); + + PieceListActions.updatePropertyForPiece({ + pieceId: this.props.content.id, + key: 'num_editions', + value: res.editions[0].num_editions + }); + + EditionListActions.toggleEditionList(this.props.content.id); + + }) + .catch(() => { + /* Ignore and keep going */ + }); + }, 5000); + + this.setState({ + pollingIntervalIndex + }); + }, + render() { let linkData; - if(this.props.content.num_editions === 0) { + if(this.props.content.num_editions < 1) { linkData = { to: 'piece', params: { @@ -81,9 +140,13 @@ let AccordionListItem = React.createClass({
{getLangText('Are you sure you would like to remove these editions from your collection')}?
{getLangText('This is an irrevocable action%s', '.')}