diff --git a/js/actions/edition_list_actions.js b/js/actions/edition_list_actions.js index d13882cd..fb0a2249 100644 --- a/js/actions/edition_list_actions.js +++ b/js/actions/edition_list_actions.js @@ -33,6 +33,10 @@ class EditionListActions { EditionListFetcher .fetch(pieceId, page, pageSize, orderBy, orderAsc, filterBy) .then((res) => { + if(res && !res.editions) { + throw new Error('Piece has no editions to fetch.'); + } + this.actions.updateEditionList({ pieceId, page, @@ -46,6 +50,7 @@ class EditionListActions { resolve(res); }) .catch((err) => { + console.logGlobal(err); reject(err); }); }); diff --git a/js/components/ascribe_detail/edition.js b/js/components/ascribe_detail/edition.js index 7f700c42..62394631 100644 --- a/js/components/ascribe_detail/edition.js +++ b/js/components/ascribe_detail/edition.js @@ -6,15 +6,11 @@ import Router from 'react-router'; import Row from 'react-bootstrap/lib/Row'; import Col from 'react-bootstrap/lib/Col'; import Glyphicon from 'react-bootstrap/lib/Glyphicon'; -import Button from 'react-bootstrap/lib/Button'; import UserActions from '../../actions/user_actions'; import UserStore from '../../stores/user_store'; import CoaActions from '../../actions/coa_actions'; import CoaStore from '../../stores/coa_store'; -import PieceListActions from '../../actions/piece_list_actions'; -import PieceListStore from '../../stores/piece_list_store'; -import EditionListActions from '../../actions/edition_list_actions'; import HistoryIterator from './history_iterator'; @@ -28,13 +24,7 @@ import EditionDetailProperty from './detail_property'; import LicenseDetail from './license_detail'; import EditionFurtherDetails from './further_details'; -import ListRequestActions from './../ascribe_forms/list_form_request_actions'; -import AclButtonList from './../ascribe_buttons/acl_button_list'; -import UnConsignRequestButton from './../ascribe_buttons/unconsign_request_button'; -import DeleteButton from '../ascribe_buttons/delete_button'; - -import GlobalNotificationModel from '../../models/global_notification_model'; -import GlobalNotificationActions from '../../actions/global_notification_actions'; +import EditionActionPanel from './edition_action_panel'; import Note from './note'; @@ -42,7 +32,6 @@ import ApiUrls from '../../constants/api_urls'; import AppConstants from '../../constants/application_constants'; import { getLangText } from '../../utils/lang_utils'; -import { mergeOptions } from '../../utils/general_utils'; let Link = Router.Link; /** @@ -57,15 +46,11 @@ let Edition = React.createClass({ mixins: [Router.Navigation], getInitialState() { - return mergeOptions( - UserStore.getState(), - PieceListStore.getState() - ); + return UserStore.getState(); }, componentDidMount() { UserStore.listen(this.onChange); - PieceListStore.listen(this.onChange); UserActions.fetchCurrentUser(); }, @@ -80,31 +65,12 @@ let Edition = React.createClass({ CoaActions.flushCoa(); UserStore.unlisten(this.onChange); - PieceListStore.unlisten(this.onChange); }, onChange(state) { this.setState(state); }, - handleDeleteSuccess(response) { - this.refreshCollection(); - - EditionListActions.closeAllEditionLists(); - EditionListActions.clearAllEditionSelections(); - - let notification = new GlobalNotificationModel(response.notification, 'success'); - GlobalNotificationActions.appendGlobalNotification(notification); - - this.transitionTo('pieces'); - }, - - refreshCollection() { - PieceListActions.fetchPieceList(this.state.page, this.state.pageSize, this.state.search, - this.state.orderBy, this.state.orderAsc, this.state.filterBy); - EditionListActions.refreshEditionList({pieceId: this.props.edition.parent}); - }, - render() { return ( @@ -121,12 +87,9 @@ let Edition = React.createClass({
- + currentUser={this.state.currentUser} + handleSuccess={this.props.loadEdition}/> @@ -209,29 +172,14 @@ let Edition = React.createClass({ let EditionSummary = React.createClass({ propTypes: { edition: React.PropTypes.object, - handleSuccess: React.PropTypes.func, currentUser: React.PropTypes.object, - handleDeleteSuccess: React.PropTypes.func, - refreshCollection: React.PropTypes.func - }, - - getTransferWithdrawData(){ - return {'bitcoin_id': this.props.edition.bitcoin_id}; + handleSuccess: React.PropTypes.func }, handleSuccess() { - this.props.refreshCollection(); this.props.handleSuccess(); }, - showNotification(response){ - this.props.handleSuccess(); - - if (response){ - let notification = new GlobalNotificationModel(response.notification, 'success'); - GlobalNotificationActions.appendGlobalNotification(notification); - } - }, getStatus(){ let status = null; if (this.props.edition.status.length > 0){ @@ -246,79 +194,26 @@ let EditionSummary = React.createClass({ return status; }, - getActions(){ - let actions = null; - if (this.props.edition && - this.props.edition.notifications && - this.props.edition.notifications.length > 0){ - actions = ( - ); - } - - else { - let withdrawButton = null; - if (this.props.edition.status.length > 0 && this.props.edition.pending_new_owner && this.props.edition.acl.acl_withdraw_transfer) { - withdrawButton = ( -
- -
- ); - } - let unconsignRequestButton = null; - if (this.props.edition.acl.acl_request_unconsign) { - unconsignRequestButton = ( - - ); - } - actions = ( - - - - {withdrawButton} - - {unconsignRequestButton} - - - ); - } - return actions; - }, render() { + let { edition, currentUser } = this.props; return (
+ value={ edition.edition_number + ' ' + getLangText('of') + ' ' + edition.num_editions} /> - + value={ edition.owner } /> + {this.getStatus()} - {this.getActions()} +
); diff --git a/js/components/ascribe_detail/edition_action_panel.js b/js/components/ascribe_detail/edition_action_panel.js new file mode 100644 index 00000000..d82a6b8f --- /dev/null +++ b/js/components/ascribe_detail/edition_action_panel.js @@ -0,0 +1,169 @@ +'use strict'; + +import React from 'react'; +import Router from 'react-router'; + +import Row from 'react-bootstrap/lib/Row'; +import Col from 'react-bootstrap/lib/Col'; +import Button from 'react-bootstrap/lib/Button'; + +import EditionListActions from '../../actions/edition_list_actions'; +import PieceListActions from '../../actions/piece_list_actions'; +import PieceListStore from '../../stores/piece_list_store'; + +import Form from './../ascribe_forms/form'; +import Property from './../ascribe_forms/property'; + +import ListRequestActions from './../ascribe_forms/list_form_request_actions'; +import AclButtonList from './../ascribe_buttons/acl_button_list'; +import UnConsignRequestButton from './../ascribe_buttons/unconsign_request_button'; +import DeleteButton from '../ascribe_buttons/delete_button'; + +import GlobalNotificationModel from '../../models/global_notification_model'; +import GlobalNotificationActions from '../../actions/global_notification_actions'; + +import AclProxy from '../acl_proxy'; + +import ApiUrls from '../../constants/api_urls'; + +import { getLangText } from '../../utils/lang_utils'; + +/* + A component that handles all the actions inside of the edition detail + handleSuccess requires a loadEdition action (could be refactored) + */ +let EditionActionPanel = React.createClass({ + propTypes: { + edition: React.PropTypes.object, + currentUser: React.PropTypes.object, + handleSuccess: React.PropTypes.func + }, + + mixins: [Router.Navigation], + + getInitialState() { + return PieceListStore.getState(); + }, + + componentDidMount() { + PieceListStore.listen(this.onChange); + }, + + componentWillUnmount() { + PieceListStore.unlisten(this.onChange); + }, + + onChange(state) { + this.setState(state); + }, + + handleDeleteSuccess(response) { + this.refreshCollection(); + + EditionListActions.closeAllEditionLists(); + EditionListActions.clearAllEditionSelections(); + + let notification = new GlobalNotificationModel(response.notification, 'success'); + GlobalNotificationActions.appendGlobalNotification(notification); + + this.transitionTo('pieces'); + }, + + refreshCollection() { + PieceListActions.fetchPieceList(this.state.page, this.state.pageSize, this.state.search, + this.state.orderBy, this.state.orderAsc, this.state.filterBy); + EditionListActions.refreshEditionList({pieceId: this.props.edition.parent}); + }, + + handleSuccess(response){ + this.refreshCollection(); + this.props.handleSuccess(); + if (response){ + let notification = new GlobalNotificationModel(response.notification, 'success'); + GlobalNotificationActions.appendGlobalNotification(notification); + } + }, + + render(){ + let {edition, currentUser} = this.props; + + if (edition && + edition.notifications && + edition.notifications.length > 0){ + return ( + ); + } + + else { + return ( + + + + +
+ + +
+
+ +
+ + +
+
+ + + + +
+ +
+ ); + } + } +}); + +export default EditionActionPanel; \ No newline at end of file diff --git a/js/components/ascribe_piece_list_bulk_modal/piece_list_bulk_modal.js b/js/components/ascribe_piece_list_bulk_modal/piece_list_bulk_modal.js index 452a9bd8..3e5b6495 100644 --- a/js/components/ascribe_piece_list_bulk_modal/piece_list_bulk_modal.js +++ b/js/components/ascribe_piece_list_bulk_modal/piece_list_bulk_modal.js @@ -33,21 +33,28 @@ let PieceListBulkModal = React.createClass({ ); }, - onChange(state) { - this.setState(state); - }, + componentDidMount() { EditionListStore.listen(this.onChange); UserStore.listen(this.onChange); + PieceListStore.listen(this.onChange); + UserActions.fetchCurrentUser(); + PieceListActions.fetchPieceList(this.state.page, this.state.pageSize, this.state.search, + this.state.orderBy, this.state.orderAsc, this.state.filterBy); }, componentWillUnmount() { EditionListStore.unlisten(this.onChange); + PieceListStore.unlisten(this.onChange); UserStore.unlisten(this.onChange); }, + onChange(state) { + this.setState(state); + }, + fetchSelectedPieceEditionList() { let filteredPieceIdList = Object.keys(this.state.editionList) .filter((pieceId) => { diff --git a/js/constants/api_urls.js b/js/constants/api_urls.js index b8d6713d..2ff689fe 100644 --- a/js/constants/api_urls.js +++ b/js/constants/api_urls.js @@ -38,6 +38,7 @@ let ApiUrls = { 'ownership_consigns': AppConstants.apiEndpoint + 'ownership/consigns/', 'ownership_consigns_confirm': AppConstants.apiEndpoint + 'ownership/consigns/confirm/', 'ownership_consigns_deny': AppConstants.apiEndpoint + 'ownership/consigns/deny/', + 'ownership_consigns_withdraw': AppConstants.apiEndpoint + 'ownership/consigns/withdraw/', 'ownership_loans_pieces': AppConstants.apiEndpoint + 'ownership/loans/pieces/', 'ownership_loans_pieces_confirm': AppConstants.apiEndpoint + 'ownership/loans/pieces/confirm/', 'ownership_loans_pieces_deny': AppConstants.apiEndpoint + 'ownership/loans/pieces/deny/', diff --git a/js/stores/edition_list_store.js b/js/stores/edition_list_store.js index 87b4df76..b3b152d3 100644 --- a/js/stores/edition_list_store.js +++ b/js/stores/edition_list_store.js @@ -13,7 +13,6 @@ class EditionListStore { } onUpdateEditionList({pieceId, editionListOfPiece, page, pageSize, orderBy, orderAsc, count, filterBy}) { - /* Basically there are two modes an edition list can be updated.