1
0
mirror of https://github.com/ascribe/onion.git synced 2025-01-03 10:25:08 +01:00

bulk transfer part 1

This commit is contained in:
ddejongh 2015-06-02 11:38:18 +02:00
parent cbecbf44ad
commit dc3d024f8d
7 changed files with 72 additions and 48 deletions

View File

@ -12,11 +12,8 @@ let AclButton = React.createClass({
action: React.PropTypes.oneOf(AppConstants.aclList).isRequired, action: React.PropTypes.oneOf(AppConstants.aclList).isRequired,
availableAcls: React.PropTypes.array.isRequired, availableAcls: React.PropTypes.array.isRequired,
editions: React.PropTypes.array.isRequired, editions: React.PropTypes.array.isRequired,
currentUser: React.PropTypes.object currentUser: React.PropTypes.object,
}, handleSuccess: React.PropTypes.func.isRequired
actionFunction() {
this.props.actionFunction(this.props.action);
}, },
actionProperties(){ actionProperties(){
@ -58,7 +55,8 @@ let AclButton = React.createClass({
</div> </div>
} }
currentUser={ this.props.currentUser } currentUser={ this.props.currentUser }
edition={ this.props.editions[0] } editions={ this.props.editions }
handleSuccess={ this.props.handleSuccess }
title={ aclProps.title } title={ aclProps.title }
tooltip={ aclProps.tooltip }> tooltip={ aclProps.tooltip }>
{ aclProps.form } { aclProps.form }

View File

@ -16,19 +16,21 @@ let ConsignForm = React.createClass({
}, },
getFormData() { getFormData() {
return { return {
bitcoin_id: this.props.edition.bitcoin_id, bitcoin_id: this.getBitcoinIds().join(),
consignee: this.refs.consignee.state.value, consignee: this.refs.consignee.state.value,
consign_message: this.refs.consign_message.state.value, consign_message: this.refs.consign_message.state.value,
password: this.refs.password.state.value password: this.refs.password.state.value
} }
}, },
renderForm() { renderForm() {
let title = this.props.edition.title; let title = this.getTitlesString().join("");
let username = this.props.currentUser.username; let username = this.props.currentUser.username;
let message = let message =
`Hi, `Hi,
I consign \" ${title} \" to you. I consign :
${title}to you.
Truly yours, Truly yours,
${username}`; ${username}`;

View File

@ -18,19 +18,24 @@ let TransferForm = React.createClass({
}, },
getFormData() { getFormData() {
return { return {
bitcoin_id: this.props.edition.bitcoin_id, bitcoin_id: this.getBitcoinIds().join(),
transferee: this.refs.transferee.state.value, transferee: this.refs.transferee.state.value,
transfer_message: this.refs.transfer_message.state.value, transfer_message: this.refs.transfer_message.state.value,
password: this.refs.password.state.value password: this.refs.password.state.value
} }
}, },
renderForm() { renderForm() {
let message = "Hi,\n" + let title = this.getTitlesString().join("");
"\n" + let username = this.props.currentUser.username;
"I transfer ownership of \"" + this.props.edition.title + "\" to you.\n" + let message =
"\n" + `Hi,
"Truly yours,\n" +
this.props.currentUser.username; I transfer ownership of :
${title}to you.
Truly yours,
${username}`;
return ( return (
<form id="transfer_modal_content" role="form" onSubmit={this.submit}> <form id="transfer_modal_content" role="form" onSubmit={this.submit}>
<input className="invisible" type="email" name="fake_transferee"/> <input className="invisible" type="email" name="fake_transferee"/>

View File

@ -17,8 +17,10 @@ let ModalWrapper = React.createClass({
<ModalTrigger modal={ <ModalTrigger modal={
<ModalBody <ModalBody
title={this.props.title} title={this.props.title}
edition={this.props.edition} editions={this.props.editions}
currentUser={this.props.currentUser}> currentUser={this.props.currentUser}
handleSuccess={this.props.handleSuccess}
>
{this.props.children} {this.props.children}
</ModalBody> </ModalBody>
}> }>
@ -33,12 +35,17 @@ let ModalWrapper = React.createClass({
let ModalBody = React.createClass({ let ModalBody = React.createClass({
mixins : [ModalMixin], mixins : [ModalMixin],
handleSuccess(){
this.props.handleSuccess();
this.props.onRequestHide();
},
renderChildren() { renderChildren() {
return ReactAddons.Children.map(this.props.children, (child, i) => { return ReactAddons.Children.map(this.props.children, (child, i) => {
return ReactAddons.addons.cloneWithProps(child, { return ReactAddons.addons.cloneWithProps(child, {
edition: this.props.edition, editions: this.props.editions,
currentUser: this.props.currentUser, currentUser: this.props.currentUser,
onRequestHide: this.onRequestHide onRequestHide: this.onRequestHide,
handleSuccess: this.handleSuccess
}); });
}); });
}, },

View File

@ -80,7 +80,9 @@ let PieceListToolbar = React.createClass({
clearAllSelections() { clearAllSelections() {
EditionListActions.clearAllEditionSelections(); EditionListActions.clearAllEditionSelections();
}, },
handleSuccess(){
},
render() { render() {
let availableAcls = this.getAvailableAcls(); let availableAcls = this.getAvailableAcls();
let editions = this.fetchSelectedEditionList(); let editions = this.fetchSelectedEditionList();
@ -107,23 +109,27 @@ let PieceListToolbar = React.createClass({
<AclButton <AclButton
availableAcls={availableAcls} availableAcls={availableAcls}
action="transfer" action="transfer"
currentUser={this.state.currentUser}
editions={editions} editions={editions}
currentUser={this.state.currentUser}/> handleSuccess={this.handleSuccess}/>
<AclButton <AclButton
availableAcls={availableAcls} availableAcls={availableAcls}
action="consign" action="consign"
currentUser={this.state.currentUser}
editions={editions} editions={editions}
currentUser={this.state.currentUser}/> handleSuccess={this.handleSuccess}/>
<AclButton <AclButton
availableAcls={availableAcls} availableAcls={availableAcls}
action="loan" action="loan"
currentUser={this.state.currentUser}
editions={editions} editions={editions}
currentUser={this.state.currentUser}/> handleSuccess={this.handleSuccess}/>
<AclButton <AclButton
availableAcls={availableAcls} availableAcls={availableAcls}
action="share" action="share"
currentUser={this.state.currentUser}
editions={editions} editions={editions}
currentUser={this.state.currentUser}/> handleSuccess={this.handleSuccess}/>
</div> </div>
</div> </div>
</div> </div>

View File

@ -1,13 +1,8 @@
import React from 'react'; import React from 'react';
import ResourceViewer from './ascribe_media/resource_viewer'; import ResourceViewer from './ascribe_media/resource_viewer';
import LoanModalButton from './ascribe_modal/modal_loan'; import EditionActions from '../actions/edition_actions'
import ModalWrapper from './ascribe_modal/modal_wrapper'; import AclButton from './acl_button'
import ConsignForm from './ascribe_forms/form_consign.js';
import UnConsignModalButton from './ascribe_modal/modal_unconsign';
import UnConsignRequestModalButton from './ascribe_modal/modal_unconsign_request';
import TransferModalButton from './ascribe_modal/modal_transfer';
import ShareModalButton from './ascribe_modal/modal_share';
/** /**
* This is the component that implements display-specific functionality * This is the component that implements display-specific functionality
@ -49,7 +44,9 @@ let EditionHeader = React.createClass({
}); });
let EditionDetails = React.createClass({ let EditionDetails = React.createClass({
handleSuccess(){
EditionActions.fetchOne(this.props.edition.id);
},
render() { render() {
return ( return (
<div className="ascribe-detail-header"> <div className="ascribe-detail-header">
@ -58,19 +55,20 @@ let EditionDetails = React.createClass({
<EditionDetailProperty label="id" value={ this.props.edition.bitcoin_id } /> <EditionDetailProperty label="id" value={ this.props.edition.bitcoin_id } />
<EditionDetailProperty label="owner" value={ this.props.edition.owner } /> <EditionDetailProperty label="owner" value={ this.props.edition.owner } />
<br/> <br/>
<LoanModalButton edition={ this.props.edition } currentUser={ this.props.currentUser }/> <AclButton
<ModalWrapper availableAcls={["transfer"]}
button={<div className="btn btn-ascribe-inv">CONSIGN</div>} action="transfer"
currentUser={ this.props.currentUser } editions={[this.props.edition]}
edition={ this.props.edition } currentUser={this.props.currentUser}
title="Consign artwork" handleSuccess={this.handleSuccess}
tooltip="Have someone else sell the artwork"> />
<ConsignForm /> <AclButton
</ModalWrapper> availableAcls={["consign"]}
<UnConsignModalButton edition={ this.props.edition } currentUser={ this.props.currentUser }/> action="consign"
<UnConsignRequestModalButton edition={ this.props.edition } currentUser={ this.props.currentUser }/> editions={[this.props.edition]}
<TransferModalButton edition={ this.props.edition } currentUser={ this.props.currentUser }/> currentUser={this.props.currentUser}
<ShareModalButton edition={ this.props.edition } currentUser={ this.props.currentUser }/> handleSuccess={this.handleSuccess}
/>
<hr/> <hr/>
</div> </div>
); );

View File

@ -1,6 +1,5 @@
import React from 'react'; import React from 'react';
import EditionActions from '../actions/edition_actions'
import AppConstants from '../constants/application_constants' import AppConstants from '../constants/application_constants'
import AlertDismissable from '../components/ascribe_forms/alert' import AlertDismissable from '../components/ascribe_forms/alert'
@ -34,8 +33,7 @@ export const FormMixin = {
handleResponse(response){ handleResponse(response){
let submitted = false; let submitted = false;
if (response.status >= 200 && response.status < 300){ if (response.status >= 200 && response.status < 300){
EditionActions.fetchOne(this.props.edition.id); this.props.handleSuccess();
this.props.onRequestHide();
submitted = true; submitted = true;
} }
else if (response.status >= 400 && response.status < 500) { else if (response.status >= 400 && response.status < 500) {
@ -57,6 +55,16 @@ export const FormMixin = {
} }
} }
}, },
getBitcoinIds(){
return this.props.editions.map(function(edition){
return edition.bitcoin_id
})
},
getTitlesString(){
return this.props.editions.map(function(edition){
return '- \"' + edition.title + ', edition ' + edition.edition_number + '\"\n'
})
},
render(){ render(){
let alert = null; let alert = null;
if (this.state.status >= 500){ if (this.state.status >= 500){