mirror of
https://github.com/ascribe/onion.git
synced 2025-01-03 18:35:09 +01:00
refactor request action form
This commit is contained in:
parent
c8dc4fa12d
commit
d968f02b59
@ -2,49 +2,50 @@
|
|||||||
|
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
|
|
||||||
import Alert from 'react-bootstrap/lib/Alert';
|
|
||||||
|
|
||||||
import ApiUrls from '../../constants/api_urls';
|
|
||||||
import FormMixin from '../../mixins/form_mixin';
|
import FormMixin from '../../mixins/form_mixin';
|
||||||
|
|
||||||
import AclButton from './../ascribe_buttons/acl_button';
|
import AclButton from './../ascribe_buttons/acl_button';
|
||||||
import ActionPanel from '../ascribe_panel/action_panel';
|
import ActionPanel from '../ascribe_panel/action_panel';
|
||||||
|
import Form from './form';
|
||||||
|
|
||||||
|
import GlobalNotificationModel from '../../models/global_notification_model';
|
||||||
|
import GlobalNotificationActions from '../../actions/global_notification_actions';
|
||||||
|
|
||||||
|
import ApiUrls from '../../constants/api_urls';
|
||||||
|
|
||||||
import AppConstants from '../../constants/application_constants';
|
|
||||||
import { getLangText } from '../../utils/lang_utils.js';
|
import { getLangText } from '../../utils/lang_utils.js';
|
||||||
|
|
||||||
let RequestActionForm = React.createClass({
|
|
||||||
mixins: [FormMixin],
|
|
||||||
|
|
||||||
url(e){
|
let RequestActionForm = React.createClass({
|
||||||
let edition = this.props.editions[0];
|
propTypes: {
|
||||||
if (e.target.id === 'request_accept'){
|
editions: React.PropTypes.arrayOf(React.PropTypes.object),
|
||||||
if (edition.request_action === 'consign'){
|
currentUser: React.PropTypes.object,
|
||||||
return ApiUrls.ownership_consigns_confirm;
|
handleSuccess: React.PropTypes.func
|
||||||
}
|
|
||||||
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){
|
getUrls() {
|
||||||
e.preventDefault();
|
let edition = this.props.editions[0];
|
||||||
this.submit(e);
|
let urls = {};
|
||||||
|
|
||||||
|
|
||||||
|
if (edition.request_action === 'consign'){
|
||||||
|
urls.accept = ApiUrls.ownership_consigns_confirm;
|
||||||
|
urls.deny = ApiUrls.ownership_consigns_deny;
|
||||||
|
} else if (edition.request_action === 'unconsign'){
|
||||||
|
urls.accept = ApiUrls.ownership_unconsigns;
|
||||||
|
urls.deny = ApiUrls.ownership_unconsigns_deny;
|
||||||
|
} else if (edition.request_action === 'loan'){
|
||||||
|
urls.accept = ApiUrls.ownership_loans_confirm;
|
||||||
|
urls.deny = ApiUrls.ownership_loans_deny;
|
||||||
|
}
|
||||||
|
|
||||||
|
return urls;
|
||||||
|
},
|
||||||
|
|
||||||
|
getBitcoinIds(){
|
||||||
|
return this.props.editions.map(function(edition){
|
||||||
|
return edition.bitcoin_id;
|
||||||
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
getFormData() {
|
getFormData() {
|
||||||
@ -53,6 +54,19 @@ let RequestActionForm = React.createClass({
|
|||||||
};
|
};
|
||||||
},
|
},
|
||||||
|
|
||||||
|
showNotification(option, action, owner) {
|
||||||
|
return () => {
|
||||||
|
let message = getLangText('You have successfully') + ' ' + option + ' ' + action + ' ' + getLangText('to') + ' ' + owner;
|
||||||
|
|
||||||
|
let notification = new GlobalNotificationModel(message, 'success');
|
||||||
|
GlobalNotificationActions.appendGlobalNotification(notification);
|
||||||
|
|
||||||
|
if(this.props.handleSuccess) {
|
||||||
|
this.props.handleSuccess();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
},
|
||||||
|
|
||||||
getContent() {
|
getContent() {
|
||||||
let edition = this.props.editions[0];
|
let edition = this.props.editions[0];
|
||||||
let message = edition.owner + ' ' + getLangText('requests you') + ' ' + edition.request_action + ' ' + getLangText('this edition%s', '.');
|
let message = edition.owner + ' ' + getLangText('requests you') + ' ' + edition.request_action + ' ' + getLangText('this edition%s', '.');
|
||||||
@ -64,15 +78,11 @@ let RequestActionForm = React.createClass({
|
|||||||
);
|
);
|
||||||
},
|
},
|
||||||
|
|
||||||
renderForm() {
|
getAcceptButton() {
|
||||||
let edition = this.props.editions[0];
|
let edition = this.props.editions[0];
|
||||||
let buttonAccept = (
|
|
||||||
<div id="request_accept"
|
if(edition.request_action === 'unconsign') {
|
||||||
onClick={this.handleRequest}
|
return (
|
||||||
className='btn btn-default btn-sm ascribe-margin-1px'>{getLangText('ACCEPT')}
|
|
||||||
</div>);
|
|
||||||
if (edition.request_action === 'unconsign') {
|
|
||||||
buttonAccept = (
|
|
||||||
<AclButton
|
<AclButton
|
||||||
availableAcls={{'acl_unconsign': true}}
|
availableAcls={{'acl_unconsign': true}}
|
||||||
action="acl_unconsign"
|
action="acl_unconsign"
|
||||||
@ -80,31 +90,52 @@ let RequestActionForm = React.createClass({
|
|||||||
currentUser={this.props.currentUser}
|
currentUser={this.props.currentUser}
|
||||||
handleSuccess={this.props.handleSuccess} />
|
handleSuccess={this.props.handleSuccess} />
|
||||||
);
|
);
|
||||||
}
|
} else {
|
||||||
let buttons = (
|
return (
|
||||||
<span>
|
<button
|
||||||
<span>
|
type="submit"
|
||||||
{buttonAccept}
|
className='btn btn-default btn-sm ascribe-margin-1px'>
|
||||||
</span>
|
{getLangText('ACCEPT')}
|
||||||
<span>
|
</button>
|
||||||
<div id="request_deny" onClick={this.handleRequest} className='btn btn-danger btn-delete btn-sm ascribe-margin-1px'>{getLangText('REJECT')}</div>
|
|
||||||
</span>
|
|
||||||
</span>
|
|
||||||
);
|
|
||||||
if (this.state.submitted){
|
|
||||||
buttons = (
|
|
||||||
<span>
|
|
||||||
<img src={AppConstants.baseUrl + 'static/img/ascribe_animated_medium.gif'} />
|
|
||||||
</span>
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
getButtonForm() {
|
||||||
|
let edition = this.props.editions[0];
|
||||||
|
|
||||||
|
let urls = this.getUrls();
|
||||||
|
let acceptButton = this.getAcceptButton();
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div>
|
||||||
|
<Form
|
||||||
|
url={urls.deny}
|
||||||
|
getFormData={this.getFormData}
|
||||||
|
handleSuccess={this.showNotification(getLangText('accepted'), edition.request_action, edition.owner)}
|
||||||
|
className='inline pull-right'>
|
||||||
|
<button
|
||||||
|
type="submit"
|
||||||
|
className='btn btn-danger btn-delete btn-sm ascribe-margin-1px'>
|
||||||
|
{getLangText('REJECT')}
|
||||||
|
</button>
|
||||||
|
</Form>
|
||||||
|
<Form
|
||||||
|
url={urls.accept}
|
||||||
|
getFormData={this.getFormData}
|
||||||
|
handleSuccess={this.showNotification(getLangText('denied'), edition.request_action, edition.owner)}
|
||||||
|
className='inline pull-right'>
|
||||||
|
{acceptButton}
|
||||||
|
</Form>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
},
|
||||||
|
|
||||||
|
render() {
|
||||||
return (
|
return (
|
||||||
<ActionPanel
|
<ActionPanel
|
||||||
content={this.getContent()}
|
content={this.getContent()}
|
||||||
buttons={buttons}/>
|
buttons={this.getButtonForm()}/>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -6,7 +6,10 @@ import classnames from 'classnames';
|
|||||||
let ActionPanel = React.createClass({
|
let ActionPanel = React.createClass({
|
||||||
propTypes: {
|
propTypes: {
|
||||||
title: React.PropTypes.string,
|
title: React.PropTypes.string,
|
||||||
content: React.PropTypes.string,
|
content: React.PropTypes.oneOfType([
|
||||||
|
React.PropTypes.string,
|
||||||
|
React.PropTypes.element
|
||||||
|
]),
|
||||||
buttons: React.PropTypes.element,
|
buttons: React.PropTypes.element,
|
||||||
onClick: React.PropTypes.func,
|
onClick: React.PropTypes.func,
|
||||||
ignoreFocus: React.PropTypes.bool
|
ignoreFocus: React.PropTypes.bool
|
||||||
|
Loading…
Reference in New Issue
Block a user