1
0
mirror of https://github.com/ascribe/onion.git synced 2025-01-07 04:04:20 +01:00
onion/js/components/ascribe_forms/form_copyright_association.js

89 lines
3.2 KiB
JavaScript
Raw Normal View History

'use strict';
import React from 'react';
import GlobalNotificationModel from '../../models/global_notification_model';
import GlobalNotificationActions from '../../actions/global_notification_actions';
import Form from './form';
import Property from './property';
import withContext from '../context/with_context';
import { currentUserShape } from '../prop_types';
2015-09-17 11:39:55 +02:00
import AppConstants from '../../constants/application_constants';
import { getLangText } from '../../utils/lang';
import { resolveUrl } from '../../utils/url_resolver';
const { bool } = React.PropTypes;
const CopyrightAssociationForm = React.createClass({
propTypes: {
// Injected through HOCs
currentUser: currentUserShape.isRequired,
isLoggedIn: bool.isRequired
},
handleSubmitSuccess() {
const notification = new GlobalNotificationModel(getLangText('Copyright association updated'), 'success', 10000);
GlobalNotificationActions.appendGlobalNotification(notification);
},
getProfileFormData() {
return { email: this.props.currentUser.email };
},
render() {
const { currentUser, isLoggedIn } = this.props;
const selectDefaultValue = ' -- ' + getLangText('select an association') + ' -- ';
2015-09-22 14:13:04 +02:00
let selectedState = selectDefaultValue;
if (currentUser.profile && currentUser.profile.copyright_association) {
if (AppConstants.copyrightAssociations.indexOf(currentUser.profile.copyright_association) !== -1) {
selectedState = AppConstants.copyrightAssociations[selectedState];
}
}
2015-09-22 14:13:04 +02:00
if (isLoggedIn) {
2015-09-17 11:39:55 +02:00
return (
<Form
ref='form'
url={resolveUrl('users_profile')}
2015-09-17 11:39:55 +02:00
getFormData={this.getProfileFormData}
handleSuccess={this.handleSubmitSuccess}>
<Property
name="copyright_association"
className="ascribe-property-collapsible-toggle"
2016-02-05 10:38:59 +01:00
label={getLangText('Copyright Association')}>
2015-09-22 14:13:04 +02:00
<select defaultValue={selectedState} name="contract">
<option
name={0}
key={0}
value={selectDefaultValue}>
{selectDefaultValue}
2015-09-17 11:39:55 +02:00
</option>
{AppConstants.copyrightAssociations.map((association, i) => {
return (
<option
2015-09-22 14:13:04 +02:00
name={i + 1}
key={i + 1}
value={association}>
2015-09-17 11:39:55 +02:00
{ association }
</option>
);
})}
</select>
</Property>
<hr />
</Form>
);
} else {
return null;
2015-09-17 11:39:55 +02:00
}
}
});
export default withContext(CopyrightAssociationForm, 'currentUser', 'isLoggedIn');