1
0
mirror of https://github.com/ascribe/onion.git synced 2024-11-15 17:45:10 +01:00
onion/js/components/ascribe_detail/edition_action_panel.js

188 lines
7.3 KiB
JavaScript
Raw Normal View History

2015-09-30 12:12:14 +02:00
'use strict';
import React from 'react';
2015-10-22 13:21:07 +02:00
import { History } from 'react-router';
2015-09-30 12:12:14 +02:00
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';
2015-11-03 10:39:01 +01:00
import AclInformation from '../ascribe_buttons/acl_information';
2015-09-30 12:12:14 +02:00
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)
*/
2015-10-01 09:49:01 +02:00
let EditionActionPanel = React.createClass({
2015-09-30 12:12:14 +02:00
propTypes: {
actionPanelButtonListType: React.PropTypes.func,
2015-09-30 12:12:14 +02:00
edition: React.PropTypes.object,
currentUser: React.PropTypes.object,
handleSuccess: React.PropTypes.func
},
2015-10-22 13:21:07 +02:00
mixins: [History],
2015-09-30 12:12:14 +02:00
getDefaultProps() {
return {
actionPanelButtonListType: AclButtonList
};
},
2015-09-30 12:12:14 +02:00
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);
2015-11-03 10:39:01 +01:00
this.history.pushState(null, '/collection');
2015-09-30 12:12:14 +02:00
},
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(){
2015-12-04 16:34:25 +01:00
const {
actionPanelButtonListType: ActionPanelButtonListType,
edition,
currentUser } = this.props;
2015-09-30 12:12:14 +02:00
if (edition &&
edition.notifications &&
edition.notifications.length > 0){
return (
<ListRequestActions
pieceOrEditions={[edition]}
currentUser={currentUser}
handleSuccess={this.handleSuccess}
notifications={edition.notifications}/>);
}
else {
return (
<Row>
<Col md={12}>
<ActionPanelButtonListType
2015-11-03 10:39:01 +01:00
className="ascribe-button-list"
2015-09-30 12:12:14 +02:00
availableAcls={edition.acl}
2015-11-03 11:13:32 +01:00
pieceOrEditions={[edition]}
2015-09-30 12:12:14 +02:00
handleSuccess={this.handleSuccess}>
<AclProxy
aclObject={edition.acl}
aclName="acl_withdraw_transfer">
<Form
url={ApiUrls.ownership_transfers_withdraw}
handleSuccess={this.handleSuccess}
className='inline'
isInline={true}>
<Property
name="bitcoin_id"
expanded={false}>
2015-09-30 12:12:14 +02:00
<input
type="text"
value={edition.bitcoin_id}
readOnly />
2015-09-30 12:12:14 +02:00
</Property>
2015-11-03 10:39:01 +01:00
<Button bsStyle="default" className="pull-center" bsSize="small" type="submit">
2015-09-30 12:12:14 +02:00
{getLangText('WITHDRAW TRANSFER')}
</Button>
</Form>
</AclProxy>
<AclProxy
aclObject={edition.acl}
aclName="acl_withdraw_consign">
<Form
url={ApiUrls.ownership_consigns_withdraw}
handleSuccess={this.handleSuccess}
className='inline'
isInline={true}>
<Property
name="bitcoin_id"
expanded={false}>
2015-09-30 12:12:14 +02:00
<input
type="text"
value={edition.bitcoin_id}
readOnly />
2015-09-30 12:12:14 +02:00
</Property>
<Button bsStyle="danger" className="btn-delete pull-center" bsSize="small" type="submit">
{getLangText('WITHDRAW CONSIGN')}
</Button>
</Form>
</AclProxy>
<AclProxy
aclObject={edition.acl}
aclName="acl_request_unconsign">
<UnConsignRequestButton
currentUser={currentUser}
edition={edition}
handleSuccess={this.handleSuccess} />
</AclProxy>
<DeleteButton
handleSuccess={this.handleDeleteSuccess}
editions={[edition]}/>
2015-11-03 10:39:01 +01:00
<AclInformation
aim="button"
2015-11-19 19:47:33 +01:00
verbs={['acl_share', 'acl_transfer', 'acl_consign', 'acl_loan', 'acl_delete']}
2015-11-03 10:39:01 +01:00
aclObject={edition.acl}/>
</ActionPanelButtonListType>
2015-09-30 12:12:14 +02:00
</Col>
</Row>
);
}
}
});
export default EditionActionPanel;