'use strict';
import React from 'react';
import AclButton from './../ascribe_buttons/acl_button';
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 { getLangText } from '../../utils/lang_utils.js';
let RequestActionForm = React.createClass({
propTypes: {
editions: React.PropTypes.arrayOf(React.PropTypes.object),
currentUser: React.PropTypes.object,
handleSuccess: React.PropTypes.func
},
getUrls() {
let edition = this.props.editions[0];
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() {
return {
bitcoin_id: this.getBitcoinIds().join()
};
},
showNotification(option, action, owner) {
return () => {
let message = getLangText('You have successfully') + ' ' + option + ' the ' + action + ' request ' + getLangText('from') + ' ' + owner;
let notification = new GlobalNotificationModel(message, 'success');
GlobalNotificationActions.appendGlobalNotification(notification);
if(this.props.handleSuccess) {
this.props.handleSuccess();
}
};
},
getContent() {
let edition = this.props.editions[0];
let message = edition.owner + ' ' + getLangText('requests you') + ' ' + edition.request_action + ' ' + getLangText('this edition%s', '.');
return (
{message}
);
},
getAcceptButtonForm(urls) {
let edition = this.props.editions[0];
if(edition.request_action === 'unconsign') {
return (