2015-06-05 11:06:36 +02:00
|
|
|
'use strict';
|
|
|
|
|
2015-05-27 14:35:33 +02:00
|
|
|
import React from 'react';
|
|
|
|
|
2015-06-03 10:27:11 +02:00
|
|
|
import ConsignForm from '../ascribe_forms/form_consign';
|
2015-06-11 15:03:55 +02:00
|
|
|
import UnConsignForm from '../ascribe_forms/form_unconsign';
|
2015-06-03 10:27:11 +02:00
|
|
|
import TransferForm from '../ascribe_forms/form_transfer';
|
|
|
|
import LoanForm from '../ascribe_forms/form_loan';
|
|
|
|
import ShareForm from '../ascribe_forms/form_share_email';
|
|
|
|
import ModalWrapper from '../ascribe_modal/modal_wrapper';
|
|
|
|
import AppConstants from '../../constants/application_constants';
|
2015-05-27 14:35:33 +02:00
|
|
|
|
2015-06-09 16:10:38 +02:00
|
|
|
import GlobalNotificationModel from '../../models/global_notification_model';
|
|
|
|
import GlobalNotificationActions from '../../actions/global_notification_actions';
|
|
|
|
|
2015-07-10 20:00:35 +02:00
|
|
|
import { getLangText } from '../../utils/lang_utils.js';
|
2015-07-13 14:10:46 +02:00
|
|
|
import apiUrls from '../../constants/api_urls';
|
2015-07-03 19:08:56 +02:00
|
|
|
|
2015-05-27 14:35:33 +02:00
|
|
|
let AclButton = React.createClass({
|
|
|
|
propTypes: {
|
|
|
|
action: React.PropTypes.oneOf(AppConstants.aclList).isRequired,
|
2015-05-27 15:49:12 +02:00
|
|
|
availableAcls: React.PropTypes.array.isRequired,
|
2015-07-13 14:10:46 +02:00
|
|
|
pieceOrEditions: React.PropTypes.object.isRequired,
|
2015-06-02 11:38:18 +02:00
|
|
|
currentUser: React.PropTypes.object,
|
2015-07-01 10:53:40 +02:00
|
|
|
handleSuccess: React.PropTypes.func.isRequired,
|
|
|
|
className: React.PropTypes.string
|
2015-05-27 14:35:33 +02:00
|
|
|
},
|
|
|
|
|
2015-07-13 14:10:46 +02:00
|
|
|
isPiece(){
|
|
|
|
return !(this.props.pieceOrEditions.constructor === Array);
|
|
|
|
},
|
2015-06-01 18:59:47 +02:00
|
|
|
actionProperties(){
|
2015-06-05 11:06:36 +02:00
|
|
|
if (this.props.action === 'consign'){
|
2015-06-01 18:59:47 +02:00
|
|
|
return {
|
2015-07-03 19:08:56 +02:00
|
|
|
title: getLangText('Consign artwork'),
|
|
|
|
tooltip: getLangText('Have someone else sell the artwork'),
|
2015-07-10 20:00:35 +02:00
|
|
|
form: <ConsignForm currentUser={ this.props.currentUser } editions={ this.props.pieceOrEditions }/>,
|
2015-06-09 16:10:38 +02:00
|
|
|
handleSuccess: this.showNotification
|
2015-06-05 11:06:36 +02:00
|
|
|
};
|
2015-06-01 18:59:47 +02:00
|
|
|
}
|
2015-06-11 15:03:55 +02:00
|
|
|
if (this.props.action === 'unconsign'){
|
|
|
|
return {
|
2015-07-03 19:08:56 +02:00
|
|
|
title: getLangText('Unconsign artwork'),
|
|
|
|
tooltip: getLangText('Have the owner manage his sales again'),
|
2015-07-10 20:00:35 +02:00
|
|
|
form: <UnConsignForm currentUser={ this.props.currentUser } editions={ this.props.pieceOrEditions }/>,
|
2015-06-11 15:03:55 +02:00
|
|
|
handleSuccess: this.showNotification
|
|
|
|
};
|
|
|
|
}else if (this.props.action === 'transfer') {
|
2015-06-01 18:59:47 +02:00
|
|
|
return {
|
2015-07-03 19:08:56 +02:00
|
|
|
title: getLangText('Transfer artwork'),
|
|
|
|
tooltip: getLangText('Transfer the ownership of the artwork'),
|
2015-07-10 20:00:35 +02:00
|
|
|
form: <TransferForm currentUser={ this.props.currentUser } editions={ this.props.pieceOrEditions }/>,
|
2015-06-09 16:10:38 +02:00
|
|
|
handleSuccess: this.showNotification
|
2015-06-05 11:06:36 +02:00
|
|
|
};
|
2015-06-01 18:59:47 +02:00
|
|
|
}
|
2015-06-05 11:06:36 +02:00
|
|
|
else if (this.props.action === 'loan'){
|
2015-06-01 18:59:47 +02:00
|
|
|
return {
|
2015-07-03 19:08:56 +02:00
|
|
|
title: getLangText('Loan artwork'),
|
|
|
|
tooltip: getLangText('Loan your artwork for a limited period of time'),
|
2015-07-10 20:00:35 +02:00
|
|
|
form: <LoanForm currentUser={ this.props.currentUser } editions={ this.props.pieceOrEditions }/>,
|
2015-06-09 16:10:38 +02:00
|
|
|
handleSuccess: this.showNotification
|
2015-06-05 11:06:36 +02:00
|
|
|
};
|
2015-06-01 18:59:47 +02:00
|
|
|
}
|
2015-06-05 11:06:36 +02:00
|
|
|
else if (this.props.action === 'share'){
|
2015-06-01 18:59:47 +02:00
|
|
|
return {
|
2015-07-03 19:08:56 +02:00
|
|
|
title: getLangText('Share artwork'),
|
|
|
|
tooltip: getLangText('Share the artwork'),
|
2015-07-13 14:10:46 +02:00
|
|
|
form: (
|
|
|
|
<ShareForm
|
|
|
|
message={this.getShareMessage()}
|
|
|
|
id={this.getFormDataId()}
|
|
|
|
url={this.isPiece() ? apiUrls.ownership_shares_pieces : apiUrls.ownership_shares_editions }/>
|
|
|
|
),
|
2015-06-09 16:10:38 +02:00
|
|
|
handleSuccess: this.showNotification
|
2015-06-05 11:06:36 +02:00
|
|
|
};
|
2015-06-01 18:59:47 +02:00
|
|
|
}
|
|
|
|
},
|
2015-07-13 14:10:46 +02:00
|
|
|
|
2015-06-09 16:10:38 +02:00
|
|
|
showNotification(response){
|
|
|
|
this.props.handleSuccess();
|
|
|
|
let notification = new GlobalNotificationModel(response.notification, 'success');
|
|
|
|
GlobalNotificationActions.appendGlobalNotification(notification);
|
|
|
|
},
|
2015-07-13 14:10:46 +02:00
|
|
|
|
|
|
|
getTitlesString(){
|
|
|
|
if (this.isPiece()){
|
|
|
|
return '\"' + this.props.pieceOrEditions.title + '\"';
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return this.props.pieceOrEditions.map(function(edition) {
|
|
|
|
return '- \"' + edition.title + ', ' + getLangText('edition') + ' ' + edition.edition_number + '\"\n';
|
|
|
|
}).join('');
|
|
|
|
}
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
getFormDataId(){
|
|
|
|
if (this.isPiece()) {
|
|
|
|
return {piece_id: this.props.pieceOrEditions.id};
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return {bitcoin_id: this.props.pieceOrEditions.map(function(edition){
|
|
|
|
return edition.bitcoin_id;
|
|
|
|
}).join()};
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2015-07-13 17:09:44 +02:00
|
|
|
getShareMessage(){
|
|
|
|
return (
|
|
|
|
`
|
|
|
|
${getLangText('Hi')},
|
|
|
|
|
|
|
|
${getLangText('I am sharing')}:
|
|
|
|
${this.getTitlesString()} ${getLangText('with you')}.
|
|
|
|
|
|
|
|
${getLangText('Truly yours')},
|
|
|
|
${this.props.currentUser.username}
|
|
|
|
`
|
|
|
|
);
|
|
|
|
},
|
|
|
|
|
2015-05-27 14:35:33 +02:00
|
|
|
render() {
|
2015-07-13 20:16:08 +02:00
|
|
|
let shouldDisplay = this.props.availableAcls[this.props.action];
|
2015-06-01 18:59:47 +02:00
|
|
|
let aclProps = this.actionProperties();
|
2015-05-27 14:35:33 +02:00
|
|
|
return (
|
2015-06-01 18:59:47 +02:00
|
|
|
<ModalWrapper
|
|
|
|
button={
|
2015-07-01 10:53:40 +02:00
|
|
|
<button className={shouldDisplay ? 'btn btn-default btn-sm ' : 'hidden'}>
|
2015-06-01 18:59:47 +02:00
|
|
|
{this.props.action.toUpperCase()}
|
2015-06-30 17:12:13 +02:00
|
|
|
</button>
|
2015-06-01 18:59:47 +02:00
|
|
|
}
|
2015-06-09 16:10:38 +02:00
|
|
|
handleSuccess={ aclProps.handleSuccess }
|
2015-06-01 18:59:47 +02:00
|
|
|
title={ aclProps.title }
|
|
|
|
tooltip={ aclProps.tooltip }>
|
|
|
|
{ aclProps.form }
|
|
|
|
</ModalWrapper>
|
2015-05-27 14:35:33 +02:00
|
|
|
);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
export default AclButton;
|