1
0
mirror of https://github.com/ascribe/onion.git synced 2024-12-23 01:39:36 +01:00

acl buttons and share forms for pieces/editions

This commit is contained in:
diminator 2015-07-10 20:00:35 +02:00
parent 62289be5ce
commit 88ff4b55d6
5 changed files with 155 additions and 62 deletions

View File

@ -13,14 +13,14 @@ import AppConstants from '../../constants/application_constants';
import GlobalNotificationModel from '../../models/global_notification_model'; import GlobalNotificationModel from '../../models/global_notification_model';
import GlobalNotificationActions from '../../actions/global_notification_actions'; import GlobalNotificationActions from '../../actions/global_notification_actions';
import { getLangText } from '../../utils/lang_utils.js' import { getLangText } from '../../utils/lang_utils.js';
let AclButton = React.createClass({ let AclButton = React.createClass({
propTypes: { propTypes: {
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, pieceOrEditions: React.PropTypes.array.isRequired,
currentUser: React.PropTypes.object, currentUser: React.PropTypes.object,
handleSuccess: React.PropTypes.func.isRequired, handleSuccess: React.PropTypes.func.isRequired,
className: React.PropTypes.string className: React.PropTypes.string
@ -31,7 +31,7 @@ let AclButton = React.createClass({
return { return {
title: getLangText('Consign artwork'), title: getLangText('Consign artwork'),
tooltip: getLangText('Have someone else sell the artwork'), tooltip: getLangText('Have someone else sell the artwork'),
form: <ConsignForm currentUser={ this.props.currentUser } editions={ this.props.editions }/>, form: <ConsignForm currentUser={ this.props.currentUser } editions={ this.props.pieceOrEditions }/>,
handleSuccess: this.showNotification handleSuccess: this.showNotification
}; };
} }
@ -39,14 +39,14 @@ let AclButton = React.createClass({
return { return {
title: getLangText('Unconsign artwork'), title: getLangText('Unconsign artwork'),
tooltip: getLangText('Have the owner manage his sales again'), tooltip: getLangText('Have the owner manage his sales again'),
form: <UnConsignForm currentUser={ this.props.currentUser } editions={ this.props.editions }/>, form: <UnConsignForm currentUser={ this.props.currentUser } editions={ this.props.pieceOrEditions }/>,
handleSuccess: this.showNotification handleSuccess: this.showNotification
}; };
}else if (this.props.action === 'transfer') { }else if (this.props.action === 'transfer') {
return { return {
title: getLangText('Transfer artwork'), title: getLangText('Transfer artwork'),
tooltip: getLangText('Transfer the ownership of the artwork'), tooltip: getLangText('Transfer the ownership of the artwork'),
form: <TransferForm currentUser={ this.props.currentUser } editions={ this.props.editions }/>, form: <TransferForm currentUser={ this.props.currentUser } editions={ this.props.pieceOrEditions }/>,
handleSuccess: this.showNotification handleSuccess: this.showNotification
}; };
} }
@ -54,7 +54,7 @@ let AclButton = React.createClass({
return { return {
title: getLangText('Loan artwork'), title: getLangText('Loan artwork'),
tooltip: getLangText('Loan your artwork for a limited period of time'), tooltip: getLangText('Loan your artwork for a limited period of time'),
form: <LoanForm currentUser={ this.props.currentUser } editions={ this.props.editions }/>, form: <LoanForm currentUser={ this.props.currentUser } editions={ this.props.pieceOrEditions }/>,
handleSuccess: this.showNotification handleSuccess: this.showNotification
}; };
} }
@ -62,7 +62,7 @@ let AclButton = React.createClass({
return { return {
title: getLangText('Share artwork'), title: getLangText('Share artwork'),
tooltip: getLangText('Share the artwork'), tooltip: getLangText('Share the artwork'),
form: <ShareForm currentUser={ this.props.currentUser } editions={ this.props.editions }/>, form: <ShareForm currentUser={ this.props.currentUser } editions={ this.props.pieceOrEditions }/>,
handleSuccess: this.showNotification handleSuccess: this.showNotification
}; };
} }

View File

@ -39,31 +39,31 @@ let AclButtonList = React.createClass({
<AclButton <AclButton
availableAcls={this.props.availableAcls} availableAcls={this.props.availableAcls}
action="transfer" action="transfer"
editions={this.props.editions} pieceOrEditions={this.props.editions}
currentUser={this.state.currentUser} currentUser={this.state.currentUser}
handleSuccess={this.props.handleSuccess}/> handleSuccess={this.props.handleSuccess}/>
<AclButton <AclButton
availableAcls={this.props.availableAcls} availableAcls={this.props.availableAcls}
action="consign" action="consign"
editions={this.props.editions} pieceOrEditions={this.props.editions}
currentUser={this.state.currentUser} currentUser={this.state.currentUser}
handleSuccess={this.props.handleSuccess} /> handleSuccess={this.props.handleSuccess} />
<AclButton <AclButton
availableAcls={this.props.availableAcls} availableAcls={this.props.availableAcls}
action="unconsign" action="unconsign"
editions={this.props.editions} pieceOrEditions={this.props.editions}
currentUser={this.state.currentUser} currentUser={this.state.currentUser}
handleSuccess={this.props.handleSuccess} /> handleSuccess={this.props.handleSuccess} />
<AclButton <AclButton
availableAcls={this.props.availableAcls} availableAcls={this.props.availableAcls}
action="loan" action="loan"
editions={this.props.editions} pieceOrEditions={this.props.editions}
currentUser={this.state.currentUser} currentUser={this.state.currentUser}
handleSuccess={this.props.handleSuccess} /> handleSuccess={this.props.handleSuccess} />
<AclButton <AclButton
availableAcls={this.props.availableAcls} availableAcls={this.props.availableAcls}
action="share" action="share"
editions={this.props.editions} pieceOrEditions={this.props.editions}
currentUser={this.state.currentUser} currentUser={this.state.currentUser}
handleSuccess={this.props.handleSuccess} /> handleSuccess={this.props.handleSuccess} />
<DeleteButton editions={this.props.editions}/> <DeleteButton editions={this.props.editions}/>

View File

@ -7,14 +7,30 @@ import Col from 'react-bootstrap/lib/Col';
import CollapsibleParagraph from './../ascribe_collapsible/collapsible_paragraph'; import CollapsibleParagraph from './../ascribe_collapsible/collapsible_paragraph';
import DetailProperty from './detail_property';
import FurtherDetails from './further_details'; import FurtherDetails from './further_details';
//import UserActions from '../../actions/user_actions'; import UserActions from '../../actions/user_actions';
//import UserStore from '../../stores/user_store'; import UserStore from '../../stores/user_store';
import MediaContainer from './media_container'; import MediaContainer from './media_container';
import Header from './header'; import Header from './header';
import Form from './../ascribe_forms/form';
import Property from './../ascribe_forms/property';
import RequestActionForm from './../ascribe_forms/form_request_action';
import EditionActions from '../../actions/edition_actions';
import AclButtonList from './../ascribe_buttons/acl_button_list';
import GlobalNotificationModel from '../../models/global_notification_model';
import GlobalNotificationActions from '../../actions/global_notification_actions';
import apiUrls from '../../constants/api_urls';
import { getLangText } from '../../utils/lang_utils';
/** /**
* This is the component that implements display-specific functionality * This is the component that implements display-specific functionality
*/ */
@ -24,22 +40,22 @@ let Piece = React.createClass({
loadPiece: React.PropTypes.func loadPiece: React.PropTypes.func
}, },
//getInitialState() { getInitialState() {
// return UserStore.getState(); return UserStore.getState();
//}, },
//
//componentDidMount() { componentDidMount() {
// UserStore.listen(this.onChange); UserStore.listen(this.onChange);
// UserActions.fetchCurrentUser(); UserActions.fetchCurrentUser();
//}, },
//
//componentWillUnmount() { componentWillUnmount() {
// UserStore.unlisten(this.onChange); UserStore.unlisten(this.onChange);
//}, },
//
//onChange(state) { onChange(state) {
// this.setState(state); this.setState(state);
//}, },
render() { render() {
@ -52,6 +68,9 @@ let Piece = React.createClass({
<Col md={6} className="ascribe-edition-details"> <Col md={6} className="ascribe-edition-details">
<Header <Header
content={this.props.piece}/> content={this.props.piece}/>
<PieceSummary
currentUser={this.state.currentUser}
piece={this.props.piece} />
<CollapsibleParagraph <CollapsibleParagraph
title="Further Details" title="Further Details"
show={this.props.piece.acl.indexOf('edit') > -1 show={this.props.piece.acl.indexOf('edit') > -1
@ -72,4 +91,37 @@ let Piece = React.createClass({
} }
}); });
let PieceSummary = React.createClass({
propTypes: {
piece: React.PropTypes.object
},
getActions(){
//let actions = (
// <Row>
// <Col md={12}>
// <AclButtonList
// className="text-center ascribe-button-list"
// availableAcls={this.props.piece.acl}
// editions={[this.props.piece]}
// handleSuccess={this.handleSuccess} />
// </Col>
// </Row>);
//return actions;
return null;
},
render() {
return (
<div className="ascribe-detail-header">
<DetailProperty label={getLangText('REGISTREE')} value={ this.props.piece.user_registered } />
<br/>
{this.getActions()}
<hr/>
</div>
);
}
});
export default Piece; export default Piece;

View File

@ -3,29 +3,45 @@
import React from 'react'; import React from 'react';
import ApiUrls from '../../constants/api_urls'; import ApiUrls from '../../constants/api_urls';
import FormMixin from '../../mixins/form_mixin';
import InputText from './input_text'; import Form from './form';
import InputTextArea from './input_textarea'; import Property from './property';
import ButtonSubmitOrClose from '../ascribe_buttons/button_submit_close'; import InputTextAreaToggable from './input_textarea_toggable';
import { getLangText } from '../../utils/lang_utils.js' import Button from 'react-bootstrap/lib/Button';
import AppConstants from '../../constants/application_constants';
import { getLangText } from '../../utils/lang_utils.js';
let ShareForm = React.createClass({ let ShareForm = React.createClass({
mixins: [FormMixin], propTypes: {
editions: React.PropTypes.array,
url() { currentUser: React.PropTypes.object
return ApiUrls.ownership_shares;
}, },
getFormData() { getFormData() {
return { return {
bitcoin_id: this.getBitcoinIds().join(), bitcoin_id: this.getBitcoinIds().join()
share_emails: this.refs.share_emails.state.value,
share_message: this.refs.share_message.state.value
}; };
}, },
handleSuccess(response){
if ('handleSuccess' in this.props){
this.props.handleSuccess(response);
}
},
getBitcoinIds(){
return this.props.editions.map(function(edition){
return edition.bitcoin_id;
});
},
renderForm() { getTitlesString(){
return this.props.editions.map(function(edition){
return '- \"' + edition.title + ', ' + getLangText('edition') + ' ' + edition.edition_number + '\"\n';
});
},
render() {
let title = this.getTitlesString().join(''); let title = this.getTitlesString().join('');
let username = this.props.currentUser.username; let username = this.props.currentUser.username;
let message = let message =
@ -36,25 +52,50 @@ ${title}${getLangText('with you')}.
${getLangText('Truly yours')}, ${getLangText('Truly yours')},
${username}`; ${username}`;
return ( return (
<form id="share_modal_content" role="form" key="share_modal_content" onSubmit={this.submit}> <Form
<InputText ref='form'
ref="share_emails" url={ApiUrls.ownership_shares_editions}
placeHolder={getLangText('Comma separated emails')} getFormData={this.getFormData}
required="required" handleSuccess={this.handleSuccess}
type="text" buttons={
submitted={this.state.submitted}/> <div className="modal-footer">
<InputTextArea <p className="pull-right">
ref="share_message" <Button
defaultValue={message} className="btn btn-default btn-sm ascribe-margin-1px"
required="" type="submit">SHARE</Button>
/> <Button
<ButtonSubmitOrClose className="btn btn-danger btn-delete btn-sm ascribe-margin-1px"
text={getLangText('SHARE')} style={{marginLeft: '0'}}
onClose={this.props.onRequestHide} onClick={this.props.onRequestHide}>CLOSE</Button>
submitted={this.state.submitted} /> </p>
</form> </div>}
spinner={
<div className="modal-footer">
<img src={AppConstants.baseUrl + 'static/img/ascribe_animated_small.gif'} />
</div>
}
>
<Property
name='share_emails'
label={getLangText('Emails')}>
<input
type="text"
placeholder={getLangText('Comma separated emails')}
required/>
</Property>
<Property
name='share_message'
label='Personal Message'
editable={true}>
<InputTextAreaToggable
rows={1}
editable={true}
defaultValue={message}
placeholder={getLangText('Enter a message...')}
required="required"/>
</Property>
</Form>
); );
} }
}); });

View File

@ -25,7 +25,7 @@ let apiUrls = {
'ownership_loans_confirm': AppConstants.apiEndpoint + 'ownership/loans/confirm/', 'ownership_loans_confirm': AppConstants.apiEndpoint + 'ownership/loans/confirm/',
'ownership_loans_deny': AppConstants.apiEndpoint + 'ownership/loans/deny/', 'ownership_loans_deny': AppConstants.apiEndpoint + 'ownership/loans/deny/',
'ownership_loans_contract': AppConstants.apiEndpoint + 'ownership/loans/contract/', 'ownership_loans_contract': AppConstants.apiEndpoint + 'ownership/loans/contract/',
'ownership_shares': AppConstants.apiEndpoint + 'ownership/shares/', 'ownership_shares_editions': AppConstants.apiEndpoint + 'ownership/shares/editions/',
'ownership_transfers': AppConstants.apiEndpoint + 'ownership/transfers/', 'ownership_transfers': AppConstants.apiEndpoint + 'ownership/transfers/',
'ownership_transfers_withdraw': AppConstants.apiEndpoint + 'ownership/transfers/withdraw/', 'ownership_transfers_withdraw': AppConstants.apiEndpoint + 'ownership/transfers/withdraw/',
'ownership_unconsigns': AppConstants.apiEndpoint + 'ownership/unconsigns/', 'ownership_unconsigns': AppConstants.apiEndpoint + 'ownership/unconsigns/',