1
0
mirror of https://github.com/ascribe/onion.git synced 2024-11-15 09:35:10 +01:00
onion/js/components/ascribe_forms/form_request_action.js

101 lines
3.2 KiB
JavaScript
Raw Normal View History

'use strict';
import React from 'react';
import Alert from 'react-bootstrap/lib/Alert';
import apiUrls from '../../constants/api_urls';
import FormMixin from '../../mixins/form_mixin';
2015-07-14 17:42:15 +02:00
import AclButton from './../ascribe_buttons/acl_button';
2015-06-16 09:59:09 +02:00
import AppConstants from '../../constants/application_constants';
2015-07-14 11:42:09 +02:00
import { getLangText } from '../../utils/lang_utils.js';
2015-06-16 09:59:09 +02:00
let RequestActionForm = React.createClass({
mixins: [FormMixin],
url(e){
let edition = this.props.editions[0];
if (e.target.id === 'request_accept'){
if (edition.request_action === 'consign'){
return apiUrls.ownership_consigns_confirm;
}
else if (edition.request_action === 'unconsign'){
return apiUrls.ownership_unconsigns;
}
else if (edition.request_action === 'loan'){
return apiUrls.ownership_loans_confirm;
}
}
else if(e.target.id === 'request_deny'){
if (edition.request_action === 'consign') {
return apiUrls.ownership_consigns_deny;
}
else if (edition.request_action === 'unconsign') {
return apiUrls.ownership_unconsigns_deny;
}
else if (edition.request_action === 'loan') {
return apiUrls.ownership_loans_deny;
}
}
},
handleRequest: function(e){
e.preventDefault();
this.submit(e);
},
getFormData() {
return {
bitcoin_id: this.getBitcoinIds().join()
};
},
renderForm() {
let edition = this.props.editions[0];
2015-07-14 17:42:15 +02:00
let buttonAccept = (
<div id="request_accept"
onClick={this.handleRequest}
className='btn btn-default btn-sm ascribe-margin-1px'>{getLangText('ACCEPT')}
</div>);
2015-08-06 10:09:25 +02:00
if (edition.request_action === 'unconsign') {
2015-07-14 17:42:15 +02:00
buttonAccept = (
<AclButton
availableAcls={{'acl_unconsign': true}}
action="acl_unconsign"
pieceOrEditions={this.props.editions}
currentUser={this.props.currentUser}
handleSuccess={this.props.handleSuccess} />
);
}
let buttons = (
2015-07-14 17:42:15 +02:00
<span>
<span>
{buttonAccept}
</span>
<span>
2015-07-14 17:42:15 +02:00
<div id="request_deny" onClick={this.handleRequest} className='btn btn-danger btn-delete btn-sm ascribe-margin-1px'>{getLangText('REJECT')}</div>
</span>
2015-07-14 17:42:15 +02:00
</span>
);
if (this.state.submitted){
buttons = (
<span>
2015-06-16 09:59:09 +02:00
<img src={AppConstants.baseUrl + 'static/img/ascribe_animated_medium.gif'} />
</span>
);
}
return (
<Alert bsStyle='warning'>
2015-07-03 12:35:45 +02:00
<div style={{textAlign: 'center'}}>
2015-07-14 14:16:51 +02:00
<div>{ edition.owner } {getLangText('requests you')} { edition.request_action } {getLangText('this edition%s', '.')}&nbsp;&nbsp;</div>
{buttons}
2015-07-03 12:35:45 +02:00
</div>
</Alert>
);
}
});
export default RequestActionForm;